Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular] Improve coverage #25165

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading