diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.spec.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.spec.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.spec.ts new file mode 100644 index 000000000..7dbfc2b1c --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.spec.ts @@ -0,0 +1,39 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TextToDownloadService } from '~/app/shared/services/text-to-download.service'; +import { configureTestBed } from '~/testing/unit-test-helper'; +import { DownloadButtonComponent } from './download-button.component'; + +describe('DownloadButtonComponent', () => { + let component: DownloadButtonComponent; + let fixture: ComponentFixture<DownloadButtonComponent>; + + configureTestBed({ + declarations: [DownloadButtonComponent], + providers: [TextToDownloadService] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(DownloadButtonComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should call download function', () => { + component.objectItem = { + testA: 'testA', + testB: 'testB' + }; + const downloadSpy = spyOn(TestBed.inject(TextToDownloadService), 'download'); + component.fileName = `${'reportText.json'}_${new Date().toLocaleDateString()}`; + component.download('json'); + expect(downloadSpy).toHaveBeenCalledWith( + JSON.stringify(component.objectItem, null, 2), + `${component.fileName}.json` + ); + }); +}); |