Skip to content

Commit f74a913

Browse files
Copiloty-lakhdar
andcommitted
Step 4: Enhance E2E tests with comprehensive functional tests
Co-authored-by: y-lakhdar <12199712+y-lakhdar@users.noreply.github.com>
1 parent d4dc4a9 commit f74a913

File tree

1 file changed

+142
-42
lines changed

1 file changed

+142
-42
lines changed
Lines changed: 142 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,168 @@
11
import {expect, test} from './fixture';
22

3-
test.describe('with facet values as link', () => {
4-
test.beforeEach(async ({facet}) => {
5-
await facet.load({story: 'display-as-link'});
6-
});
3+
test.describe('atomic-rating-facet', () => {
4+
test.describe('default rendering', () => {
5+
test.beforeEach(async ({facet}) => {
6+
await facet.load({story: 'default'});
7+
});
8+
9+
test('should render rating facet with values', async ({facet}) => {
10+
await facet.hydrated.waitFor();
11+
const values = await facet.facetValues.all();
12+
expect(values.length).toBeGreaterThan(0);
13+
});
14+
15+
test('should render rating icons for each value', async ({facet}) => {
16+
await facet.hydrated.waitFor();
17+
const ratingIcons = await facet.component
18+
.locator('[part~="value-rating-icon"]')
19+
.all();
20+
expect(ratingIcons.length).toBeGreaterThan(0);
21+
});
22+
23+
test('should show checkboxes by default', async ({facet}) => {
24+
await facet.hydrated.waitFor();
25+
const checkbox = await facet.component
26+
.locator('[part~="value-checkbox"]')
27+
.first();
28+
await expect(checkbox).toBeVisible();
29+
});
730

8-
test.describe('when no value is selected', () => {
9-
test('should not dim any facet values', async ({facet}) => {
10-
const facetValues = await facet.facetValues.all();
11-
for (let i = 0; i < facetValues.length; i++) {
12-
await expect(facetValues[i]).toHaveCSS('opacity', '1');
13-
}
31+
test('should allow selecting a value', async ({facet}) => {
32+
await facet.hydrated.waitFor();
33+
const firstValue = facet.getFacetValueButtonByPosition(0);
34+
await firstValue.click();
35+
36+
const selected = await facet.component
37+
.locator('[part~="value-checkbox-checked"]')
38+
.first();
39+
await expect(selected).toBeVisible();
40+
});
41+
42+
test('should show clear button after selection', async ({facet}) => {
43+
await facet.hydrated.waitFor();
44+
await facet.getFacetValueButtonByPosition(0).click();
45+
await expect(facet.clearFilter).toBeVisible();
46+
});
47+
48+
test('should clear selection when clicking clear button', async ({
49+
facet,
50+
}) => {
51+
await facet.hydrated.waitFor();
52+
await facet.getFacetValueButtonByPosition(0).click();
53+
await facet.clearFilter.click();
54+
55+
const selected = await facet.component
56+
.locator('[part~="value-checkbox-checked"]')
57+
.all();
58+
expect(selected.length).toBe(0);
1459
});
1560
});
1661

17-
test.describe('when selecting a value', () => {
62+
test.describe('with facet values as link', () => {
1863
test.beforeEach(async ({facet}) => {
19-
await facet.getFacetValueButtonByPosition(0).click();
64+
await facet.load({story: 'display-as-link'});
2065
});
2166

22-
test('should dim unselected facet values', async ({facet}) => {
23-
const facetValues = await facet.facetValues.all();
24-
for (let i = 1; i < facetValues.length; i++) {
25-
await expect(facetValues[i]).toHaveCSS('opacity', '0.8');
26-
}
67+
test('should render links instead of checkboxes', async ({facet}) => {
68+
await facet.hydrated.waitFor();
69+
const link = await facet.component
70+
.locator('[part~="value-link"]')
71+
.first();
72+
await expect(link).toBeVisible();
2773
});
2874

29-
test('should not dim selected facet', async ({facet}) => {
30-
await expect(facet.facetValues.nth(0)).toHaveCSS('opacity', '1');
75+
test.describe('when no value is selected', () => {
76+
test('should not dim any facet values', async ({facet}) => {
77+
const facetValues = await facet.facetValues.all();
78+
for (let i = 0; i < facetValues.length; i++) {
79+
await expect(facetValues[i]).toHaveCSS('opacity', '1');
80+
}
81+
});
3182
});
32-
});
33-
});
3483

35-
test.describe('Visual Regression', () => {
36-
test('should match baseline in default state', async ({facet}) => {
37-
await facet.load({story: 'default'});
38-
await facet.hydrated.waitFor();
84+
test.describe('when selecting a value', () => {
85+
test.beforeEach(async ({facet}) => {
86+
await facet.getFacetValueButtonByPosition(0).click();
87+
});
88+
89+
test('should dim unselected facet values', async ({facet}) => {
90+
const facetValues = await facet.facetValues.all();
91+
for (let i = 1; i < facetValues.length; i++) {
92+
await expect(facetValues[i]).toHaveCSS('opacity', '0.8');
93+
}
94+
});
3995

40-
const screenshot = await facet.captureScreenshot();
41-
expect(screenshot).toMatchSnapshot('rating-facet-default.png', {
42-
maxDiffPixelRatio: 0.01,
96+
test('should not dim selected facet', async ({facet}) => {
97+
await expect(facet.facetValues.nth(0)).toHaveCSS('opacity', '1');
98+
});
99+
100+
test('should show selected link style', async ({facet}) => {
101+
const selectedLink = facet.getSelectedFacetValueLink;
102+
await expect(selectedLink).toBeVisible();
103+
});
43104
});
44105
});
45106

46-
test('should match baseline with display-as-link', async ({facet}) => {
47-
await facet.load({story: 'display-as-link'});
48-
await facet.hydrated.waitFor();
107+
test.describe('accessibility', () => {
108+
test.beforeEach(async ({facet}) => {
109+
await facet.load({story: 'default'});
110+
await facet.hydrated.waitFor();
111+
});
112+
113+
test('should have accessible facet values as list items', async ({
114+
facet,
115+
}) => {
116+
const listItems = await facet.facetValues.all();
117+
expect(listItems.length).toBeGreaterThan(0);
118+
});
49119

50-
const screenshot = await facet.captureScreenshot();
51-
expect(screenshot).toMatchSnapshot('rating-facet-display-as-link.png', {
52-
maxDiffPixelRatio: 0.01,
120+
test('should have clickable buttons for each value', async ({facet}) => {
121+
const firstButton = facet.getFacetValueButtonByPosition(0);
122+
await expect(firstButton).toBeVisible();
123+
await expect(firstButton).toBeEnabled();
124+
});
125+
126+
test('should show result counts for each value', async ({facet}) => {
127+
const counts = await facet.component
128+
.locator('[part~="value-count"]')
129+
.all();
130+
expect(counts.length).toBeGreaterThan(0);
53131
});
54132
});
55133

56-
test('should match baseline after selecting a value', async ({facet}) => {
57-
await facet.load({story: 'default'});
58-
await facet.hydrated.waitFor();
134+
test.describe('Visual Regression', () => {
135+
test('should match baseline in default state', async ({facet}) => {
136+
await facet.load({story: 'default'});
137+
await facet.hydrated.waitFor();
138+
139+
const screenshot = await facet.captureScreenshot();
140+
expect(screenshot).toMatchSnapshot('rating-facet-default.png', {
141+
maxDiffPixelRatio: 0.01,
142+
});
143+
});
144+
145+
test('should match baseline with display-as-link', async ({facet}) => {
146+
await facet.load({story: 'display-as-link'});
147+
await facet.hydrated.waitFor();
59148

60-
await facet.getFacetValueButtonByPosition(0).click();
61-
await facet.page.waitForTimeout(300);
149+
const screenshot = await facet.captureScreenshot();
150+
expect(screenshot).toMatchSnapshot('rating-facet-display-as-link.png', {
151+
maxDiffPixelRatio: 0.01,
152+
});
153+
});
154+
155+
test('should match baseline after selecting a value', async ({facet}) => {
156+
await facet.load({story: 'default'});
157+
await facet.hydrated.waitFor();
158+
159+
await facet.getFacetValueButtonByPosition(0).click();
160+
await facet.page.waitForTimeout(300);
62161

63-
const screenshot = await facet.captureScreenshot();
64-
expect(screenshot).toMatchSnapshot('rating-facet-after-selection.png', {
65-
maxDiffPixelRatio: 0.01,
162+
const screenshot = await facet.captureScreenshot();
163+
expect(screenshot).toMatchSnapshot('rating-facet-after-selection.png', {
164+
maxDiffPixelRatio: 0.01,
165+
});
66166
});
67167
});
68168
});

0 commit comments

Comments
 (0)