Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / views-components / baner / banner.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { configure, shallow, mount } from "enzyme";
7 import { BannerComponent } from './banner';
8 import { Button } from "@material-ui/core";
9 import Adapter from "enzyme-adapter-react-16";
10 import servicesProvider from '../../common/service-provider';
11
12 configure({ adapter: new Adapter() });
13
14 jest.mock('../../common/service-provider', () => ({
15     getServices: jest.fn(),
16 }));
17
18 describe('<BannerComponent />', () => {
19
20     let props;
21
22     beforeEach(() => {
23         props = {
24             isOpen: false,
25             bannerUUID: undefined,
26             keepWebInlineServiceUrl: '',
27             openBanner: jest.fn(),
28             closeBanner: jest.fn(),
29             classes: {} as any,
30         }
31     });
32
33     it('renders without crashing', () => {
34         // when
35         const banner = shallow(<BannerComponent {...props} />);
36         
37         // then
38         expect(banner.find(Button)).toHaveLength(1);
39     });
40
41     it('calls collectionService', () => {
42         // given
43         props.isOpen = true;
44         props.bannerUUID = '123';
45         const mocks = {
46             collectionService: {
47                 files: jest.fn(() => ({ then: (callback) => callback([{ name: 'banner.html' }]) })),
48                 getFileContents: jest.fn(() => ({ then: (callback) => callback('<h1>Test</h1>') }))
49             }
50         };
51         (servicesProvider.getServices as any).mockImplementation(() => mocks);
52
53         // when
54         const banner = mount(<BannerComponent {...props} />);
55
56         // then
57         expect(servicesProvider.getServices).toHaveBeenCalled();
58         expect(mocks.collectionService.files).toHaveBeenCalled();
59         expect(mocks.collectionService.getFileContents).toHaveBeenCalled();
60         expect(banner.html()).toContain('<h1>Test</h1>');
61     });
62 });
63