|
1 | 1 | import {expect, test} from './fixture'; |
2 | 2 |
|
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 | + }); |
7 | 30 |
|
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); |
14 | 59 | }); |
15 | 60 | }); |
16 | 61 |
|
17 | | - test.describe('when selecting a value', () => { |
| 62 | + test.describe('with facet values as link', () => { |
18 | 63 | test.beforeEach(async ({facet}) => { |
19 | | - await facet.getFacetValueButtonByPosition(0).click(); |
| 64 | + await facet.load({story: 'display-as-link'}); |
20 | 65 | }); |
21 | 66 |
|
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(); |
27 | 73 | }); |
28 | 74 |
|
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 | + }); |
31 | 82 | }); |
32 | | - }); |
33 | | -}); |
34 | 83 |
|
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 | + }); |
39 | 95 |
|
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 | + }); |
43 | 104 | }); |
44 | 105 | }); |
45 | 106 |
|
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 | + }); |
49 | 119 |
|
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); |
53 | 131 | }); |
54 | 132 | }); |
55 | 133 |
|
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(); |
59 | 148 |
|
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); |
62 | 161 |
|
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 | + }); |
66 | 166 | }); |
67 | 167 | }); |
68 | 168 | }); |
0 commit comments