1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
12 configure({ adapter: new Adapter() });
14 jest.mock('../../common/service-provider', () => ({
15 getServices: jest.fn(),
18 describe('<BannerComponent />', () => {
25 bannerUUID: undefined,
26 keepWebInlineServiceUrl: '',
27 openBanner: jest.fn(),
28 closeBanner: jest.fn(),
33 it('renders without crashing', () => {
35 const banner = shallow(<BannerComponent {...props} />);
38 expect(banner.find(Button)).toHaveLength(1);
41 it('calls collectionService', () => {
44 props.bannerUUID = '123';
47 files: jest.fn(() => ({ then: (callback) => callback([{ name: 'banner.html' }]) })),
48 getFileContents: jest.fn(() => ({ then: (callback) => callback('<h1>Test</h1>') }))
51 (servicesProvider.getServices as any).mockImplementation(() => mocks);
54 const banner = mount(<BannerComponent {...props} />);
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>');