Welcome to mirror list, hosted at ThFree Co, Russian Federation.

system_note_spec.js « notes « components « work_items « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 69bc096124077f139ce064a03c8b4eb2d17611bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import WorkItemSystemNote from '~/work_items/components/notes/system_note.vue';
import { workItemSystemNoteWithMetadata } from 'jest/work_items/mock_data';
import axios from '~/lib/utils/axios_utils';

jest.mock('~/behaviors/markdown/render_gfm');

describe('Work Items system note component', () => {
  let wrapper;
  let mock;

  const createComponent = ({ note = workItemSystemNoteWithMetadata } = {}) => {
    mock = new MockAdapter(axios);

    wrapper = shallowMount(WorkItemSystemNote, {
      propsData: {
        note,
      },
    });
  };

  const findTimelineIcon = () => wrapper.findComponent(GlIcon);
  const findComparePreviousVersionButton = () => wrapper.find('[data-testid="compare-btn"]');

  beforeEach(() => {
    createComponent();
    mock = new MockAdapter(axios);
  });

  afterEach(() => {
    mock.restore();
  });

  it('should render a list item with correct id', () => {
    expect(wrapper.attributes('id')).toBe(
      `note_${getIdFromGraphQLId(workItemSystemNoteWithMetadata.id)}`,
    );
  });

  it('should render svg icon only for allowed icons', () => {
    expect(findTimelineIcon().exists()).toBe(false);

    const ALLOWED_ICONS = ['issue-close'];
    ALLOWED_ICONS.forEach((icon) => {
      createComponent({ note: { ...workItemSystemNoteWithMetadata, systemNoteIconName: icon } });
      expect(findTimelineIcon().exists()).toBe(true);
    });
  });

  it('should not show compare previous version for FOSS', () => {
    expect(findComparePreviousVersionButton().exists()).toBe(false);
  });
});