From af2da01729cb1382d1049dacaafb19d1f5d98f22 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Sat, 3 Sep 2022 16:30:29 +0200 Subject: [PATCH] Unit Testing stuff --- karma.conf.js | 4 +- package-lock.json | 55 ++++++++++++++++--- package.json | 1 + src/app/app.component.spec.ts | 11 +--- .../header/header.component.spec.ts | 4 ++ .../components/profile/profile.component.scss | 2 +- .../components/profile/profile.component.ts | 2 - src/app/pages/home/home.component.spec.ts | 14 ++++- 8 files changed, 69 insertions(+), 24 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 352bfbf..907568b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -7,7 +7,7 @@ module.exports = function (config) { frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), - require('karma-chrome-launcher'), + require('karma-firefox-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage'), require('@angular-devkit/build-angular/plugins/karma') @@ -37,7 +37,7 @@ module.exports = function (config) { colors: true, logLevel: config.LOG_INFO, autoWatch: true, - browsers: ['Chrome'], + browsers: ['Firefox'], singleRun: false, restartOnFileChange: true }); diff --git a/package-lock.json b/package-lock.json index dbcdb13..bd34cb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@angular/platform-browser": "^14.0.0", "@angular/platform-browser-dynamic": "^14.0.0", "@angular/router": "^14.0.0", + "karma-firefox-launcher": "^2.1.2", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" @@ -6641,7 +6642,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", - "dev": true, "bin": { "is-docker": "cli.js" }, @@ -6764,7 +6764,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", - "dev": true, "dependencies": { "is-docker": "^2.0.0" }, @@ -6793,8 +6792,7 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "node_modules/isobject": { "version": "3.0.1", @@ -7119,6 +7117,29 @@ "node": "*" } }, + "node_modules/karma-firefox-launcher": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-2.1.2.tgz", + "integrity": "sha512-VV9xDQU1QIboTrjtGVD4NCfzIH7n01ZXqy/qpBhnOeGVOkG5JYPEm8kuSd7psHE6WouZaQ9Ool92g8LFweSNMA==", + "dependencies": { + "is-wsl": "^2.2.0", + "which": "^2.0.1" + } + }, + "node_modules/karma-firefox-launcher/node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/karma-jasmine": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.1.0.tgz", @@ -16645,8 +16666,7 @@ "is-docker": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", - "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", - "dev": true + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==" }, "is-extglob": { "version": "2.1.1", @@ -16724,7 +16744,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", - "dev": true, "requires": { "is-docker": "^2.0.0" } @@ -16744,8 +16763,7 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "isobject": { "version": "3.0.1", @@ -17088,6 +17106,25 @@ } } }, + "karma-firefox-launcher": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-2.1.2.tgz", + "integrity": "sha512-VV9xDQU1QIboTrjtGVD4NCfzIH7n01ZXqy/qpBhnOeGVOkG5JYPEm8kuSd7psHE6WouZaQ9Ool92g8LFweSNMA==", + "requires": { + "is-wsl": "^2.2.0", + "which": "^2.0.1" + }, + "dependencies": { + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "requires": { + "isexe": "^2.0.0" + } + } + } + }, "karma-jasmine": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.1.0.tgz", diff --git a/package.json b/package.json index 8c5b9e2..5e9e424 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@angular/platform-browser": "^14.0.0", "@angular/platform-browser-dynamic": "^14.0.0", "@angular/router": "^14.0.0", + "karma-firefox-launcher": "^2.1.2", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 3acaa67..c8d3b25 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -20,16 +20,9 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it(`should have as title 'Doppelkopf-Stats-Frontend'`, () => { + it(`should have as title 'Doppelkopf-Stats'`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.componentInstance; - expect(app.title).toEqual('Doppelkopf-Stats-Frontend'); - }); - - it('should render title', () => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('.content span')?.textContent).toContain('Doppelkopf-Stats-Frontend app is running!'); + expect(app.title).toEqual('Doppelkopf-Stats'); }); }); diff --git a/src/app/components/header/header.component.spec.ts b/src/app/components/header/header.component.spec.ts index e3fe6c6..eb8e600 100644 --- a/src/app/components/header/header.component.spec.ts +++ b/src/app/components/header/header.component.spec.ts @@ -20,4 +20,8 @@ describe('HeaderComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should return the correct user name', () => { + expect(component.getUserName()).toEqual('Logged out'); + }); }); diff --git a/src/app/components/profile/profile.component.scss b/src/app/components/profile/profile.component.scss index 1a71751..b0875c8 100644 --- a/src/app/components/profile/profile.component.scss +++ b/src/app/components/profile/profile.component.scss @@ -11,7 +11,7 @@ @media (min-width: 768px) { #profile-popover { - width: 15em; + max-width: 15em; right: 1em; top: $header_height + 1em; border-radius: 1em; diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index e28272c..86f3cc4 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -12,8 +12,6 @@ export class ProfileComponent implements OnInit { @Input() user?: User; @Output() showProfilePopoverChange = new EventEmitter(); - isLoggedIn = true; - constructor(private eRef: ElementRef) { } diff --git a/src/app/pages/home/home.component.spec.ts b/src/app/pages/home/home.component.spec.ts index 0914023..e82edf9 100644 --- a/src/app/pages/home/home.component.spec.ts +++ b/src/app/pages/home/home.component.spec.ts @@ -1,6 +1,15 @@ import {ComponentFixture, TestBed} from '@angular/core/testing'; import {HomeComponent} from './home.component'; +import {ActivatedRoute} from '@angular/router'; + +const activatedRouteStub = { + queryParams: { + subscribe() { + return {}; + } + } +}; describe('HomeComponent', () => { let component: HomeComponent; @@ -8,7 +17,10 @@ describe('HomeComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [HomeComponent] + declarations: [HomeComponent], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub } + ], }) .compileComponents();