Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(atomic): dim unselected facet value #4410

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ export const Default: Story = {
},
decorators: [facetDecorator],
};

export const DisplayAsLink: Story = {
name: 'atomic-rating-facet',
tags: ['test'],
args: {
'attributes-display-values-as': 'link',
'attributes-field': 'snrating',
},
decorators: [facetDecorator],
};
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export class AtomicRatingFacet implements InitializableComponent {
private renderValue(facetValue: NumericFacetValue, onClick: () => void) {
const displayValue = this.formatFacetValue(facetValue);
const isSelected = facetValue.state === 'selected';
const shouldBeDimmed = this.facetState.hasActiveValues && !isSelected;
switch (this.displayValuesAs) {
case 'checkbox':
return (
Expand All @@ -393,6 +394,7 @@ export class AtomicRatingFacet implements InitializableComponent {
isSelected={isSelected}
i18n={this.bindings.i18n}
onClick={onClick}
class={shouldBeDimmed ? 'opacity-50' : undefined}
>
{this.ratingContent(facetValue)}
</FacetValueLink>
Expand Down
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {test, expect} from './fixture';

test.describe('with facet values as link', () => {
test.beforeEach(async ({facet}) => {
await facet.load({story: 'display-as-link'});
});

test.describe('when no value is selected', () => {
test('should not dim any facet values', async ({facet}) => {
const facetValues = await facet.facetValues.all();
for (let i = 0; i < facetValues.length; i++) {
await expect(facetValues[i]).toHaveCSS('opacity', '1');
}
});
});

test.describe('when selecting a value', () => {
test.beforeEach(async ({facet}) => {
await facet.getFacetValueButtonByPosition(0).click();
});

test('should dim unselected facet values', async ({facet}) => {
const facetValues = await facet.facetValues.all();
for (let i = 1; i < facetValues.length; i++) {
await expect(facetValues[i]).toHaveCSS('opacity', '1');
}
});

test('should not dim selected facet', async ({facet}) => {
await expect(facet.facetValues.nth(0)).toHaveCSS('opacity', '1');
});
});
});
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 {AtomicRatingFacetPageObject as Facet} from './page-object';

type MyFixture = {
facet: Facet;
};

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

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

export class AtomicRatingFacetPageObject extends BasePageObject<'atomic-rating-facet'> {
constructor(page: Page) {
super(page, 'atomic-rating-facet');
}

getFacetValueByPosition(valuePosition: number) {
return this.facetValues.nth(valuePosition);
}

getFacetValueButtonByPosition(valuePosition: number) {
const value = this.getFacetValueByPosition(valuePosition);
return value.locator('button');
}

get clearFilter() {
return this.page.getByRole('button').filter({hasText: /Clear.*filter/});
}

get getSelectedFacetValueLink() {
return this.page.locator('[part="value-link value-link-selected"]');
}

get facetValues() {
return this.page.getByRole('listitem');
}
}
Loading