Skip to content

Commit b702ac5

Browse files
committed
tests: fix failures
Signed-off-by: ivelin <[email protected]>
1 parent 348a4a1 commit b702ac5

File tree

2 files changed

+33
-49
lines changed

2 files changed

+33
-49
lines changed

tests/e2e/docs.spec.ts

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,57 @@
1-
// File path: tests/e2e/docs.spec.ts
2-
// E2E tests for documentation pages, including mobile menu toggle and CTA visibility
3-
4-
import { test, expect, devices } from '@playwright/test';
1+
// tests/e2e/docs.spec.ts
2+
// End-to-end tests for K12Beast documentation pages
3+
// Verifies rendering, navigation, and mobile menu functionality
4+
import { test, expect } from '@playwright/test';
5+
import { loginUser } from './utils';
56

67
test.describe('Documentation Pages', () => {
78
test('Docs page loads', async ({ page }) => {
8-
await page.goto('/public/docs/parents/introduction');
9-
await expect(page.locator('h1')).toContainText('Introduction for Parents');
9+
await page.goto('/public/docs/parents');
10+
await expect(page.locator('h1')).toContainText('Parents');
1011
});
1112

1213
test('Mobile menu toggle works', async ({ page }) => {
13-
// Use mobile viewport to simulate a phone
14-
await page.setViewportSize(devices['iPhone 12'].viewport);
15-
16-
// Navigate to a documentation page
17-
await page.goto('/public/docs/parents/introduction');
14+
await page.setViewportSize({ width: 375, height: 667 });
15+
await page.goto('/public/docs/parents');
1816

1917
// Verify the menu button is visible on mobile
2018
const menuButton = page.locator('label[aria-label="Toggle menu"]');
2119
await expect(menuButton).toBeVisible({ timeout: 5000 });
2220

2321
// Verify the sidebar is initially hidden
2422
const sidebar = page.locator('aside');
25-
await expect(sidebar).toHaveCSS('display', 'none');
23+
await expect(sidebar).toHaveCSS('display', 'none'); // Check CSS hidden state
2624

27-
// Click the menu button to open the sidebar
25+
// Toggle the menu to show sidebar
2826
await menuButton.click();
29-
// Add a brief delay to ensure the DOM updates
30-
await page.waitForTimeout(1000);
31-
await expect(sidebar).toHaveCSS('display', 'block');
27+
await expect(sidebar).toHaveCSS('display', 'block'); // Check CSS visible state
3228

33-
// Verify key navigation links are visible in the sidebar
34-
await expect(page.getByRole('link', { name: 'Parents' })).toBeVisible();
35-
await expect(page.getByRole('link', { name: 'Students' })).toBeVisible();
36-
37-
// Click the menu button again to close the sidebar
29+
// Toggle back to hide sidebar
3830
await menuButton.click();
39-
await page.waitForTimeout(1000);
4031
await expect(sidebar).toHaveCSS('display', 'none');
4132
});
4233

4334
test.describe('CTA Visibility', () => {
44-
test('CTA is hidden for logged-in users', async ({ page }) => {
45-
// Simulate a logged-in user by setting the supabase-auth-token cookie
46-
await page.context().addCookies([{
47-
name: 'supabase-auth-token',
48-
value: 'dummy-token',
49-
domain: 'localhost',
50-
path: '/',
51-
}]);
52-
53-
// Navigate to the documentation page
54-
await page.goto('/public/docs/parents/introduction');
35+
test('CTA is visible for logged-out users', async ({ page, context }) => {
36+
// Clear cookies to ensure logged-out state
37+
await context.clearCookies();
38+
await page.goto('/public/docs/parents');
5539

56-
// Verify the CTA button is not visible
40+
// Verify the CallToAction button is visible
5741
const ctaButton = page.getByText("Sign up to start supporting your child’s learning");
58-
await expect(ctaButton).not.toBeVisible();
42+
await expect(ctaButton).toBeVisible();
43+
// Ensure the button links to the signup page
44+
const link = ctaButton.locator('xpath=ancestor-or-self::a');
45+
await expect(link).toHaveAttribute('href', '/public/signup');
5946
});
6047

61-
test('CTA is visible for logged-out users', async ({ page }) => {
62-
// Ensure no supabase-auth-token cookie is present (clear cookies)
63-
await page.context().clearCookies();
64-
65-
// Navigate to the documentation page
66-
await page.goto('/public/docs/parents/introduction');
48+
test('CTA is hidden for logged-in users', async ({ page }) => {
49+
await loginUser(page);
50+
await page.goto('/public/docs/parents');
6751

68-
// Verify the CTA button is visible
52+
// Verify the CallToAction button is not visible
6953
const ctaButton = page.getByText("Sign up to start supporting your child’s learning");
70-
await expect(ctaButton).toBeVisible();
54+
await expect(ctaButton).not.toBeVisible();
7155
});
7256
});
7357
});

tests/e2e/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// File path: tests/e2e/utils.ts
1+
// tests/e2e/utils.ts
22
// Reusable utility functions for E2E tests
33

4-
import { Page, BrowserContext } from "@playwright/test";
4+
import { Page } from "@playwright/test";
55

66
// Login utility function that can be used in both fixtures and global setup
7-
export async function loginUser(page: Page, context: BrowserContext) {
7+
export async function loginUser(page: Page) {
88
const testUserEmail = process.env.TEST_USER_EMAIL;
99
const testUserPassword = process.env.TEST_USER_PASSWORD;
1010

@@ -61,13 +61,13 @@ export async function loginUser(page: Page, context: BrowserContext) {
6161

6262
// Log additional context for debugging without sensitive information
6363
console.log('Current URL after login attempt:', page.url());
64-
console.log('Cookies after login attempt (count):', (await context.cookies()).length);
64+
console.log('Cookies after login attempt (count):', (await page.context().cookies()).length);
6565
console.log('Page content after login attempt:', await page.content().catch(e => `Failed to get page content: ${e.message}`));
66-
throw new Error(`Failed to redirect to /chat/new/: ${error.message}`);
66+
throw new Error(`Failed to redirect to /chat/new/: ${(error as Error).message}`);
6767
}
6868

6969
// Verify authentication by checking for the presence of the auth token cookie
70-
const cookies = await context.cookies();
70+
const cookies = await page.context().cookies();
7171
const authTokenCookie = cookies.find(cookie => cookie.name === 'supabase-auth-token');
7272
if (!authTokenCookie) {
7373
throw new Error("Supabase auth token cookie not set after login");

0 commit comments

Comments
 (0)