-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
340 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
client/src/app/common-components/badge/badge.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { Component } from '@angular/core'; | ||
import { BadgeComponent } from './badge.component'; | ||
|
||
async function setup({ | ||
template, | ||
}: { | ||
template?: string; | ||
} = {}) { | ||
@Component({ | ||
template, | ||
}) | ||
class TestComponent {} | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [BadgeComponent, TestComponent], | ||
}).compileComponents(); | ||
|
||
const fixture = TestBed.createComponent(TestComponent); | ||
const debugElement = fixture.debugElement.children[0]; | ||
fixture.detectChanges(); | ||
|
||
return { | ||
fixture, | ||
nativeElement: debugElement.nativeElement as HTMLElement, | ||
}; | ||
} | ||
|
||
describe('BadgeComponent', () => { | ||
it('renders content', async () => { | ||
const { nativeElement } = await setup({ | ||
template: '<app-badge>test text</app-badge>', | ||
}); | ||
expect(nativeElement.textContent).toBe('test text'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 25 additions & 13 deletions
38
client/src/app/common-components/heading/heading.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { Component } from '@angular/core'; | ||
import { HeadingComponent } from './heading.component'; | ||
|
||
async function setup() { | ||
async function setup({ | ||
template, | ||
}: { | ||
template?: string; | ||
} = {}) { | ||
@Component({ | ||
template, | ||
}) | ||
class TestComponent {} | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [HeadingComponent], | ||
declarations: [TestComponent, HeadingComponent], | ||
}).compileComponents(); | ||
|
||
const fixture = TestBed.createComponent(HeadingComponent); | ||
const fixture = TestBed.createComponent(TestComponent); | ||
const debugElement = fixture.debugElement.children[0]; | ||
fixture.detectChanges(); | ||
|
||
return { | ||
fixture, | ||
component: fixture.componentInstance, | ||
element: fixture.nativeElement as HTMLElement, | ||
nativeElement: debugElement.nativeElement as HTMLElement, | ||
}; | ||
} | ||
|
||
describe('HeadingComponent', () => { | ||
it('renders content', async () => { | ||
const { nativeElement } = await setup({ template: '<app-heading>test text</app-heading>'}); | ||
expect(nativeElement.textContent).toContain('test text'); | ||
}); | ||
|
||
it('defaults to level 1', async () => { | ||
const { element, fixture } = await setup(); | ||
fixture.detectChanges(); | ||
expect(element.className).toContain('level1'); | ||
const { nativeElement } = await setup({ template: '<app-heading></app-heading>'}); | ||
expect(nativeElement.className).toContain('level1'); | ||
}); | ||
|
||
[1, 2, 3, 4, 5, 6].forEach((level) => { | ||
it(`renderes level ${level}`, async () => { | ||
const { component, element, fixture } = await setup(); | ||
component.level = level; | ||
fixture.detectChanges(); | ||
expect(element.className).toContain(`level${level}`); | ||
const { nativeElement } = await setup({ template: `<app-heading level="${level}"></app-heading>`}); | ||
expect(nativeElement.className).toContain(`level${level}`); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
client/src/app/common-components/main/main.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { Component } from '@angular/core'; | ||
import { MainComponent } from './main.component'; | ||
|
||
async function setup({ | ||
template, | ||
}: { | ||
template?: string; | ||
} = {}) { | ||
@Component({ | ||
template, | ||
}) | ||
class TestComponent {} | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [MainComponent, TestComponent], | ||
}).compileComponents(); | ||
|
||
const fixture = TestBed.createComponent(TestComponent); | ||
const debugElement = fixture.debugElement.children[0]; | ||
fixture.detectChanges(); | ||
|
||
return { | ||
fixture, | ||
nativeElement: debugElement.nativeElement as HTMLElement, | ||
}; | ||
} | ||
|
||
describe('MainComponent', () => { | ||
it('renders content', async () => { | ||
const { nativeElement } = await setup({ | ||
template: '<app-main>test text</app-main>', | ||
}); | ||
expect(nativeElement.textContent).toBe('test text'); | ||
}); | ||
}); |
55 changes: 47 additions & 8 deletions
55
client/src/app/common-components/notification.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,55 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NotificationService } from './notification.service'; | ||
import { Notification, NotificationService } from './notification.service'; | ||
|
||
describe('NotificationService', () => { | ||
let service: NotificationService; | ||
function setup() { | ||
TestBed.configureTestingModule({}); | ||
|
||
const service = TestBed.inject(NotificationService); | ||
return { service }; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(NotificationService); | ||
describe('NotificationService', () => { | ||
it('stores notifications', () => { | ||
const notifications: Notification[] = []; | ||
const { service } = setup(); | ||
service.$notifications.subscribe((notification) => | ||
notifications.push(notification) | ||
); | ||
service.showNotification('test notification'); | ||
expect(notifications).toHaveSize(1); | ||
expect(notifications[0]).toEqual({ | ||
type: 'success', | ||
message: 'test notification', | ||
}); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
it('stores multiple notifications', () => { | ||
const notifications: Notification[] = []; | ||
const { service } = setup(); | ||
service.$notifications.subscribe((notification) => | ||
notifications.push(notification) | ||
); | ||
service.showNotification('test notification 1'); | ||
service.showNotification('test notification 2', 'error'); | ||
service.showNotification('test notification 3', 'success'); | ||
service.showNotification('test notification 4', 'error'); | ||
expect(notifications).toHaveSize(4); | ||
expect(notifications[0]).toEqual({ | ||
type: 'success', | ||
message: 'test notification 1', | ||
}); | ||
expect(notifications[1]).toEqual({ | ||
type: 'error', | ||
message: 'test notification 2', | ||
}); | ||
expect(notifications[2]).toEqual({ | ||
type: 'success', | ||
message: 'test notification 3', | ||
}); | ||
expect(notifications[3]).toEqual({ | ||
type: 'error', | ||
message: 'test notification 4', | ||
}); | ||
}); | ||
}); |
72 changes: 55 additions & 17 deletions
72
client/src/app/common-components/notification/notification.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,63 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NotificationComponent } from './notification.component'; | ||
import { Component } from '@angular/core'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { NotificationComponent } from './notification.component'; | ||
|
||
async function setup({ | ||
template, | ||
}: { | ||
template?: string; | ||
} = {}) { | ||
@Component({ | ||
template, | ||
}) | ||
class TestComponent {} | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [NotificationComponent, TestComponent], | ||
imports: [NoopAnimationsModule], | ||
}).compileComponents(); | ||
|
||
const fixture = TestBed.createComponent(TestComponent); | ||
const debugElement = fixture.debugElement.children[0]; | ||
fixture.detectChanges(); | ||
|
||
return { | ||
fixture, | ||
nativeElement: debugElement.nativeElement as HTMLElement, | ||
}; | ||
} | ||
|
||
describe('NotificationComponent', () => { | ||
let component: NotificationComponent; | ||
let fixture: ComponentFixture<NotificationComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ NotificationComponent ], | ||
imports: [NoopAnimationsModule] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(NotificationComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
it('renders content', async () => { | ||
const { nativeElement } = await setup({ | ||
template: '<app-notification>Test notification</app-notification>', | ||
}); | ||
expect(nativeElement.textContent).toBe('Test notification'); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
it('defaults to success type', async () => { | ||
const { nativeElement } = await setup({ | ||
template: '<app-notification></app-notification>', | ||
}); | ||
|
||
expect(nativeElement.classList.contains('success')).toBe(true); | ||
}); | ||
|
||
it('renders success type', async () => { | ||
const { nativeElement } = await setup({ | ||
template: '<app-notification type="success"></app-notification>', | ||
}); | ||
|
||
expect(nativeElement.classList.contains('success')).toBe(true); | ||
}); | ||
|
||
it('renders error type', async () => { | ||
const { nativeElement } = await setup({ | ||
template: '<app-notification type="error"></app-notification>', | ||
}); | ||
|
||
expect(nativeElement.classList.contains('error')).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.