TrackPanel.test.tsx 2.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
import React from 'react';
18
import { render } from '@testing-library/react';
19 20 21 22 23 24
import faker from 'faker';

import { TrackPanel, TrackPanelProps } from './TrackPanel';

import { createEnsObject } from 'tests/fixtures/ens-object';

25 26 27 28
jest.mock('src/shared/components/loader', () => ({
  SidebarLoader: () => <div className="sidebarLoader" />
}));

29
jest.mock('./track-panel-bar/TrackPanelBar', () => () => (
30
  <div className="trackPanel" />
31 32
));
jest.mock('./track-panel-list/TrackPanelList', () => () => (
33
  <div className="trackPanelList" />
34 35
));
jest.mock('./track-panel-modal/TrackPanelModal', () => () => (
36
  <div className="trackPanelModal" />
37
));
38
jest.mock('../drawer/Drawer', () => () => <div className="drawer" />);
39 40 41 42 43 44 45 46 47 48

describe('<TrackPanel />', () => {
  afterEach(() => {
    jest.resetAllMocks();
  });

  const defaultProps: TrackPanelProps = {
    activeGenomeId: null,
    browserActivated: false,
    activeEnsObject: null,
49 50
    isTrackPanelModalOpened: false,
    restoreBrowserTrackStates: jest.fn()
51 52
  };

53 54
  const renderTrackPanel = (props?: Partial<TrackPanelProps>) =>
    render(<TrackPanel {...defaultProps} {...props} />);
55 56

  describe('rendering', () => {
57
    it('does not render anything when not all rendering requirements are satisfied', () => {
58 59
      // defaultProps are insufficient for rendering anything useful
      // TODO: in the future, it might be a good idea to at least render a spinner here
60
      const { container } = renderTrackPanel();
61
      expect(container.querySelector('.sidebarLoader')).toBeTruthy();
62 63
    });

64 65
    it('renders TrackPanelList when necessary requirements are satisfied', () => {
      const { container } = renderTrackPanel({
66
        browserActivated: true,
67 68
        activeEnsObject: createEnsObject(),
        activeGenomeId: faker.lorem.words()
69
      });
70
      expect(container.querySelector('.trackPanelList')).toBeTruthy();
71 72
    });

73 74
    it('renders track panel modal when necessary requirements are satisfied', () => {
      const { container } = renderTrackPanel({
75 76 77 78 79
        activeGenomeId: faker.lorem.words(),
        browserActivated: true,
        activeEnsObject: createEnsObject(),
        isTrackPanelModalOpened: true
      });
80
      expect(container.querySelector('.trackPanelModal')).toBeTruthy();
81 82 83
    });
  });
});