From 4a7ef6d637bc05d9080d42156e7ac8f40267c889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Sat, 26 Jun 2021 14:33:58 +0200 Subject: [PATCH] Adjusting some frontend tests --- Frontend/karma.conf.js | 59 ++++++++-------- Frontend/src/app/app.component.spec.ts | 6 +- Frontend/src/app/app.component.ts | 5 +- Frontend/src/app/app.module.ts | 2 +- Frontend/src/app/app.routing.ts | 12 ++-- .../registration.component.spec.ts | 65 ++++++++++++----- .../auth/signin/signin.component.spec.ts | 65 ++++++++++++----- .../copyright/copyright.component.css | 24 +++++++ .../copyright/copyright.component.html | 8 ++- .../hot-deals-widget.component.spec.ts | 69 ++++++++++++++----- .../kunden/kunden.component.spec.ts | 64 ++++++++++++----- .../product-details.component.spec.ts | 5 ++ .../product-list.component.spec.ts | 3 +- .../product-list/product-list.component.ts | 2 +- .../profile/profile.component.spec.ts | 25 ------- .../top-bar/top-bar.component.spec.ts | 59 +++++++++++----- .../app/pages/imprint/imprint.component.html | 7 +- .../landingpage/landingpage.component.ts | 3 +- .../app/pages/privacy/privacy.component.html | 7 +- .../profile/profile.component.css | 0 .../profile/profile.component.html | 0 .../pages/profile/profile.component.spec.ts | 47 +++++++++++++ .../profile/profile.component.ts | 0 Frontend/src/app/services/api.service.ts | 2 +- 24 files changed, 370 insertions(+), 169 deletions(-) delete mode 100644 Frontend/src/app/components/profile/profile.component.spec.ts rename Frontend/src/app/{components => pages}/profile/profile.component.css (100%) rename Frontend/src/app/{components => pages}/profile/profile.component.html (100%) create mode 100644 Frontend/src/app/pages/profile/profile.component.spec.ts rename Frontend/src/app/{components => pages}/profile/profile.component.ts (100%) diff --git a/Frontend/karma.conf.js b/Frontend/karma.conf.js index 74211c5..4a72f2c 100644 --- a/Frontend/karma.conf.js +++ b/Frontend/karma.conf.js @@ -2,32 +2,35 @@ // https://karma-runner.github.io/1.0/config/configuration-file.html module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-firefox-launcher'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular-devkit/build-angular/plugins/karma') - ], - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - coverageIstanbulReporter: { - dir: require('path').join(__dirname, './coverage/Betterzon'), - reports: ['html', 'lcovonly', 'text-summary'], - fixWebpackSourcePaths: true - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Firefox'], - singleRun: false, - restartOnFileChange: true - }); + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-firefox-launcher'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage-istanbul-reporter'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + clearContext: false, // leave Jasmine Spec Runner output visible in browser + jasmine: { + random: false + } + }, + coverageIstanbulReporter: { + dir: require('path').join(__dirname, './coverage/Betterzon'), + reports: ['html', 'lcovonly', 'text-summary'], + fixWebpackSourcePaths: true + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Firefox'], + singleRun: false, + restartOnFileChange: true + }); }; diff --git a/Frontend/src/app/app.component.spec.ts b/Frontend/src/app/app.component.spec.ts index a309d0b..702527d 100644 --- a/Frontend/src/app/app.component.spec.ts +++ b/Frontend/src/app/app.component.spec.ts @@ -1,8 +1,8 @@ import {TestBed} from '@angular/core/testing'; import {AppComponent} from './app.component'; -import {RouterTestingModule} from "@angular/router/testing"; -import {NgcCookieConsentConfig, NgcCookieConsentModule} from "ngx-cookieconsent"; -import {FormsModule} from "@angular/forms"; +import {RouterTestingModule} from '@angular/router/testing'; +import {NgcCookieConsentConfig, NgcCookieConsentModule} from 'ngx-cookieconsent'; +import {FormsModule} from '@angular/forms'; // For cookie consent module testing const cookieConfig: NgcCookieConsentConfig = { diff --git a/Frontend/src/app/app.component.ts b/Frontend/src/app/app.component.ts index f65d28c..0941258 100644 --- a/Frontend/src/app/app.component.ts +++ b/Frontend/src/app/app.component.ts @@ -1,7 +1,7 @@ import {Component, OnDestroy, OnInit} from '@angular/core'; import {NgcCookieConsentService, NgcInitializeEvent, NgcNoCookieLawEvent, NgcStatusChangeEvent} from 'ngx-cookieconsent'; import {Subscription} from 'rxjs'; -import {ApiService} from "./services/api.service"; +import {ApiService} from './services/api.service'; @Component({ @@ -26,8 +26,7 @@ export class AppComponent implements OnInit, OnDestroy { username?: string; constructor( - private ccService: NgcCookieConsentService, - private api: ApiService + private ccService: NgcCookieConsentService ) { } diff --git a/Frontend/src/app/app.module.ts b/Frontend/src/app/app.module.ts index 153ae2c..246d159 100644 --- a/Frontend/src/app/app.module.ts +++ b/Frontend/src/app/app.module.ts @@ -38,7 +38,7 @@ import { CopyrightComponent } from './components/copyright/copyright.component'; import { GreetingInfoSliderComponent } from './components/greeting-info-slider/greeting-info-slider.component'; import { KundenComponent } from './components/kunden/kunden.component'; import { AboutUsComponent } from './components/about-us/about-us.component'; -import { ProfileComponent } from './components/profile/profile.component'; +import { ProfileComponent } from './pages/profile/profile.component'; import { ProfilePageComponent } from './pages/profile-page/profile-page.component'; // For cookie popup diff --git a/Frontend/src/app/app.routing.ts b/Frontend/src/app/app.routing.ts index 2e13ded..0582366 100644 --- a/Frontend/src/app/app.routing.ts +++ b/Frontend/src/app/app.routing.ts @@ -9,10 +9,10 @@ import {ProductSearchPageComponent} from './pages/product-search-page/product-se import {PageNotFoundPageComponent} from './pages/page-not-found-page/page-not-found-page.component'; import {ImprintComponent} from './pages/imprint/imprint.component'; import {PrivacyComponent} from './pages/privacy/privacy.component'; -import {SigninComponent} from "./components/auth/signin/signin.component"; -import {RegistrationComponent} from "./components/auth/registration/registration.component"; -import {ProfileComponent} from "./components/profile/profile.component"; -import {ProfilePageComponent} from "./pages/profile-page/profile-page.component"; +import {SigninComponent} from './components/auth/signin/signin.component'; +import {RegistrationComponent} from './components/auth/registration/registration.component'; +import {ProfileComponent} from './pages/profile/profile.component'; +import {ProfilePageComponent} from './pages/profile-page/profile-page.component'; const routes: Routes = [ {path: '', component: LandingpageComponent, pathMatch: 'full'}, @@ -22,8 +22,8 @@ const routes: Routes = [ {path: 'datenschutz', component: PrivacyComponent}, {path: 'signin', component: SigninComponent}, {path: 'registration', component: RegistrationComponent}, - {path: "product-detail", component: ProductDetailPageComponent}, - {path: "profile", component: ProfilePageComponent}, + {path: 'product-detail', component: ProductDetailPageComponent}, + {path: 'profile', component: ProfilePageComponent}, {path: '**', component: PageNotFoundPageComponent} ]; diff --git a/Frontend/src/app/components/auth/registration/registration.component.spec.ts b/Frontend/src/app/components/auth/registration/registration.component.spec.ts index 6c3a576..bc8f6fe 100644 --- a/Frontend/src/app/components/auth/registration/registration.component.spec.ts +++ b/Frontend/src/app/components/auth/registration/registration.component.spec.ts @@ -1,25 +1,54 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import {ComponentFixture, TestBed} from '@angular/core/testing'; -import { RegistrationComponent } from './registration.component'; +import {RegistrationComponent} from './registration.component'; +import {AbstractMockObservableService} from '../../../mocks/mock.service'; +import {ApiService} from '../../../services/api.service'; +import {FormBuilder, FormControl, Validators} from '@angular/forms'; +import {Router} from '@angular/router'; + +class MockApiService extends AbstractMockObservableService { + registerUser(username: string, password: string, email: string): any { + this.content = []; + return this; + } +} describe('RegistrationComponent', () => { - let component: RegistrationComponent; - let fixture: ComponentFixture; + let component: RegistrationComponent; + let fixture: ComponentFixture; + let mockService; + let formBuilder: FormBuilder; + const router = { + navigate: jasmine.createSpy('navigate'), + routerState: jasmine.createSpy('routerState') + }; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ RegistrationComponent ] - }) - .compileComponents(); - }); + beforeEach(async () => { + mockService = new MockApiService(); + await TestBed.configureTestingModule({ + declarations: [RegistrationComponent], + providers: [{provide: ApiService, useValue: mockService}, {provide: Router, useValue: router}, FormBuilder] + }) + .compileComponents(); + }); - beforeEach(() => { - fixture = TestBed.createComponent(RegistrationComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(RegistrationComponent); + component = fixture.componentInstance; + formBuilder = TestBed.get(FormBuilder); + component.form = formBuilder.group({ + recipientTypes: new FormControl( + { + value: ['mock'], + disabled: true + }, + Validators.required + ) + }); + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/Frontend/src/app/components/auth/signin/signin.component.spec.ts b/Frontend/src/app/components/auth/signin/signin.component.spec.ts index b19d8bf..813162a 100644 --- a/Frontend/src/app/components/auth/signin/signin.component.spec.ts +++ b/Frontend/src/app/components/auth/signin/signin.component.spec.ts @@ -1,25 +1,54 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import {ComponentFixture, TestBed} from '@angular/core/testing'; -import { SigninComponent } from './signin.component'; +import {SigninComponent} from './signin.component'; +import {AbstractMockObservableService} from '../../../mocks/mock.service'; +import {ApiService} from '../../../services/api.service'; +import {FormBuilder, FormControl, Validators} from '@angular/forms'; +import {Router} from '@angular/router'; + +class MockApiService extends AbstractMockObservableService { + loginUser(username: string, password: string): any { + this.content = []; + return this; + } +} describe('SigninComponent', () => { - let component: SigninComponent; - let fixture: ComponentFixture; + let component: SigninComponent; + let fixture: ComponentFixture; + let mockService; + let formBuilder: FormBuilder; + const router = { + navigate: jasmine.createSpy('navigate'), + routerState: jasmine.createSpy('routerState') + }; - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ SigninComponent ] - }) - .compileComponents(); - }); + beforeEach(async () => { + mockService = new MockApiService(); + await TestBed.configureTestingModule({ + declarations: [SigninComponent], + providers: [{provide: ApiService, useValue: mockService}, {provide: Router, useValue: router}, FormBuilder] + }) + .compileComponents(); + }); - beforeEach(() => { - fixture = TestBed.createComponent(SigninComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(SigninComponent); + component = fixture.componentInstance; + formBuilder = TestBed.get(FormBuilder); + component.loginForm = formBuilder.group({ + recipientTypes: new FormControl( + { + value: ['mock'], + disabled: true + }, + Validators.required + ) + }); + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/Frontend/src/app/components/copyright/copyright.component.css b/Frontend/src/app/components/copyright/copyright.component.css index e69de29..81713a1 100644 --- a/Frontend/src/app/components/copyright/copyright.component.css +++ b/Frontend/src/app/components/copyright/copyright.component.css @@ -0,0 +1,24 @@ +#imprintSection { + right: 1em; + bottom: 1em; + width: 100%; + text-align: right; + padding-right: 1em; + grid-area: right; +} + +#imprintSection a { + color: white; + text-decoration: none; +} + +#copyright { + display: grid; + grid-template-areas: + 'left center right'; + grid-template-columns: 30% 40% 30%; +} + +#copyright-text { + grid-area: center; +} diff --git a/Frontend/src/app/components/copyright/copyright.component.html b/Frontend/src/app/components/copyright/copyright.component.html index a9545ed..ce09033 100644 --- a/Frontend/src/app/components/copyright/copyright.component.html +++ b/Frontend/src/app/components/copyright/copyright.component.html @@ -1,3 +1,7 @@ -