DefaultTranscriptListItem.test.tsx 2.98 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 18 19
import React from 'react';
import { mount } from 'enzyme';

20 21 22 23
import {
  DefaultTranscriptListItem,
  DefaultTranscriptListItemProps
} from './DefaultTranscriptListItem';
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
import TranscriptsListItemInfo from '../transcripts-list-item-info/TranscriptsListItemInfo';
import UnsplicedTranscript from 'src/content/app/entity-viewer/gene-view/components/unspliced-transcript/UnsplicedTranscript';

import { createTranscript } from 'tests/fixtures/entity-viewer/transcript';
import {
  createGene,
  createRulerTicks
} from 'tests/fixtures/entity-viewer/gene';

jest.mock('../transcripts-list-item-info/TranscriptsListItemInfo', () => () => (
  <div>TranscriptsListItemInfo</div>
));

jest.mock(
  'src/content/app/entity-viewer/gene-view/components/unspliced-transcript/UnsplicedTranscript',
  () => () => <div>UnsplicedTranscript</div>
);

42 43
const toggleTranscriptInfo = jest.fn();

44 45 46
describe('<DefaultTranscriptListItem />', () => {
  let wrapper: any;

47 48
  afterEach(() => {
    jest.resetAllMocks();
49 50
  });

51 52 53 54 55 56 57 58 59 60 61 62
  const defaultProps = {
    gene: createGene(),
    transcript: createTranscript(),
    rulerTicks: createRulerTicks(),
    expandTranscript: false,
    expandDownload: false,
    toggleTranscriptInfo: toggleTranscriptInfo
  };

  const renderComponent = (props?: Partial<DefaultTranscriptListItemProps>) =>
    mount(<DefaultTranscriptListItem {...defaultProps} {...props} />);

63
  it('displays unspliced transcript', () => {
64
    wrapper = renderComponent();
65 66 67
    expect(wrapper.exists(UnsplicedTranscript)).toBe(true);
  });

68 69
  it('toggles transcript item info onClick', () => {
    wrapper = renderComponent();
Andrey Azov's avatar
Andrey Azov committed
70
    wrapper.find('.clickableTranscriptArea').simulate('click');
71
    expect(toggleTranscriptInfo).toHaveBeenCalledTimes(1);
72
    wrapper.find('.right').simulate('click');
73 74 75 76 77 78
    expect(toggleTranscriptInfo).toHaveBeenCalledTimes(2);
  });

  it('hides transcript info by default', () => {
    wrapper = renderComponent();

79 80
    expect(wrapper.exists(TranscriptsListItemInfo)).toBe(false);
  });
81 82 83 84 85 86

  it('displays transcript info if expandTranscript is true', () => {
    wrapper = renderComponent({ expandTranscript: true });

    expect(wrapper.exists(TranscriptsListItemInfo)).toBe(true);
  });
87 88 89 90 91

  it('displays selected transcript', () => {
    wrapper = renderComponent({ isDefault: true });
    expect(wrapper.find('.defaultTranscriptLabel').text()).toBe('Selected');
  });
92
});