Skip to content

Commit

Permalink
[pre-commit.ci lite] apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci-lite[bot] authored Feb 13, 2024
1 parent a82f9c9 commit 2976dc3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 89 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module.exports = {
parserOptions: {
ecmaVersion: 'latest'
},
rules: {
"chai-friendly/no-unused-expressions": "off"
},
rules: {
'chai-friendly/no-unused-expressions': 'off'
},
plugins: [
'cypress',
'chai-friendly'
Expand Down
56 changes: 28 additions & 28 deletions src/main/resources/static/theme-toggle.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
(function () {
const label = document.getElementById('theme-toggle-label');
const toggle = document.getElementById('theme-toggle');
const label = document.getElementById('theme-toggle-label')
const toggle = document.getElementById('theme-toggle')

function applyDarkMode(darkMode) {
document.body.classList.toggle('dark-mode', darkMode);
label.textContent = darkMode ? '🌙' : '☀️';
localStorage.setItem('darkMode', darkMode ? 'true' : 'false');
localStorage.setItem('darkmode-pref-set', 'true');
function applyDarkMode (darkMode) {
document.body.classList.toggle('dark-mode', darkMode)
label.textContent = darkMode ? '🌙' : '☀️'
localStorage.setItem('darkMode', darkMode ? 'true' : 'false')
localStorage.setItem('darkmode-pref-set', 'true')

if (darkMode) {
label.classList.add('rotate');
} else {
label.classList.remove('rotate');
}
if (darkMode) {
label.classList.add('rotate')
} else {
label.classList.remove('rotate')
}
}

function toggleTheme() {
const darkMode = !document.body.classList.contains('dark-mode');
applyDarkMode(darkMode);
toggle.checked = darkMode;
}
function toggleTheme () {
const darkMode = !document.body.classList.contains('dark-mode')
applyDarkMode(darkMode)
toggle.checked = darkMode
}

window.addEventListener('load', () => {
const darkModePref = localStorage.getItem('darkMode') === 'true';
applyDarkMode(darkModePref);
toggle.checked = darkModePref;
window.addEventListener('load', () => {
const darkModePref = localStorage.getItem('darkMode') === 'true'
applyDarkMode(darkModePref)
toggle.checked = darkModePref

// Prevent the rotate animation on load
label.classList.add('notransition'); // Temporarily disable transition
label.offsetHeight; // Trigger reflow to apply the transition disable
label.classList.remove('notransition'); // Re-enable transitions
});
// Prevent the rotate animation on load
label.classList.add('notransition') // Temporarily disable transition
label.offsetHeight // Trigger reflow to apply the transition disable
label.classList.remove('notransition') // Re-enable transitions
})

label.onclick = toggleTheme;
})();
label.onclick = toggleTheme
})()
116 changes: 58 additions & 58 deletions src/test/e2e/cypress/integration/themeSwitch.cy.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import ThemeSwitchPage from '../pages/themeSwitchPage'

describe('Theme Switching Tests', () => {
it('A user can switch the theme to dark on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`);
cy.get('body').then(($body) => {
if (!$body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
}
});
cy.get(ThemeSwitchPage.DARK_MODE).should('exist');
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
});
});
it('A user can switch the theme to dark on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get('body').then(($body) => {
if (!$body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
}
})
cy.get(ThemeSwitchPage.DARK_MODE).should('exist')
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
})
})

it('Dark mode persists on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`);
cy.get('body').then(($body) => {
if (!$body.hasClass('dark-mode')) {
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
}
});
cy.get(ThemeSwitchPage.DARK_MODE).should('exist');
});
});
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get('body').then(($body) => {
if (!$body.hasClass('dark-mode')) {
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
}
})
cy.get(ThemeSwitchPage.DARK_MODE).should('exist')
})
})

it('A user can switch the theme to dark on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`);
cy.get('body').then(($body) => {
if ($body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
}
});
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist');
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
});
});
it('A user can switch the theme to dark on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get('body').then(($body) => {
if ($body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
}
})
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist')
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
})
})

it('A user can switch the theme to dark on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`);
cy.get('body').then(($body) => {
if ($body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
}
});
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist');
});
});
it('A user can switch the theme to dark on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get('body').then(($body) => {
if ($body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
}
})
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist')
})
})

it('A user can switch theme to dark and back to light on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`);
cy.get('body').then(($body) => {
if (!$body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
}
});
cy.get(ThemeSwitchPage.DARK_MODE).should('exist');
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click();
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist');
});
});
});
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get('body').then(($body) => {
if (!$body.hasClass('dark-mode')) { // Adjust this condition to check for light mode
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
}
})
cy.get(ThemeSwitchPage.DARK_MODE).should('exist')
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist')
})
})
})

0 comments on commit 2976dc3

Please sign in to comment.