Skip to content

Commit

Permalink
test: add units for AppComponent.
Browse files Browse the repository at this point in the history
  • Loading branch information
poirierlouis committed Sep 9, 2024
1 parent b97cc9e commit 4e634e6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

<div class="space"></div>

<button mat-icon-button
<button data-testid="btn-github"
mat-icon-button
(click)="openGitHub()"
matTooltip="Repository">
<mat-icon svgIcon="logo-github"></mat-icon>
Expand Down
44 changes: 40 additions & 4 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
import {TestBed} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {AppComponent} from './app.component';
import {IconService} from "./services/icon.service";
import {MatIconTestingModule} from "@angular/material/icon/testing";
import {MatButtonHarness} from "@angular/material/button/testing";
import {NoopAnimationsModule} from "@angular/platform-browser/animations";
import {getHarness} from "../test/helpers.test";

jest.mock('./services/icon.service');

describe('AppComponent', () => {
let fixture: ComponentFixture<AppComponent>;
let app: AppComponent;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent],
imports: [
NoopAnimationsModule,
MatIconTestingModule,

AppComponent
],
providers: [
IconService
]
}).compileComponents();
fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
app = fixture.componentInstance;
});

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it('should load icons', () => {
const iconService = TestBed.inject(IconService);

expect(iconService.load).toHaveBeenCalled();
});

it('should open GitHub in a new tab', async () => {
// GIVEN
const $button: MatButtonHarness = await getHarness(fixture, MatButtonHarness.with({selector: '[data-testid=btn-github]'}));

// WHEN
await $button.click();

// THEN
expect(window.open).toHaveBeenCalledWith('https://github.com/poirierlouis/FellowImGui', '_blank');
});
});

0 comments on commit 4e634e6

Please sign in to comment.