diff --git a/generators/client/files-angular.js b/generators/client/files-angular.js index 05ff693d7e0..d1be7efb6e7 100644 --- a/generators/client/files-angular.js +++ b/generators/client/files-angular.js @@ -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', diff --git a/generators/client/templates/angular/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.ejs b/generators/client/templates/angular/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.ejs new file mode 100644 index 00000000000..6e9e42b7c48 --- /dev/null +++ b/generators/client/templates/angular/src/main/webapp/app/admin/health/modal/health-modal.component.spec.ts.ejs @@ -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; + 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(); + }); + }); + }); +}); diff --git a/test/utils/expected-files.js b/test/utils/expected-files.js index 1beca8d5f9e..fc66e407403 100644 --- a/test/utils/expected-files.js +++ b/test/utils/expected-files.js @@ -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`,