From 172a2af6ceafdfc2b135e0327755683d69d7c5e5 Mon Sep 17 00:00:00 2001 From: Chris Pyles Date: Sun, 28 Apr 2024 15:18:31 -0700 Subject: [PATCH] get initial tests passing --- package-lock.json | 16 ++++++++++++++++ package.json | 3 ++- src/app/app.component.spec.ts | 16 +++------------- .../contrast-chart.component.spec.ts | 6 ++++-- src/app/header/header.component.spec.ts | 10 +++++++--- .../palette-item/palette-item.component.spec.ts | 8 ++++++-- src/app/palette/palette.component.spec.ts | 8 +++++--- 7 files changed, 43 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index a8165d8..0a9b995 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "ng-mocks": "^14.12.2", "typescript": "~5.4.2" } }, @@ -8566,6 +8567,21 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/ng-mocks": { + "version": "14.12.2", + "resolved": "https://registry.npmjs.org/ng-mocks/-/ng-mocks-14.12.2.tgz", + "integrity": "sha512-7HFb1G4I9885ipqdm0o+kPhFvy5EfEooIfl1DqxA84rvig6FhugZ8UDgV6YPYlwnGQyfwmAOexoPTuSVs36bhw==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/help-me-mom" + }, + "peerDependencies": { + "@angular/common": "5.0.0-alpha - 5 || 6.0.0-alpha - 6 || 7.0.0-alpha - 7 || 8.0.0-alpha - 8 || 9.0.0-alpha - 9 || 10.0.0-alpha - 10 || 11.0.0-alpha - 11 || 12.0.0-alpha - 12 || 13.0.0-alpha - 13 || 14.0.0-alpha - 14 || 15.0.0-alpha - 15 || 16.0.0-alpha - 16 || 17.0.0-alpha - 17", + "@angular/core": "5.0.0-alpha - 5 || 6.0.0-alpha - 6 || 7.0.0-alpha - 7 || 8.0.0-alpha - 8 || 9.0.0-alpha - 9 || 10.0.0-alpha - 10 || 11.0.0-alpha - 11 || 12.0.0-alpha - 12 || 13.0.0-alpha - 13 || 14.0.0-alpha - 14 || 15.0.0-alpha - 15 || 16.0.0-alpha - 16 || 17.0.0-alpha - 17", + "@angular/forms": "5.0.0-alpha - 5 || 6.0.0-alpha - 6 || 7.0.0-alpha - 7 || 8.0.0-alpha - 8 || 9.0.0-alpha - 9 || 10.0.0-alpha - 10 || 11.0.0-alpha - 11 || 12.0.0-alpha - 12 || 13.0.0-alpha - 13 || 14.0.0-alpha - 14 || 15.0.0-alpha - 15 || 16.0.0-alpha - 16 || 17.0.0-alpha - 17", + "@angular/platform-browser": "5.0.0-alpha - 5 || 6.0.0-alpha - 6 || 7.0.0-alpha - 7 || 8.0.0-alpha - 8 || 9.0.0-alpha - 9 || 10.0.0-alpha - 10 || 11.0.0-alpha - 11 || 12.0.0-alpha - 12 || 13.0.0-alpha - 13 || 14.0.0-alpha - 14 || 15.0.0-alpha - 15 || 16.0.0-alpha - 16 || 17.0.0-alpha - 17" + } + }, "node_modules/nice-napi": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", diff --git a/package.json b/package.json index 361ecf5..2606b90 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", - "test": "ng test" + "test": "ng test --browsers=ChromeHeadless --code-coverage --source-map=false" }, "private": true, "dependencies": { @@ -36,6 +36,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "ng-mocks": "^14.12.2", "typescript": "~5.4.2" } } diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 785bec8..0193e39 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,10 +1,13 @@ import { TestBed } from '@angular/core/testing'; +import { MessageService } from 'primeng/api'; + import { AppComponent } from './app.component'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [AppComponent], + providers: [MessageService], }).compileComponents(); }); @@ -13,17 +16,4 @@ describe('AppComponent', () => { const app = fixture.componentInstance; expect(app).toBeTruthy(); }); - - it(`should have the 'contrastinator' title`, () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('contrastinator'); - }); - - it('should render title', () => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('Hello, contrastinator'); - }); }); diff --git a/src/app/contrast-chart/contrast-chart.component.spec.ts b/src/app/contrast-chart/contrast-chart.component.spec.ts index 2c09700..f087772 100644 --- a/src/app/contrast-chart/contrast-chart.component.spec.ts +++ b/src/app/contrast-chart/contrast-chart.component.spec.ts @@ -10,10 +10,12 @@ describe('ContrastChartComponent', () => { await TestBed.configureTestingModule({ imports: [ContrastChartComponent] }) - .compileComponents(); - + .compileComponents(); + fixture = TestBed.createComponent(ContrastChartComponent); component = fixture.componentInstance; + const componentRef = fixture.componentRef; + componentRef.setInput('colors', []); fixture.detectChanges(); }); diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts index 4ff21e8..55c0788 100644 --- a/src/app/header/header.component.spec.ts +++ b/src/app/header/header.component.spec.ts @@ -1,5 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MessageService } from 'primeng/api'; import { HeaderComponent } from './header.component'; describe('HeaderComponent', () => { @@ -8,12 +9,15 @@ describe('HeaderComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [HeaderComponent] + imports: [HeaderComponent], + providers: [MessageService], }) - .compileComponents(); - + .compileComponents(); + fixture = TestBed.createComponent(HeaderComponent); component = fixture.componentInstance; + const componentRef = fixture.componentRef; + componentRef.setInput('colors', []); fixture.detectChanges(); }); diff --git a/src/app/palette-item/palette-item.component.spec.ts b/src/app/palette-item/palette-item.component.spec.ts index a313957..34b8d09 100644 --- a/src/app/palette-item/palette-item.component.spec.ts +++ b/src/app/palette-item/palette-item.component.spec.ts @@ -1,5 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import Color from 'color'; import { PaletteItemComponent } from './palette-item.component'; describe('PaletteItemComponent', () => { @@ -10,10 +11,13 @@ describe('PaletteItemComponent', () => { await TestBed.configureTestingModule({ imports: [PaletteItemComponent] }) - .compileComponents(); - + .compileComponents(); + fixture = TestBed.createComponent(PaletteItemComponent); component = fixture.componentInstance; + const componentRef = fixture.componentRef; + componentRef.setInput('color', new Color('#000')); + componentRef.setInput('locked', false); fixture.detectChanges(); }); diff --git a/src/app/palette/palette.component.spec.ts b/src/app/palette/palette.component.spec.ts index 7458026..85f24f4 100644 --- a/src/app/palette/palette.component.spec.ts +++ b/src/app/palette/palette.component.spec.ts @@ -1,5 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MessageService } from 'primeng/api'; import { PaletteComponent } from './palette.component'; describe('PaletteComponent', () => { @@ -8,10 +9,11 @@ describe('PaletteComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [PaletteComponent] + imports: [PaletteComponent], + providers: [MessageService], }) - .compileComponents(); - + .compileComponents(); + fixture = TestBed.createComponent(PaletteComponent); component = fixture.componentInstance; fixture.detectChanges();