summaryrefslogtreecommitdiff
path: root/spec/frontend/work_items/components/notes/system_note_spec.js
blob: 03f1aa356adebf1373228165fad0f5b4467333b2 (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
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', () => {
    expect(findTimelineIcon().exists()).toBe(true);
  });

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