Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
mwskwong committed Feb 17, 2024
1 parent f146e75 commit 605b7a0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
84 changes: 42 additions & 42 deletions cypress/e2e/color-mode.cy.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { colors } from '../fixtures/colors';

describe('Color mode', () => {
const expectColorMode = (colorMode: 'dark' | 'light') => {
cy.get('html').should('have.attr', 'data-joy-color-scheme', colorMode);
cy.get('body')
.should('have.css', 'background-color', colors[colorMode].bgColor)
.and('have.css', 'color', colors[colorMode].color);
};

beforeEach(() => cy.visit('/'));

it('default is light mode', () => expectColorMode('light'));

describe('Mode toggle button', () => {
it('toggles color mode', () => {
cy.get('[data-cy="mode-toggle-button"]').click();
expectColorMode('dark');

cy.get('[data-cy="mode-toggle-button"]').click();
expectColorMode('light');
});

it('updates icon according to color mode', () => {
const expectIcon = (icon: 'sun' | 'moon') => {
cy.get('[data-cy="mode-toggle-button"]')
.find('[data-cy="moon"]')
.should(icon === 'moon' ? 'be.visible' : 'not.exist');

cy.get('[data-cy="mode-toggle-button"]')
.find('[data-cy="sun"]')
.should(icon === 'sun' ? 'be.visible' : 'not.exist');
};

expectIcon('moon');
cy.get('[data-cy="mode-toggle-button"]').click();
expectIcon('sun');
cy.get('[data-cy="mode-toggle-button"]').click();
expectIcon('moon');
});
});
});
import { colors } from '../fixtures/colors';

describe('Color mode', () => {
const expectColorMode = (colorMode: 'dark' | 'light') => {
cy.get('html').should('have.attr', 'data-joy-color-scheme', colorMode);
cy.get('body')
.should('have.css', 'background-color', colors[colorMode].bgColor)
.and('have.css', 'color', colors[colorMode].color);
};

beforeEach(() => cy.visit('/'));

it('default is light mode', () => expectColorMode('light'));

describe('Mode toggle button', () => {
it('toggles color mode', () => {
cy.get('[data-cy="mode-toggle-button"]').click();
expectColorMode('dark');

cy.get('[data-cy="mode-toggle-button"]').click();
expectColorMode('light');
});

it('updates icon according to color mode', () => {
const expectIcon = (icon: 'sun' | 'moon') => {
cy.get('[data-cy="mode-toggle-button"]')
.find('[data-cy="moon"]')
.should(icon === 'moon' ? 'be.visible' : 'not.exist');

cy.get('[data-cy="mode-toggle-button"]')
.find('[data-cy="sun"]')
.should(icon === 'sun' ? 'be.visible' : 'not.exist');
};

expectIcon('moon');
cy.get('[data-cy="mode-toggle-button"]').click();
expectIcon('sun');
cy.get('[data-cy="mode-toggle-button"]').click();
expectIcon('moon');
});
});
});
20 changes: 10 additions & 10 deletions cypress/fixtures/colors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const colors = {
light: {
bgColor: 'rgb(255, 255, 255)',
color: 'rgb(50, 56, 62)',
},
dark: {
bgColor: 'rgb(9, 9, 11)',
color: 'rgb(205, 215, 225)',
},
};
export const colors = {
light: {
bgColor: 'rgb(255, 255, 255)',
color: 'rgb(50, 56, 62)',
},
dark: {
bgColor: 'rgb(9, 9, 11)',
color: 'rgb(205, 215, 225)',
},
};

0 comments on commit 605b7a0

Please sign in to comment.