Skip to content

Commit

Permalink
Merge pull request #3 from surenpoghosian/feature/pathBuilder-tests
Browse files Browse the repository at this point in the history
[feature/pathBuilder-tests] add pathBuilder tests
  • Loading branch information
surenpoghosian authored Jul 23, 2024
2 parents ff15ac1 + ece1510 commit 8b0ed49
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/__tests__/listam.test.ts

This file was deleted.

72 changes: 72 additions & 0 deletions src/__tests__/pathBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import PathBuilderFactory from "../PathBuilderFactory";
import ListAm from "../PathBuilderFactory/products/ListAm";
import { ListAmCategory, ListAmCurrency, ListAmGeolocation, ListAmSellerType, PathBuilderVariant } from "../configs/types";

describe('ListAm', () => {
let listAm: ListAm;

beforeEach(() => {
listAm = PathBuilderFactory.createPathBuilder(PathBuilderVariant.LISTAM) as ListAm;
listAm.init('base-path');
});

test('should initialize with correct path', () => {
expect(listAm.build()).toBe('base-path');
});

test('should build path with category', () => {
listAm.init('base-path', ListAmCategory.ROOM_FOR_A_RENT);
expect(listAm.build()).toBe('base-path/category/212');
});

test('should add and build path with currency', () => {
listAm.addCurrency(ListAmCurrency.USD);
expect(listAm.build()).toBe('base-path?crc=1');
});

test('should add and build path with geolocation', () => {
listAm.addGeolocation(ListAmGeolocation.YEREVAN);
expect(listAm.build()).toBe('base-path?n=1');
});

test('should add and build path with seller type', () => {
listAm.addSellerType(ListAmSellerType.INDIVIDUAL);
expect(listAm.build()).toBe('base-path?cmtype=1');
});

test('should add and build path with price range', () => {
listAm.addPriceRange(1000, 2000);
expect(listAm.build()).toBe('base-path?price1=1000&price2=2000');
});

test('should add multiple parameters', () => {
listAm.addCurrency(ListAmCurrency.USD);
listAm.addGeolocation(ListAmGeolocation.YEREVAN);
expect(listAm.build()).toBe('base-path?crc=1&n=1');
});

test('should handle page number correctly', () => {
listAm.addPageNumber(2);
expect(listAm.build()).toBe('base-path/2');
});

test('should handle category and page number correctly', () => {
listAm.init('base-path', ListAmCategory.ROOM_FOR_A_RENT);
listAm.addPageNumber(2);
expect(listAm.build()).toBe('base-path/category/212/2');
});

test('should handle parameters, category, and page number correctly', () => {
listAm.init('base-path', ListAmCategory.ROOM_FOR_A_RENT);
listAm.addCurrency(ListAmCurrency.USD);
listAm.addPageNumber(2);
expect(listAm.build()).toBe('base-path/category/212/2?crc=1');
});

test('should reset correctly', () => {
listAm.addCurrency(ListAmCurrency.USD);
listAm.addPageNumber(2);
listAm.reset();
expect(listAm.build()).toBe('base-path');
});
});

0 comments on commit 8b0ed49

Please sign in to comment.