blob: 85580571c8229735182a1df80dd1f65ba4a0abd3 [file] [log] [blame]
elinuxhenrik5d7de182021-02-08 15:40:38 +01001/*-
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 */
20import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
elinuxhenrik2b1dd822021-02-08 16:54:00 +010021import { TestBed, async, ComponentFixture } from '@angular/core/testing';
Lathish095fb8c2021-01-28 17:14:19 +000022import { RouterTestingModule } from '@angular/router/testing';
elinuxhenrik8068db82021-02-23 15:30:40 +010023import { CookieService } from 'ngx-cookie-service';
Lathish84d9bf62021-01-15 14:34:55 +000024import { AppComponent } from './app.component';
ychaconae54b922021-03-25 00:31:31 +010025import { UiService } from '@services/ui/ui.service';
Lathish84d9bf62021-01-15 14:34:55 +000026
27describe('AppComponent', () => {
elinuxhenrik2b1dd822021-02-08 16:54:00 +010028 let fixture: ComponentFixture<AppComponent>;
elinuxhenrikeb55f292021-02-10 14:44:10 +010029 let app: AppComponent;
30 let cookieServiceSpy: any;
31 let uiService: UiService;
elinuxhenrik2b1dd822021-02-08 16:54:00 +010032
Lathish84d9bf62021-01-15 14:34:55 +000033 beforeEach(async(() => {
elinuxhenrik8068db82021-02-23 15:30:40 +010034 cookieServiceSpy = jasmine.createSpyObj('CookieService', [ 'get', 'set' ]);
Lathish84d9bf62021-01-15 14:34:55 +000035 TestBed.configureTestingModule({
Lathish84d9bf62021-01-15 14:34:55 +000036 imports: [
Lathish095fb8c2021-01-28 17:14:19 +000037 RouterTestingModule
Lathish84d9bf62021-01-15 14:34:55 +000038 ],
elinuxhenrik5d7de182021-02-08 15:40:38 +010039 schemas: [
40 CUSTOM_ELEMENTS_SCHEMA
41 ],
42 declarations: [
43 AppComponent
44 ],
45 providers: [
elinuxhenrikeb55f292021-02-10 14:44:10 +010046 { provide: CookieService, useValue: cookieServiceSpy },
elinuxhenrik5d7de182021-02-08 15:40:38 +010047 UiService
48 ]
Lathish84d9bf62021-01-15 14:34:55 +000049 }).compileComponents();
50 }));
51
elinuxhenrik2b1dd822021-02-08 16:54:00 +010052 beforeEach(() => {
53 fixture = TestBed.createComponent(AppComponent);
elinuxhenrikeb55f292021-02-10 14:44:10 +010054 app = fixture.componentInstance;
elinuxhenrikad70d412021-02-15 14:38:02 +010055 uiService = TestBed.inject(UiService);
elinuxhenrik2b1dd822021-02-08 16:54:00 +010056 fixture.detectChanges();
57 });
58
elinuxhenrik5d7de182021-02-08 15:40:38 +010059 it('should create the app', () => {
Lathish84d9bf62021-01-15 14:34:55 +000060 expect(app).toBeTruthy();
elinuxhenrik5d7de182021-02-08 15:40:38 +010061 });
elinuxhenrik2b1dd822021-02-08 16:54:00 +010062
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
elinuxhenrikeb55f292021-02-10 14:44:10 +010069 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
elinuxhenrik2b1dd822021-02-08 16:54:00 +010079 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 });
elinuxhenrikeb55f292021-02-10 14:44:10 +010094
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();
elinuxhenrik7ca2d232021-02-16 15:38:47 +0100104 expect(cookieServiceSpy.get).toHaveBeenCalled();
elinuxhenrikeb55f292021-02-10 14:44:10 +0100105 });
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();
elinuxhenrik8068db82021-02-23 15:30:40 +0100113 expect(cookieServiceSpy.set).toHaveBeenCalledWith('darkMode', 'no');
elinuxhenrikeb55f292021-02-10 14:44:10 +0100114
115
116 // Toggle to dark mode
117 darkModeSelector.click();
118 expect(uiService.getDarkMode()).toBeTruthy();
elinuxhenrik8068db82021-02-23 15:30:40 +0100119 expect(cookieServiceSpy.set).toHaveBeenCalledWith('darkMode', 'yes');
elinuxhenrikeb55f292021-02-10 14:44:10 +0100120 });
121 });
elinuxhenrik5d7de182021-02-08 15:40:38 +0100122});