elinuxhenrik | 5d7de18 | 2021-02-08 15:40:38 +0100 | [diff] [blame] | 1 | /*- |
| 2 | * ========================LICENSE_START================================= |
| 3 | * O-RAN-SC |
| 4 | * %% |
| 5 | * Copyright (C) 2019 AT&T Intellectual Property |
| 6 | * %% |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * ========================LICENSE_END=================================== |
| 19 | */ |
| 20 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 21 | import { TestBed, async, ComponentFixture } from '@angular/core/testing'; |
Lathish | 095fb8c | 2021-01-28 17:14:19 +0000 | [diff] [blame] | 22 | import { RouterTestingModule } from '@angular/router/testing'; |
elinuxhenrik | 8068db8 | 2021-02-23 15:30:40 +0100 | [diff] [blame] | 23 | import { CookieService } from 'ngx-cookie-service'; |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 24 | import { AppComponent } from './app.component'; |
ychacon | ae54b92 | 2021-03-25 00:31:31 +0100 | [diff] [blame] | 25 | import { UiService } from '@services/ui/ui.service'; |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 26 | |
| 27 | describe('AppComponent', () => { |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 28 | let fixture: ComponentFixture<AppComponent>; |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 29 | let app: AppComponent; |
| 30 | let cookieServiceSpy: any; |
| 31 | let uiService: UiService; |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 32 | |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 33 | beforeEach(async(() => { |
elinuxhenrik | 8068db8 | 2021-02-23 15:30:40 +0100 | [diff] [blame] | 34 | cookieServiceSpy = jasmine.createSpyObj('CookieService', [ 'get', 'set' ]); |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 35 | TestBed.configureTestingModule({ |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 36 | imports: [ |
Lathish | 095fb8c | 2021-01-28 17:14:19 +0000 | [diff] [blame] | 37 | RouterTestingModule |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 38 | ], |
elinuxhenrik | 5d7de18 | 2021-02-08 15:40:38 +0100 | [diff] [blame] | 39 | schemas: [ |
| 40 | CUSTOM_ELEMENTS_SCHEMA |
| 41 | ], |
| 42 | declarations: [ |
| 43 | AppComponent |
| 44 | ], |
| 45 | providers: [ |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 46 | { provide: CookieService, useValue: cookieServiceSpy }, |
elinuxhenrik | 5d7de18 | 2021-02-08 15:40:38 +0100 | [diff] [blame] | 47 | UiService |
| 48 | ] |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 49 | }).compileComponents(); |
| 50 | })); |
| 51 | |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 52 | beforeEach(() => { |
| 53 | fixture = TestBed.createComponent(AppComponent); |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 54 | app = fixture.componentInstance; |
elinuxhenrik | ad70d41 | 2021-02-15 14:38:02 +0100 | [diff] [blame] | 55 | uiService = TestBed.inject(UiService); |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 56 | fixture.detectChanges(); |
| 57 | }); |
| 58 | |
elinuxhenrik | 5d7de18 | 2021-02-08 15:40:38 +0100 | [diff] [blame] | 59 | it('should create the app', () => { |
Lathish | 84d9bf6 | 2021-01-15 14:34:55 +0000 | [diff] [blame] | 60 | expect(app).toBeTruthy(); |
elinuxhenrik | 5d7de18 | 2021-02-08 15:40:38 +0100 | [diff] [blame] | 61 | }); |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 62 | |
| 63 | describe('#content', () => { |
| 64 | it('should contain oran logo', async(() => { |
| 65 | const ele = fixture.debugElement.nativeElement.querySelector('img'); |
| 66 | expect(ele.src).toContain('assets/oran-logo.png'); |
| 67 | })); |
| 68 | |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 69 | it('should contain navigation menu', async(() => { |
| 70 | const ele = fixture.debugElement.nativeElement.querySelector('nrcp-sidenav-list'); |
| 71 | expect(ele).toBeTruthy(); |
| 72 | })); |
| 73 | |
| 74 | it('should contain dark mode selector', async(() => { |
| 75 | const ele = fixture.debugElement.nativeElement.querySelector('#darkModeSwitch'); |
| 76 | expect(ele).toBeTruthy(); |
| 77 | })); |
| 78 | |
elinuxhenrik | 2b1dd82 | 2021-02-08 16:54:00 +0100 | [diff] [blame] | 79 | it('should contain heading', async(() => { |
| 80 | const ele = fixture.debugElement.nativeElement.querySelector('tspan'); |
| 81 | expect(ele.textContent.trim()).toBe('Non-RT RIC Control Panel'); |
| 82 | })); |
| 83 | |
| 84 | it('should contain router-outlet', async(() => { |
| 85 | const ele = fixture.debugElement.nativeElement.querySelector('router-outlet'); |
| 86 | expect(ele).toBeTruthy(); |
| 87 | })); |
| 88 | |
| 89 | it('should contain nrcp-footer', async(() => { |
| 90 | const ele = fixture.debugElement.nativeElement.querySelector('nrcp-footer'); |
| 91 | expect(ele).toBeTruthy(); |
| 92 | })); |
| 93 | }); |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 94 | |
| 95 | describe('#darkMode', () => { |
| 96 | it('when dark mode value yes from cookie at start should set mode to dark', () => { |
| 97 | uiService.darkModeState.next(false); // Set internal state to light mode. |
| 98 | cookieServiceSpy.get.and.returnValue('yes'); // Cookie shall return dark mode used. |
| 99 | |
| 100 | app.ngOnInit(); |
| 101 | |
| 102 | expect(uiService.getDarkMode()).toBeTruthy(); |
| 103 | expect(app.darkMode).toBeTruthy(); |
elinuxhenrik | 7ca2d23 | 2021-02-16 15:38:47 +0100 | [diff] [blame] | 104 | expect(cookieServiceSpy.get).toHaveBeenCalled(); |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 105 | }); |
| 106 | |
| 107 | it('should toggle dark mode when selector is clicked', () => { |
| 108 | const darkModeSelector = fixture.debugElement.nativeElement.querySelector('#darkModeSwitch'); |
| 109 | |
| 110 | // Toggle to light mode |
| 111 | darkModeSelector.click(); |
| 112 | expect(uiService.getDarkMode()).toBeFalsy(); |
elinuxhenrik | 8068db8 | 2021-02-23 15:30:40 +0100 | [diff] [blame] | 113 | expect(cookieServiceSpy.set).toHaveBeenCalledWith('darkMode', 'no'); |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 114 | |
| 115 | |
| 116 | // Toggle to dark mode |
| 117 | darkModeSelector.click(); |
| 118 | expect(uiService.getDarkMode()).toBeTruthy(); |
elinuxhenrik | 8068db8 | 2021-02-23 15:30:40 +0100 | [diff] [blame] | 119 | expect(cookieServiceSpy.set).toHaveBeenCalledWith('darkMode', 'yes'); |
elinuxhenrik | eb55f29 | 2021-02-10 14:44:10 +0100 | [diff] [blame] | 120 | }); |
| 121 | }); |
elinuxhenrik | 5d7de18 | 2021-02-08 15:40:38 +0100 | [diff] [blame] | 122 | }); |