11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2+ import { CookieService } from 'ngx-cookie-service' ;
3+ import { FeatureToggle } from 'src/environments/enum' ;
24
35import { DarkModeComponent } from './dark-mode.component' ;
46
57describe ( 'DarkModeComponent' , ( ) => {
68 let component : DarkModeComponent ;
79 let fixture : ComponentFixture < DarkModeComponent > ;
10+ let cookieService : CookieService ;
811
912 beforeEach ( async ( ) => {
1013 await TestBed . configureTestingModule ( {
@@ -14,6 +17,7 @@ describe('DarkModeComponent', () => {
1417
1518 beforeEach ( ( ) => {
1619 fixture = TestBed . createComponent ( DarkModeComponent ) ;
20+ cookieService = TestBed . inject ( CookieService ) ;
1721 component = fixture . componentInstance ;
1822 fixture . detectChanges ( ) ;
1923 } ) ;
@@ -26,32 +30,32 @@ describe('DarkModeComponent', () => {
2630 expect ( component ) . toBeTruthy ( ) ;
2731 } ) ;
2832
29- it ( 'should be clear the default theme' , ( ) => {
30- expect ( component . theme ) . toBe ( 'light' ) ;
33+ it ( 'should be light the default theme' , ( ) => {
34+ expect ( component . theme ) . toEqual ( 'light' ) ;
3135 } ) ;
3236
3337 it ( 'should change the value of the theme property if it exists in the local storage' , ( ) => {
3438 localStorage . setItem ( 'theme' , 'dark' ) ;
3539 component . checkThemeInLocalStorage ( ) ;
36- expect ( component . theme ) . toBe ( 'dark' ) ;
40+ expect ( component . theme ) . toEqual ( 'dark' ) ;
3741 } ) ;
3842
3943 it ( 'should be light theme if it does not exist in local storage' , ( ) => {
4044 component . checkThemeInLocalStorage ( ) ;
41- expect ( component . theme ) . toBe ( 'light' ) ;
45+ expect ( component . theme ) . toEqual ( 'light' ) ;
4246 } ) ;
4347
4448 it ( 'should be light theme if only the theme property exists in local storage and not its value' , ( ) => {
4549 localStorage . setItem ( 'theme' , '' ) ;
4650 component . checkThemeInLocalStorage ( ) ;
47- expect ( component . theme ) . toBe ( 'light' ) ;
51+ expect ( component . theme ) . toEqual ( 'light' ) ;
4852 } ) ;
4953
5054 it ( 'should switch to dark theme if the theme property is light and vice versa' , ( ) => {
5155 component . theme = component . setTheme ( ) ;
52- expect ( component . theme ) . toBe ( 'dark' ) ;
56+ expect ( component . theme ) . toEqual ( 'dark' ) ;
5357 component . theme = component . setTheme ( ) ;
54- expect ( component . theme ) . toBe ( 'light' ) ;
58+ expect ( component . theme ) . toEqual ( 'light' ) ;
5559 } ) ;
5660
5761 it ( 'should add the dark class in the html tag to apply dark mode' , ( ) => {
@@ -63,9 +67,19 @@ describe('DarkModeComponent', () => {
6367 } ) ;
6468
6569 it ( 'should be changed to dark mode if the mode toggle is selected' , ( ) => {
70+ component . isFeatureToggleDarkModeActive = true ;
71+ fixture . detectChanges ( ) ;
6672 component . themeToggle . nativeElement . click ( ) ;
6773 fixture . detectChanges ( ) ;
68- expect ( component . theme ) . toBe ( 'dark' ) ;
69- expect ( localStorage . getItem ( 'theme' ) ) . toBe ( 'dark' ) ;
74+ expect ( component . theme ) . toEqual ( 'dark' ) ;
75+ expect ( localStorage . getItem ( 'theme' ) ) . toEqual ( 'dark' ) ;
76+ } ) ;
77+
78+ it ( 'call switchThemeToggleStyles() when ngAfterViewInit is called and isFeatureToggleDarkModeActive is true' , ( ) => {
79+ component . isFeatureToggleDarkModeActive = true ;
80+ fixture . detectChanges ( ) ;
81+ component . ngAfterViewInit ( ) ;
82+ fixture . detectChanges ( ) ;
83+ expect ( component . themeToggle . nativeElement . classList . contains ( 'bg-warning' ) ) . toBe ( true ) ;
7084 } ) ;
7185} ) ;
0 commit comments