-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
125 lines (100 loc) · 3.36 KB
/
index.test.ts
File metadata and controls
125 lines (100 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import path from 'node:path';
import { type Build, type Dev, expect, test } from '@e2e/helper';
import type { Page } from 'playwright';
const PROJECT_DIR = path.resolve(
import.meta.dirname,
'../../../examples/static',
);
const setup = async (dev: Dev, build: Build, page: Page) => {
const rsbuild =
process.env.TEST_MODE === 'dev'
? await dev({ cwd: PROJECT_DIR })
: await build({ cwd: PROJECT_DIR, preview: true });
await page.goto(`http://localhost:${rsbuild.port}`);
return rsbuild;
};
test('should load the page and display the title', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
await expect(page).toHaveTitle('Static RSC');
const heading = page.locator('h1');
await expect(heading).toBeVisible();
await expect(heading).toHaveText('This is an RSC!');
const links = page.locator('link[rel="stylesheet"]');
await expect(links).toHaveCount(1);
});
test('should display and interact with Counter component', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
const counterButton = page.locator('button:has-text("Count:")');
await expect(counterButton).toBeVisible();
await expect(counterButton).toHaveText('Count: 0');
await counterButton.click();
await expect(counterButton).toHaveText('Count: 1');
await counterButton.click();
await expect(counterButton).toHaveText('Count: 2');
await counterButton.click();
await expect(counterButton).toHaveText('Count: 3');
});
test('should navigate to Other page via client-side navigation', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
// Click the "Other" nav link
const otherLink = page.locator('nav a:has-text("Other")');
await expect(otherLink).toBeVisible();
await otherLink.click();
// Verify heading changes
const heading = page.locator('h1');
await expect(heading).toHaveText('This is another RSC!');
// Verify URL changed
await expect(page).toHaveURL(/\/other$/);
});
test('should apply CSS styles to current nav link', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
const currentLink = page.locator('nav a[aria-current="page"]');
await expect(currentLink).toBeVisible();
const backgroundColor = await currentLink.evaluate((el) =>
window.getComputedStyle(el).getPropertyValue('background-color'),
);
expect(backgroundColor).toBe('rgb(0, 0, 0)');
const color = await currentLink.evaluate((el) =>
window.getComputedStyle(el).getPropertyValue('color'),
);
expect(color).toBe('rgb(255, 255, 255)');
});
test('should reset counter state on navigation', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
// Increment counter
const counterButton = page.locator('button:has-text("Count:")');
await counterButton.click();
await counterButton.click();
await expect(counterButton).toHaveText('Count: 2');
// Navigate to Other page
const otherLink = page.locator('nav a:has-text("Other")');
await otherLink.click();
await expect(page.locator('h1')).toHaveText('This is another RSC!');
// Navigate back to Index page
const indexLink = page.locator('nav a:has-text("Index")');
await indexLink.click();
await expect(page.locator('h1')).toHaveText('This is an RSC!');
// Counter should be reset
const resetCounter = page.locator('button:has-text("Count:")');
await expect(resetCounter).toHaveText('Count: 0');
});