File tree Expand file tree Collapse file tree 3 files changed +21
-10
lines changed
cypress/e2e/english/landing Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -51,24 +51,29 @@ describe('Landing (Hashnode sourced)', () => {
5151
5252 it ( 'The dark mode button should be able to change the theme to dark mode from light mode' , function ( ) {
5353 visit ( false ) ;
54+ cy . get ( selectors . toggleDropDownMenuButton ) . click ( ) ;
5455 cy . get ( selectors . darkModeButton ) . click ( ) ;
5556
5657 cy . get ( 'body' , { timeout : 1000 } ) . should ( 'have.class' , 'dark-mode' ) ;
5758 } ) ;
5859
5960 it ( 'The dark mode button should be able to change the theme to light mode from dark mode' , function ( ) {
6061 visit ( true ) ;
62+ cy . get ( selectors . toggleDropDownMenuButton ) . click ( ) ;
6163 cy . get ( selectors . darkModeButton ) . click ( ) ;
6264
6365 cy . get ( 'body' , { timeout : 1000 } ) . should ( 'not.have.class' , 'dark-mode' ) ;
6466 } ) ;
6567
6668 it ( 'The theme should be set to dark and update the value in localStorage to dark' , function ( ) {
67- visit ( false ) ;
69+ cy . clearLocalStorage ( ) ;
70+ cy . clearCookies ( ) ;
71+ cy . get ( selectors . toggleDropDownMenuButton ) . click ( ) ;
6872 cy . get ( selectors . darkModeButton ) . click ( ) ;
6973 cy . window ( ) . then ( win => {
7074 expect ( win . localStorage . getItem ( 'theme' ) ) . to . equal ( 'dark' ) ;
7175 } ) ;
76+ visit ( false ) ;
7277 } ) ;
7378
7479 // Because all templates readers see use `default.njk` as a base,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ function loadDarkModePreference() {
44 window . matchMedia ( '(prefers-color-scheme: dark)' ) ?. matches ||
55 theme == 'dark'
66 ) {
7+ localStorage . setItem ( 'theme' , 'dark' ) ;
78 document . body . classList . add ( 'dark-mode' ) ;
89 }
910}
@@ -14,5 +15,10 @@ document.addEventListener('DOMContentLoaded', () => {
1415 . getElementById ( 'toggle-dark-mode' )
1516 . addEventListener ( 'click' , function ( ) {
1617 document . body . classList . toggle ( 'dark-mode' ) ;
18+ if ( document . body . classList . contains ( 'dark-mode' ) ) {
19+ localStorage . setItem ( 'theme' , 'dark' ) ;
20+ } else {
21+ localStorage . setItem ( 'theme' , 'light' ) ;
22+ }
1723 } ) ;
1824} ) ;
Original file line number Diff line number Diff line change 1818 rel =" noopener noreferrer"
1919 href =" {% t 'links:forum' %}"
2020 target =" _blank"
21- data-test-label =" forum-button"
22- >{% t ' buttons.forum' %} </a ></li >
21+ data-test-label =" forum-button" >{% t ' buttons.forum' %} </a ></li >
2322 <li ><a
2423 class =" nav-link nav-link-flex"
2524 id =" nav-learn"
2827 target =" _blank"
2928 data-test-label =" learn-button"
3029 >{% t ' buttons.learn' %} </a ></li >
30+ <li ><a
31+ class =" nav-link nav-link-flex"
32+ id =" toggle-dark-mode"
33+ data-test-label =" dark-mode-button" >
34+ {% t ' buttons.toggle-dark-mode' %} </a ></li >
3135 </ul >
3236 <a
3337 class =" toggle-button-nav"
3438 id =" nav-donate"
3539 rel =" noopener noreferrer"
3640 href =" {% t 'links:donate' %}"
3741 target =" _blank"
38- data-test-label =" donate-button"
39- >{% t ' buttons.donate' %} </a >
40- <li
41- class =" nav-link nav-link-flex"
42- id =" toggle-dark-mode"
43- data-test-label =" dark-mode-button"
44- >{% t ' buttons.toggle-dark-mode' %} </li >
42+ data-test-label =" donate-button" >
43+ {% t ' buttons.donate' %}
44+ </a >
4545 </div >
4646
4747 </div >
You can’t perform that action at this time.
0 commit comments