Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbush committed Jun 16, 2024
1 parent cd6febc commit b03af15
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cypress/e2e/theme-switch.cy.ts
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');
});
});

0 comments on commit b03af15

Please sign in to comment.