Skip to content

Commit

Permalink
Merge pull request #14849 from qmonmert/angular/test-healthmodal
Browse files Browse the repository at this point in the history
[Angular] Add health-modal test
  • Loading branch information
mshima authored May 2, 2021
2 parents 8f76af8 + acf5708 commit 856d391
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions generators/client/files-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ const files = {
templates: [
'admin/configuration/configuration.component.spec.ts',
'admin/configuration/configuration.service.spec.ts',
'admin/health/modal/health-modal.component.spec.ts',
'admin/health/health.component.spec.ts',
'admin/logs/logs.component.spec.ts',
'admin/logs/logs.service.spec.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import { HealthModalComponent } from './health-modal.component';

describe('Component Tests', () => {
describe('HealthModalComponent', () => {
let comp: HealthModalComponent;
let fixture: ComponentFixture<HealthModalComponent>;
let mockActiveModal: NgbActiveModal;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [HealthModalComponent],
providers: [NgbActiveModal],
})
.overrideTemplate(HealthModalComponent, '')
.compileComponents();
})
);

beforeEach(() => {
fixture = TestBed.createComponent(HealthModalComponent);
comp = fixture.componentInstance;
mockActiveModal = TestBed.inject(NgbActiveModal);
});

describe('readableValue', () => {
it('should return stringify value', () => {
// GIVEN
comp.health = undefined;

// WHEN
const result = comp.readableValue({ 'name': 'jhipster' });

// THEN
expect(result).toEqual('{"name":"jhipster"}');
});

it('should return string value', () => {
// GIVEN
comp.health = undefined;

// WHEN
const result = comp.readableValue('jhipster');

// THEN
expect(result).toEqual('jhipster');
});

it('should return storage space in an human readable unit (GB)', () => {
// GIVEN
comp.health = {
key: 'diskSpace',
value: {
status: 'UP'
}
};

// WHEN
const result = comp.readableValue(1073741825);

// THEN
expect(result).toEqual('1.00 GB');
});

it('should return storage space in an human readable unit (MB)', () => {
// GIVEN
comp.health = {
key: 'diskSpace',
value: {
status: 'UP'
}
};

// WHEN
const result = comp.readableValue(1073741824);

// THEN
expect(result).toEqual('1024.00 MB');
});

it('should return string value', () => {
// GIVEN
comp.health = {
key: 'mail',
value: {
status: 'UP'
}
};

// WHEN
const result = comp.readableValue(1234);

// THEN
expect(result).toEqual('1234');
});
});

describe('dismiss', () => {
it('should call dismiss when dismiss modal is called', () => {
// GIVEN
const spy = spyOn(mockActiveModal, 'dismiss').and.callThrough();

// WHEN
comp.dismiss();

// THEN
expect(spy).toHaveBeenCalled();
});
});
});
});
1 change: 1 addition & 0 deletions test/utils/expected-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ const expectedFiles = {
`${CLIENT_MAIN_SRC_DIR}app/admin/metrics/metrics.model.ts`,
`${CLIENT_MAIN_SRC_DIR}app/admin/configuration/configuration.component.spec.ts`,
`${CLIENT_MAIN_SRC_DIR}app/admin/configuration/configuration.service.spec.ts`,
`${CLIENT_MAIN_SRC_DIR}app/admin/health/modal/health-modal.component.spec.ts`,
`${CLIENT_MAIN_SRC_DIR}app/admin/health/health.component.spec.ts`,
`${CLIENT_MAIN_SRC_DIR}app/admin/logs/logs.component.spec.ts`,
`${CLIENT_MAIN_SRC_DIR}app/admin/logs/logs.service.spec.ts`,
Expand Down

0 comments on commit 856d391

Please sign in to comment.