Skip to content

Commit 89ecc46

Browse files
committed
fix(e2e): Correct API mocks and add waits for dropdown enablement
1 parent 3d8de37 commit 89ecc46

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

tests/e2e/csv-validator.spec.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ test.describe("CSV Data Validator Application", () => {
2121
// Set up page object
2222
csvValidatorPage = new CSVValidatorPage(page);
2323

24-
// Set up API mocks for consistent testing
24+
// Set up API mocks for consistent testing (BEFORE navigation)
2525
await setupApiMocks(page);
2626

27-
// Navigate to application
27+
// Navigate to application (AFTER mocks are set up)
2828
await csvValidatorPage.goto();
2929
});
3030

@@ -153,8 +153,8 @@ A schema for validating data.
153153
* Test 1: Schema dropdown population and selection
154154
*/
155155
test("should populate and allow selection from schema dropdown", async () => {
156-
// Wait for schemas to load in dropdown
157-
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled();
156+
// Wait for schemas to load and dropdown to be enabled (due to mocked API call)
157+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
158158

159159
// Open dropdown and verify schemas are listed
160160
await csvValidatorPage.schemaDropdownTrigger.click();
@@ -181,6 +181,8 @@ A schema for validating data.
181181
* Test 2: Schema documentation panel toggle and content
182182
*/
183183
test("should toggle schema documentation panel and display content", async () => {
184+
// Wait for dropdown to be enabled
185+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
184186
// First select a schema
185187
await csvValidatorPage.selectSchema("event");
186188

@@ -208,6 +210,8 @@ A schema for validating data.
208210
* Test 3: CSV file upload functionality
209211
*/
210212
test("should upload and display CSV file content", async () => {
213+
// Wait for dropdown to be enabled
214+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
211215
// First select a schema
212216
await csvValidatorPage.selectSchema("event");
213217

@@ -235,6 +239,8 @@ A schema for validating data.
235239
// Initially, validate button should be disabled
236240
await expect(csvValidatorPage.validateButton).toBeDisabled();
237241

242+
// Wait for dropdown to be enabled
243+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
238244
// Select a schema, button should still be disabled
239245
await csvValidatorPage.selectSchema("event");
240246
await expect(csvValidatorPage.validateButton).toBeDisabled();
@@ -254,7 +260,9 @@ A schema for validating data.
254260
* Test 5: Validation results display for valid CSV
255261
*/
256262
test("should validate and display success for valid CSV", async () => {
257-
// Set up test with schema and valid CSV
263+
// Wait for dropdown to be enabled
264+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
265+
// Select schema and upload valid CSV
258266
await csvValidatorPage.selectSchema("event");
259267
const sampleCsvPath = path.join(
260268
process.cwd(),
@@ -277,7 +285,9 @@ A schema for validating data.
277285
* Test 6: Validation results display for invalid CSV
278286
*/
279287
test("should validate and display errors for invalid CSV", async () => {
280-
// Set up test with schema and invalid CSV
288+
// Wait for dropdown to be enabled
289+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
290+
// Select schema and upload invalid CSV
281291
await csvValidatorPage.selectSchema("event");
282292
const invalidCsvPath = path.join(
283293
process.cwd(),
@@ -305,7 +315,9 @@ A schema for validating data.
305315
* Test 7 (Optional): Error highlighting when clicking on errors
306316
*/
307317
test("should highlight CSV line when clicking on error", async () => {
308-
// Set up test with schema and invalid CSV
318+
// Wait for dropdown to be enabled
319+
await expect(csvValidatorPage.schemaDropdownTrigger).toBeEnabled({ timeout: 10000 });
320+
// Select schema, upload invalid CSV, and validate
309321
await csvValidatorPage.selectSchema("event");
310322
const invalidCsvPath = path.join(
311323
process.cwd(),

tests/e2e/e2e.spec.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,57 @@ test.describe("CSV Data Validator E2E", () => {
1010
// Helper function to set up API route mocking for all tests
1111
const setupApiMocks = async (page: Page) => {
1212
console.log("Setting up API mocks...");
13-
// Mock schemas list response
14-
await page.route("**/api/schemas", async (route: Route) => {
15-
console.log("Intercepted /api/schemas");
13+
// Mock schemas list response - Updated Endpoint
14+
await page.route("**/api/list-schemas", async (route: Route) => {
15+
console.log("Intercepted /api/list-schemas");
1616
await route.fulfill({
1717
status: 200,
1818
contentType: "application/json",
1919
body: JSON.stringify({
20-
schemas: ["event.json", "place.json"],
20+
schemas: ["event.json", "place.json"], // Ensure this matches expected schema names
2121
}),
2222
});
2323
});
2424

25-
// Mock individual schema content response
26-
await page.route("**/api/schemas/event*", async (route: Route) => {
27-
console.log("Intercepted /api/schemas/event*");
25+
// Mock individual schema content response for event - Updated Endpoint
26+
await page.route("**/api/get-schema/event*", async (route: Route) => {
27+
console.log("Intercepted /api/get-schema/event*");
2828
await route.fulfill({
2929
status: 200,
3030
contentType: "application/json",
3131
body: JSON.stringify({
3232
content: {
3333
$schema: "http://json-schema.org/draft-07/schema#",
34-
title: "Sample Schema",
34+
title: "Event Schema", // Use a distinct title for clarity
3535
type: "object",
3636
properties: {
3737
id: { type: "string" },
3838
name: { type: "string" },
39+
date: { type: "string", format: "date" },
3940
},
41+
required: ["id", "name", "date"],
42+
},
43+
}),
44+
});
45+
});
46+
47+
// Mock individual schema content response for place - Added Mock
48+
await page.route("**/api/get-schema/place*", async (route: Route) => {
49+
console.log("Intercepted /api/get-schema/place*");
50+
await route.fulfill({
51+
status: 200,
52+
contentType: "application/json",
53+
body: JSON.stringify({
54+
content: {
55+
$schema: "http://json-schema.org/draft-07/schema#",
56+
title: "Place Schema", // Use a distinct title for clarity
57+
type: "object",
58+
properties: {
59+
placeId: { type: "string" },
60+
address: { type: "string" },
61+
city: { type: "string" },
62+
},
63+
required: ["placeId", "address"],
4064
},
4165
}),
4266
});

0 commit comments

Comments
 (0)