Skip to content

Commit 686d943

Browse files
committed
test(segment-view): add a test for the proper content being displayed
1 parent ba28530 commit 686d943

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
/**
5+
* This behavior does not vary across modes/directions
6+
*/
7+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
8+
test.describe(title('segment-view: basic'), () => {
9+
test('should show the first content with no initial value', async ({ page }) => {
10+
await page.setContent(
11+
`
12+
<ion-segment>
13+
<ion-segment-button content-id="paid" value="paid">
14+
<ion-label>Paid</ion-label>
15+
</ion-segment-button>
16+
<ion-segment-button content-id="free" value="free">
17+
<ion-label>Free</ion-label>
18+
</ion-segment-button>
19+
<ion-segment-button content-id="top" value="top">
20+
<ion-label>Top</ion-label>
21+
</ion-segment-button>
22+
</ion-segment>
23+
</ion-toolbar>
24+
<ion-segment-view>
25+
<ion-segment-content id="paid">Paid</ion-segment-content>
26+
<ion-segment-content id="free">Free</ion-segment-content>
27+
<ion-segment-content id="top">Top</ion-segment-content>
28+
</ion-segment-view>
29+
`,
30+
config
31+
);
32+
33+
const segmentContent = page.locator('ion-segment-content[id="paid"]');
34+
await expect(segmentContent).toBeInViewport();
35+
});
36+
37+
test('should show the content matching the initial value', async ({ page }) => {
38+
await page.setContent(
39+
`
40+
<ion-segment value="free">
41+
<ion-segment-button content-id="paid" value="paid">
42+
<ion-label>Paid</ion-label>
43+
</ion-segment-button>
44+
<ion-segment-button content-id="free" value="free">
45+
<ion-label>Free</ion-label>
46+
</ion-segment-button>
47+
<ion-segment-button content-id="top" value="top">
48+
<ion-label>Top</ion-label>
49+
</ion-segment-button>
50+
</ion-segment>
51+
</ion-toolbar>
52+
<ion-segment-view>
53+
<ion-segment-content id="paid">Paid</ion-segment-content>
54+
<ion-segment-content id="free">Free</ion-segment-content>
55+
<ion-segment-content id="top">Top</ion-segment-content>
56+
</ion-segment-view>
57+
`,
58+
config
59+
);
60+
61+
const segmentContent = page.locator('ion-segment-content[id="free"]');
62+
await expect(segmentContent).toBeInViewport();
63+
});
64+
65+
test('should update the content when changing the value by clicking a segment button', async ({ page }) => {
66+
await page.setContent(
67+
`
68+
<ion-segment value="free">
69+
<ion-segment-button content-id="paid" value="paid">
70+
<ion-label>Paid</ion-label>
71+
</ion-segment-button>
72+
<ion-segment-button content-id="free" value="free">
73+
<ion-label>Free</ion-label>
74+
</ion-segment-button>
75+
<ion-segment-button content-id="top" value="top">
76+
<ion-label>Top</ion-label>
77+
</ion-segment-button>
78+
</ion-segment>
79+
</ion-toolbar>
80+
<ion-segment-view>
81+
<ion-segment-content id="paid">Paid</ion-segment-content>
82+
<ion-segment-content id="free">Free</ion-segment-content>
83+
<ion-segment-content id="top">Top</ion-segment-content>
84+
</ion-segment-view>
85+
`,
86+
config
87+
);
88+
89+
await page.click('ion-segment-button[value="top"]');
90+
91+
const segmentContent = page.locator('ion-segment-content[id="top"]');
92+
await expect(segmentContent).toBeInViewport();
93+
});
94+
});
95+
});

0 commit comments

Comments
 (0)