1 import { TestBed } from '@angular/core/testing';
3 import * as BrowserDetect from 'detect-browser';
4 import { ToastrService } from 'ngx-toastr';
6 import { configureTestBed } from '~/testing/unit-test-helper';
7 import { Copy2ClipboardButtonComponent } from './copy2clipboard-button.component';
9 describe('Copy2ClipboardButtonComponent', () => {
10 let component: Copy2ClipboardButtonComponent;
15 provide: ToastrService,
24 it('should create an instance', () => {
25 component = new Copy2ClipboardButtonComponent(null);
26 expect(component).toBeTruthy();
29 describe('test onClick behaviours', () => {
30 let toastrService: ToastrService;
31 let queryFn: jasmine.Spy;
32 let writeTextFn: jasmine.Spy;
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() },
44 queryFn = spyOn(navigator.permissions, 'query');
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, _) => {
55 expect(queryFn).not.toHaveBeenCalled();
56 expect(writeTextFn).toHaveBeenCalledWith('foo');
59 it('should call permissions API', () => {
60 spyOn(BrowserDetect, 'detect').and.returnValue({ name: 'chrome' });
62 expect(queryFn).toHaveBeenCalled();