Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This repository (`SwiftChain-Frontend`) contains the frontend application built
## 🚀 Project Overview

### Core Problem

//Temproary fix for pr and commit
Traditional logistics systems suffer from:

- Lack of trust between senders and independent drivers.
Expand Down
60 changes: 60 additions & 0 deletions cypress/e2e/theme-toggle.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// cypress/e2e/theme-toggle.cy.ts

describe('E2E: Toggle Dark/Light Mode on Dashboard Overview', () => {
beforeEach(() => {
// Mock authentication to safely access the dashboard
cy.intercept('POST', '**/api/auth/login', {
statusCode: 200,
body: { success: true, token: 'mock-token' }
}).as('login');

// Set token to bypass login screen if your app uses localStorage
cy.window().then((win) => {
win.localStorage.setItem('token', 'mock-token');
});

cy.visit('/dashboard');
});

it('toggles the dashboard between light and dark modes successfully', () => {
// 1. Initial State Check (Assuming light mode default)
cy.get('html').should('not.have.class', 'dark');

// 2. Toggle to Dark Mode
cy.get('button[aria-label="Toggle Dark Mode"], button[aria-label="Toggle Theme"]')
.first()
.click();

// Verify Tailwind's 'dark' class is applied to the root element
cy.get('html').should('have.class', 'dark');

// Verify a specific CSS variable or background color change
cy.get('body').should('have.css', 'background-color')
.and((color) => {
// Checking that the color transitioned away from pure white
expect(color).to.not.equal('rgb(255, 255, 255)');
});

// 3. Toggle back to Light Mode
cy.get('button[aria-label="Toggle Dark Mode"], button[aria-label="Toggle Theme"]')
.first()
.click();

cy.get('html').should('not.have.class', 'dark');
});

it('persists theme preference across page reloads', () => {
// Toggle to Dark Mode
cy.get('button[aria-label="Toggle Dark Mode"], button[aria-label="Toggle Theme"]')
.first()
.click();

cy.get('html').should('have.class', 'dark');

// Reload the page
cy.reload();

// The dark class should still be present if preference is cached
cy.get('html').should('have.class', 'dark');
});
});
Loading