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

note_body_spec.js « components « notes « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4922de987fa8a312711bbf3e0f23803febcef4fe (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
102
103
104
105
106
107
108
109
110
111
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';

import { suggestionCommitMessage } from '~/diffs/store/getters';
import noteBody from '~/notes/components/note_body.vue';
import createStore from '~/notes/stores';
import notes from '~/notes/stores/modules/index';

import Suggestions from '~/vue_shared/components/markdown/suggestions.vue';

import { noteableDataMock, notesDataMock, note } from '../mock_data';

describe('issue_note_body component', () => {
  let store;
  let vm;

  beforeEach(() => {
    const Component = Vue.extend(noteBody);

    store = createStore();
    store.dispatch('setNoteableData', noteableDataMock);
    store.dispatch('setNotesData', notesDataMock);

    vm = new Component({
      store,
      propsData: {
        note,
        canEdit: true,
        canAwardEmoji: true,
      },
    }).$mount();
  });

  afterEach(() => {
    vm.$destroy();
  });

  it('should render the note', () => {
    expect(vm.$el.querySelector('.note-text').innerHTML).toEqual(note.note_html);
  });

  it('should render awards list', () => {
    expect(vm.$el.querySelector('.js-awards-block button [data-name="baseball"]')).not.toBeNull();
    expect(vm.$el.querySelector('.js-awards-block button [data-name="bath_tone3"]')).not.toBeNull();
  });

  describe('isEditing', () => {
    beforeEach((done) => {
      vm.isEditing = true;
      Vue.nextTick(done);
    });

    it('renders edit form', () => {
      expect(vm.$el.querySelector('textarea.js-task-list-field')).not.toBeNull();
    });

    it('adds autosave', () => {
      const autosaveKey = `autosave/Note/${note.noteable_type}/${note.id}`;

      expect(vm.autosave).toExist();
      expect(vm.autosave.key).toEqual(autosaveKey);
    });
  });

  describe('commitMessage', () => {
    let wrapper;

    Vue.use(Vuex);

    beforeEach(() => {
      const notesStore = notes();

      notesStore.state.notes = {};

      store = new Vuex.Store({
        modules: {
          notes: notesStore,
          diffs: {
            namespaced: true,
            state: {
              defaultSuggestionCommitMessage:
                '%{branch_name}%{project_path}%{project_name}%{username}%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}',
              branchName: 'branch',
              projectPath: '/path',
              projectName: 'name',
              username: 'user',
              userFullName: 'user userton',
            },
            getters: { suggestionCommitMessage },
          },
        },
      });

      wrapper = shallowMount(noteBody, {
        store,
        propsData: {
          note: { ...note, suggestions: [12345] },
          canEdit: true,
          file: { file_path: 'abc' },
        },
      });
    });

    it('passes the correct default placeholder commit message for a suggestion to the suggestions component', () => {
      const commitMessage = wrapper.find(Suggestions).attributes('defaultcommitmessage');

      expect(commitMessage).toBe('branch/pathnameuseruser usertonabc11');
    });
  });
});