summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/components/download-button/download-button.component.spec.ts
blob: 7dbfc2b1cabb148fcf50896941d29f932fec56bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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`
    );
  });
});