Skip to content

Commit

Permalink
Merge pull request #25165 from qmonmert/angularspec
Browse files Browse the repository at this point in the history
[Angular] Improve coverage
  • Loading branch information
DanielFran committed Feb 12, 2024
2 parents 290feee + 02b2cb7 commit 4bf1e2f
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const tsKeyId = this.generateTestEntityId(primaryKey.type);
const testEntity = this.generateTestEntityPrimaryKey(primaryKey, 0);
_%>
import { TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter, withComponentInputBinding } from '@angular/router';
import { RouterTestingHarness, RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
Expand All @@ -32,6 +32,8 @@ import { DataUtils } from 'app/core/util/data-util.service';
import { <%= entityAngularName %>DetailComponent } from './<%= entityFileName %>-detail.component';

describe('<%= entityAngularName %> Management Detail Component', () => {
let comp: <%= entityAngularName %>DetailComponent;
let fixture: ComponentFixture<<%= entityAngularName %>DetailComponent>;
<%_ if (anyFieldIsBlobDerived) { _%>
let dataUtils: DataUtils;
<%_ } _%>
Expand Down Expand Up @@ -60,6 +62,11 @@ describe('<%= entityAngularName %> Management Detail Component', () => {
<%_ } _%>
});

beforeEach(() => {
fixture = TestBed.createComponent(<%= entityAngularName %>DetailComponent);
comp = fixture.componentInstance;
});

describe('OnInit', () => {
it('Should load <%= entityInstance %> on init', async () => {
const harness = await RouterTestingHarness.create();
Expand All @@ -70,14 +77,20 @@ describe('<%= entityAngularName %> Management Detail Component', () => {
});
});

describe('PreviousState', () => {
it('Should navigate to previous state', () => {
jest.spyOn(window.history, 'back');
comp.previousState();
expect(window.history.back).toHaveBeenCalled();
});
});

<%_ if (anyFieldIsBlobDerived) { _%>
describe('byteSize', () => {
it('Should call byteSize from DataUtils', () => {
// GIVEN
jest.spyOn(dataUtils, 'byteSize');
const fakeBase64 = 'fake base64';
const fixture = TestBed.createComponent(<%= entityAngularName %>DetailComponent);
const comp = fixture.componentInstance;

// WHEN
comp.byteSize(fakeBase64);
Expand All @@ -98,8 +111,6 @@ describe('<%= entityAngularName %> Management Detail Component', () => {
jest.spyOn(dataUtils, 'openFile');
const fakeContentType = 'fake content type';
const fakeBase64 = 'fake base64';
const fixture = TestBed.createComponent(<%= entityAngularName %>DetailComponent);
const comp = fixture.componentInstance;

// WHEN
comp.openFile(fakeBase64, fakeContentType);
Expand Down

0 comments on commit 4bf1e2f

Please sign in to comment.