-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
151 lines (121 loc) · 4.22 KB
/
index.test.ts
File metadata and controls
151 lines (121 loc) · 4.22 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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/client',
);
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, runServer: 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);
// Check client-rendered title is visible
const clientTitle = page.locator('h1:has-text("Client rendered")');
await expect(clientTitle).toBeVisible();
await expect(clientTitle).toHaveText('Client rendered');
// Check that RSC component loaded
const rscTitle = page.locator('h2:has-text("RSC!")');
await expect(rscTitle).toBeVisible();
await expect(rscTitle).toHaveText('RSC!');
// Check that only one stylesheet is loaded (from RSC)
const links = page.locator('link[rel="stylesheet"]');
await expect(links).toHaveCount(1);
});
test('should render RSC component with styles', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
// Check RSC container exists and has class
const rscContainer = page.locator('div.rsc');
await expect(rscContainer).toBeVisible();
// Check RSC heading
const rscHeading = rscContainer.locator('h2');
await expect(rscHeading).toBeVisible();
await expect(rscHeading).toHaveText('RSC!');
// Verify styles are applied by checking computed style
const backgroundColor = await rscContainer.evaluate((el) => {
return window.getComputedStyle(el).borderColor;
});
// The RSC.css should apply border color
expect(backgroundColor).toBe('rgb(128, 128, 128)');
});
test('should display and interact with Counter component', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
// Find the counter button
const counterButton = page.locator('button:has-text("Count:")');
await expect(counterButton).toBeVisible();
// Check initial state
await expect(counterButton).toHaveText('Count: 0');
// Click the button multiple times
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 maintain Counter state across multiple interactions', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
const counterButton = page.locator('button:has-text("Count:")');
await expect(counterButton).toBeVisible();
// Increment counter 5 times
for (let i = 1; i <= 5; i++) {
await counterButton.click();
await expect(counterButton).toHaveText(`Count: ${i}`);
}
// Final state should be 5
await expect(counterButton).toHaveText('Count: 5');
});
test('should show loading state before RSC hydrates', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
// By the time we check, the RSC should already be loaded
// but we can verify the loading fallback is not present
const loadingText = page.locator('text="Loading RSC"');
await expect(loadingText).not.toBeVisible();
// And the actual RSC content is present
const rscTitle = page.locator('h2:has-text("RSC!")');
await expect(rscTitle).toBeVisible();
});
test('should properly separate client and server components', async ({
page,
dev,
build,
}) => {
await setup(dev, build, page);
// Check client component (main App)
const clientRendered = page.locator('h1:has-text("Client rendered")');
await expect(clientRendered).toBeVisible();
// Check server component (RSC)
const serverRendered = page.locator('div.rsc h2:has-text("RSC!")');
await expect(serverRendered).toBeVisible();
// Check client component inside RSC (Counter)
const counterButton = page.locator('div.rsc button:has-text("Count:")');
await expect(counterButton).toBeVisible();
// Verify Counter is interactive (client component)
await counterButton.click();
await expect(counterButton).toHaveText('Count: 1');
});