]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/copy2clipboard-button/copy2clipboard-button.component.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / copy2clipboard-button / copy2clipboard-button.component.spec.ts
1 import { TestBed } from '@angular/core/testing';
2
3 import * as BrowserDetect from 'detect-browser';
4 import { ToastrService } from 'ngx-toastr';
5
6 import { configureTestBed } from '~/testing/unit-test-helper';
7 import { Copy2ClipboardButtonComponent } from './copy2clipboard-button.component';
8
9 describe('Copy2ClipboardButtonComponent', () => {
10 let component: Copy2ClipboardButtonComponent;
11
12 configureTestBed({
13 providers: [
14 {
15 provide: ToastrService,
16 useValue: {
17 error: () => true,
18 success: () => true
19 }
20 }
21 ]
22 });
23
24 it('should create an instance', () => {
25 component = new Copy2ClipboardButtonComponent(null);
26 expect(component).toBeTruthy();
27 });
28
29 describe('test onClick behaviours', () => {
30 let toastrService: ToastrService;
31 let queryFn: jasmine.Spy;
32 let writeTextFn: jasmine.Spy;
33
34 beforeEach(() => {
35 toastrService = TestBed.inject(ToastrService);
36 component = new Copy2ClipboardButtonComponent(toastrService);
37 spyOn<any>(component, 'getText').and.returnValue('foo');
38 Object.assign(navigator, {
39 permissions: { query: jest.fn() },
40 clipboard: {
41 writeText: jest.fn()
42 }
43 });
44 queryFn = spyOn(navigator.permissions, 'query');
45 });
46
47 it('should not call permissions API', () => {
48 spyOn(BrowserDetect, 'detect').and.returnValue({ name: 'firefox' });
49 writeTextFn = spyOn(navigator.clipboard, 'writeText').and.returnValue(
50 new Promise<void>((resolve, _) => {
51 resolve();
52 })
53 );
54 component.onClick();
55 expect(queryFn).not.toHaveBeenCalled();
56 expect(writeTextFn).toHaveBeenCalledWith('foo');
57 });
58
59 it('should call permissions API', () => {
60 spyOn(BrowserDetect, 'detect').and.returnValue({ name: 'chrome' });
61 component.onClick();
62 expect(queryFn).toHaveBeenCalled();
63 });
64 });
65 });