11/**
2- * E2E Tests for Login & Logout Flows
2+ * @fileoverview E2E Tests for Login & Logout Flows
3+ * Tests authentication workflow, session persistence, and protected routes.
34 * Split from auth_happy_unhappy.cy.js for file size optimization
5+ * @module cypress/e2e/auth_login_logout
46 */
7+
58import { visitLogin , expectUrlToEqual , expectUrlToContain , fillLoginForm , submitForm , logMessage } from '../support/helpers' ;
69
10+ /**
11+ * Test suite for authentication flows.
12+ * Covers login, logout, session persistence, and route protection.
13+ */
714describe ( 'Login & Logout Flows' , ( ) => {
15+ // Clear state before each test for isolation
816 beforeEach ( ( ) => { cy . clearLocalStorage ( ) ; cy . clearCookies ( ) ; } ) ;
917
18+ /**
19+ * Login Page Tests
20+ * Verify login form renders and authentication succeeds with valid credentials.
21+ */
1022 describe ( 'Login Page' , ( ) => {
23+ // Test: Page loads correctly
1124 it ( 'should load the login page' , ( ) => {
1225 visitLogin ( ) ;
1326 cy . contains ( / l o g i n / i) . should ( 'be.visible' ) ;
1427 } ) ;
1528
29+ // Test: Login with custom test user fixture
1630 it ( 'should successfully log in with valid credentials' , ( ) => {
1731 cy . loginAsTestUser ( 'validUser' ) ;
1832 expectUrlToEqual ( '/' ) ;
1933 cy . shouldBeAuthenticated ( ) ;
2034 logMessage ( '✅ Successfully logged in with test user' ) ;
2135 } ) ;
2236
37+ // Test: Login with hardcoded demo credentials
2338 it ( 'should log in with demo user credentials' , ( ) => {
2439 cy . login ( 'user1@example.com' , 'password123' ) ;
2540 cy . url ( ) . should ( 'not.include' , '/login' ) ;
@@ -28,7 +43,12 @@ describe('Login & Logout Flows', () => {
2843 } ) ;
2944 } ) ;
3045
46+ /**
47+ * Logout Tests
48+ * Verify logout clears session and redirects appropriately.
49+ */
3150 describe ( 'Logout' , ( ) => {
51+ // Test: Programmatic logout
3252 it ( 'should successfully log out' , ( ) => {
3353 cy . loginAsTestUser ( 'validUser' ) ;
3454 cy . url ( ) . should ( 'not.include' , '/login' ) ;
@@ -37,6 +57,7 @@ describe('Login & Logout Flows', () => {
3757 logMessage ( '✅ Successfully logged out' ) ;
3858 } ) ;
3959
60+ // Test: Logout via UI dropdown button
4061 it ( 'should log out via UI logout button' , ( ) => {
4162 cy . loginAsTestUser ( 'validUser' ) ;
4263 cy . get ( '[data-cy="user-dropdown-trigger"]' ) . should ( 'be.visible' ) . click ( ) ;
@@ -47,7 +68,12 @@ describe('Login & Logout Flows', () => {
4768 } ) ;
4869 } ) ;
4970
71+ /**
72+ * Session Persistence Tests
73+ * Verify session survives page reloads and data is stored correctly.
74+ */
5075 describe ( 'Session Persistence' , ( ) => {
76+ // Test: Session survives reload
5177 it ( 'should maintain session after page reload' , ( ) => {
5278 cy . loginAsTestUser ( 'validUser' ) ;
5379 expectUrlToEqual ( '/' ) ;
@@ -57,6 +83,7 @@ describe('Login & Logout Flows', () => {
5783 logMessage ( '✅ Session persists after page reload' ) ;
5884 } ) ;
5985
86+ // Test: User data in localStorage is correct
6087 it ( 'should restore user data from localStorage' , ( ) => {
6188 cy . loginAsTestUser ( 'validUser' ) ;
6289 cy . window ( ) . its ( 'localStorage.user' ) . should ( 'exist' ) ;
@@ -69,7 +96,12 @@ describe('Login & Logout Flows', () => {
6996 } ) ;
7097 } ) ;
7198
99+ /**
100+ * Protected Route Tests
101+ * Verify authenticated users can access protected routes.
102+ */
72103 describe ( 'Protected Routes' , ( ) => {
104+ // Test: Authenticated access to profile page
73105 it ( 'should allow access to protected route when authenticated' , ( ) => {
74106 cy . loginAsTestUser ( 'validUser' ) ;
75107 cy . visit ( '/profile' ) ;
0 commit comments