Skip to content

Commit

Permalink
fix(atomic): field sort should be applied when selected
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-bompart committed Aug 28, 2024
1 parent 49bec88 commit 602802c
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export const Default: Story = {
label="most-recent"
expression="date descending"
></atomic-sort-expression>
<atomic-sort-expression
label="Price ascending"
expression="sncost ascending"
></atomic-sort-expression>
<atomic-sort-expression
label="Price ascending & Most recent"
expression="sncost ascending, date descending"
></atomic-sort-expression>
`,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@ export class AtomicSortDropdown implements InitializableComponent {
);
option && this.sort.sortBy(option.criteria);
}

public componentShouldUpdate(): void {
if (
this.options.some(
(option) => option.expression === this.sortState.sortCriteria
(option) =>
option.expression.trim().replace(/\s*,\s*/g, ',') ===
this.sortState.sortCriteria.replace(/@/g, '')
)
) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {expect, test} from './fixture';

test.describe('default', () => {
test.beforeEach(async ({sortDropdown}) => {
await sortDropdown.load();
});

test.describe('when selecting a field sort criterion', async () => {
test.beforeEach(async ({sortDropdown}) => {
await sortDropdown.dropdown.selectOption('sncost ascending');
});

test('should properly reflect the selected sort criteria into the URL', async ({
page,
}) => {
expect(page.url()).toContain('sortCriteria=%40sncost%20ascending');
});
});

test.describe('when selecting a composite field sort criterion', async () => {
test.beforeEach(async ({sortDropdown}) => {
await sortDropdown.dropdown.selectOption(
'sncost ascending, date descending'
);
});

test('should properly reflect the selected sort criteria into the URL', async ({
page,
}) => {
expect(page.url()).toContain(
// eslint-disable-next-line @cspell/spellchecker
'sortCriteria=%40sncost%20ascending%2Cdate%20descending'
);
});
});

test.describe('when selecting a relevance sort criterion', async () => {
test.beforeEach(async ({sortDropdown}) => {
await sortDropdown.dropdown.selectOption('relevancy');
});

test('should not reflect any sortCriteria in the URL', async ({page}) => {
expect(page.url()).not.toContain('sortCriteria=');
});
});

test.describe('when selecting a date sort criterion', async () => {
test.beforeEach(async ({sortDropdown}) => {
await sortDropdown.dropdown.selectOption('date descending');
});

test('should properly reflect the selected sort criteria into the URL', async ({
page,
}) => {
expect(page.url()).toContain('sortCriteria=date%20descending');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {test as base} from '@playwright/test';
import {
AxeFixture,
makeAxeBuilder,
} from '../../../../../playwright-utils/base-fixture';
import {AtomicSortDropdownPageObject} from './page-object';

type MyFixture = {
sortDropdown: AtomicSortDropdownPageObject;
};

export const test = base.extend<MyFixture & AxeFixture>({
makeAxeBuilder,
sortDropdown: async ({page}, use) => {
await use(new AtomicSortDropdownPageObject(page));
},
});

export {expect} from '@playwright/test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type {Page} from '@playwright/test';
import {BasePageObject} from '../../../../../playwright-utils/base-page-object';

export class AtomicSortDropdownPageObject extends BasePageObject<'atomic-sort-dropdown'> {
constructor(page: Page) {
super(page, 'atomic-sort-dropdown');
}

get dropdown() {
return this.page.getByLabel('Sort by');
}
}

0 comments on commit 602802c

Please sign in to comment.