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

system_note_spec.js « notes « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 559f9bcb1a8a9ea9e64c8b83123c74169674d3af (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import MockAdapter from 'axios-mock-adapter';
import { mount } from '@vue/test-utils';
import waitForPromises from 'helpers/wait_for_promises';
import createStore from '~/notes/stores';
import IssueSystemNote from '~/vue_shared/components/notes/system_note.vue';
import axios from '~/lib/utils/axios_utils';
import { renderGFM } from '~/behaviors/markdown/render_gfm';

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

describe('system note component', () => {
  let vm;
  let props;
  let mock;

  function createComponent(propsData = {}) {
    const store = createStore();
    store.dispatch('setTargetNoteHash', `note_${props.note.id}`);

    vm = mount(IssueSystemNote, {
      store,
      propsData,
    });
  }

  beforeEach(() => {
    props = {
      note: {
        id: '1424',
        author: {
          id: 1,
          name: 'Root',
          username: 'root',
          state: 'active',
          avatar_url: 'path',
          path: '/root',
        },
        note_html: '<p dir="auto">closed</p>',
        system_note_icon_name: 'status_closed',
        created_at: '2017-08-02T10:51:58.559Z',
      },
    };

    mock = new MockAdapter(axios);
  });

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

  it('should render a list item with correct id', () => {
    createComponent(props);

    expect(vm.attributes('id')).toEqual(`note_${props.note.id}`);
  });

  it('should render target class is note is target note', () => {
    createComponent(props);

    expect(vm.classes()).toContain('target');
  });

  it('should render svg icon', () => {
    createComponent(props);

    expect(vm.find('.timeline-icon svg').exists()).toBe(true);
  });

  // Redcarpet Markdown renderer wraps text in `<p>` tags
  // we need to strip them because they break layout of commit lists in system notes:
  // https://gitlab.com/gitlab-org/gitlab-foss/uploads/b07a10670919254f0220d3ff5c1aa110/jqzI.png
  it('removes wrapping paragraph from note HTML', () => {
    createComponent(props);

    expect(vm.find('.system-note-message').html()).toContain('<span>closed</span>');
  });

  it('should renderGFM onMount', () => {
    createComponent(props);

    expect(renderGFM).toHaveBeenCalled();
  });

  it('renders outdated code lines', async () => {
    mock
      .onGet('/outdated_line_change_path')
      .reply(200, [
        { rich_text: 'console.log', type: 'new', line_code: '123', old_line: null, new_line: 1 },
      ]);

    createComponent({
      note: { ...props.note, outdated_line_change_path: '/outdated_line_change_path' },
    });

    await vm.find("[data-testid='outdated-lines-change-btn']").trigger('click');
    await waitForPromises();

    expect(vm.find("[data-testid='outdated-lines']").exists()).toBe(true);
  });
});