-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
describe('ThemeSwitch Component', () => { | ||
beforeEach(() => { | ||
cy.visit('http://localhost:4321'); | ||
}); | ||
|
||
it('should display the theme switch', () => { | ||
cy.get('.switch').should('exist'); | ||
cy.get('.switch input').should('have.attr', 'type', 'checkbox'); | ||
}); | ||
|
||
it('should toggle dark mode when the switch is clicked', () => { | ||
cy.get('html').should('not.have.class', 'dark'); | ||
cy.get('.switch input').check({ force: true }).should(() => { | ||
expect(localStorage.getItem('darkMode')).to.eq('true'); | ||
}); | ||
cy.get('html').should('have.class', 'dark'); | ||
|
||
cy.get('.switch input').uncheck({ force: true }).should(() => { | ||
expect(localStorage.getItem('darkMode')).to.eq('false'); | ||
}); | ||
cy.get('html').should('not.have.class', 'dark'); | ||
}); | ||
|
||
it('should retain the theme preference after page reload', () => { | ||
cy.get('.switch input').check({ force: true }); | ||
cy.reload(); | ||
cy.get('html').should('have.class', 'dark'); | ||
cy.get('.switch input').should('be.checked'); | ||
|
||
cy.get('.switch input').uncheck({ force: true }); | ||
cy.reload(); | ||
cy.get('html').should('not.have.class', 'dark'); | ||
cy.get('.switch input').should('not.be.checked'); | ||
}); | ||
}); |