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
67test . 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} ) ;
0 commit comments