]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
5ce06508b09ad4cde6b2e1023b2a634c9992f49b
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { configureTestBed } from '~/testing/unit-test-helper';
4 import { TextToDownloadService } from '~/app/shared/services/text-to-download.service';
5 import { DownloadButtonComponent } from './download-button.component';
6
7 describe('DownloadButtonComponent', () => {
8   let component: DownloadButtonComponent;
9   let fixture: ComponentFixture<DownloadButtonComponent>;
10
11   configureTestBed({
12     declarations: [DownloadButtonComponent],
13     providers: [TextToDownloadService]
14   });
15
16   beforeEach(() => {
17     fixture = TestBed.createComponent(DownloadButtonComponent);
18     component = fixture.componentInstance;
19     fixture.detectChanges();
20   });
21
22   it('should create', () => {
23     expect(component).toBeTruthy();
24   });
25
26   it('should call download function', () => {
27     component.objectItem = {
28       testA: 'testA',
29       testB: 'testB'
30     };
31     const downloadSpy = spyOn(TestBed.inject(TextToDownloadService), 'download');
32     component.fileName = `${'reportText.json'}_${new Date().toLocaleDateString()}`;
33     component.download('json');
34     expect(downloadSpy).toHaveBeenCalledWith(
35       JSON.stringify(component.objectItem, null, 2),
36       `${component.fileName}.json`
37     );
38   });
39 });