2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
21 import { TestBed, async, ComponentFixture } from '@angular/core/testing';
22 import { RouterTestingModule } from '@angular/router/testing';
23 import { CookieService } from 'ngx-cookie-service';
24 import { AppComponent } from './app.component';
25 import { UiService } from './services/ui/ui.service';
27 describe('AppComponent', () => {
28 let fixture: ComponentFixture<AppComponent>;
29 let app: AppComponent;
30 let cookieServiceSpy: any;
31 let uiService: UiService;
33 beforeEach(async(() => {
34 cookieServiceSpy = jasmine.createSpyObj('CookieService', [ 'get', 'set' ]);
35 TestBed.configureTestingModule({
40 CUSTOM_ELEMENTS_SCHEMA
46 { provide: CookieService, useValue: cookieServiceSpy },
49 }).compileComponents();
53 fixture = TestBed.createComponent(AppComponent);
54 app = fixture.componentInstance;
55 uiService = TestBed.inject(UiService);
56 fixture.detectChanges();
59 it('should create the app', () => {
60 expect(app).toBeTruthy();
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');
69 it('should contain navigation menu', async(() => {
70 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-sidenav-list');
71 expect(ele).toBeTruthy();
74 it('should contain dark mode selector', async(() => {
75 const ele = fixture.debugElement.nativeElement.querySelector('#darkModeSwitch');
76 expect(ele).toBeTruthy();
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');
84 it('should contain router-outlet', async(() => {
85 const ele = fixture.debugElement.nativeElement.querySelector('router-outlet');
86 expect(ele).toBeTruthy();
89 it('should contain nrcp-footer', async(() => {
90 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-footer');
91 expect(ele).toBeTruthy();
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.
102 expect(uiService.getDarkMode()).toBeTruthy();
103 expect(app.darkMode).toBeTruthy();
104 expect(cookieServiceSpy.get).toHaveBeenCalled();
107 it('should toggle dark mode when selector is clicked', () => {
108 const darkModeSelector = fixture.debugElement.nativeElement.querySelector('#darkModeSwitch');
110 // Toggle to light mode
111 darkModeSelector.click();
112 expect(uiService.getDarkMode()).toBeFalsy();
113 expect(cookieServiceSpy.set).toHaveBeenCalledWith('darkMode', 'no');
116 // Toggle to dark mode
117 darkModeSelector.click();
118 expect(uiService.getDarkMode()).toBeTruthy();
119 expect(cookieServiceSpy.set).toHaveBeenCalledWith('darkMode', 'yes');