diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 18:08:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 18:08:23 +0300 |
commit | 868e4e69bba7d3ddc2bf4899ee45d6c377a8e536 (patch) | |
tree | 921098180de1fbf8e58cfaeade0d0999177b0ce6 /spec/frontend/vue_shared/components/markdown | |
parent | 41e8b05e8d06f4b13a984e4a3ad26e9a48294543 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components/markdown')
-rw-r--r-- | spec/frontend/vue_shared/components/markdown/suggestions_spec.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/markdown/suggestions_spec.js b/spec/frontend/vue_shared/components/markdown/suggestions_spec.js new file mode 100644 index 00000000000..34ccdf38b00 --- /dev/null +++ b/spec/frontend/vue_shared/components/markdown/suggestions_spec.js @@ -0,0 +1,102 @@ +import Vue from 'vue'; +import SuggestionsComponent from '~/vue_shared/components/markdown/suggestions.vue'; + +const MOCK_DATA = { + suggestions: [ + { + id: 1, + appliable: true, + applied: false, + current_user: { + can_apply: true, + }, + diff_lines: [ + { + can_receive_suggestion: false, + line_code: null, + meta_data: null, + new_line: null, + old_line: 5, + rich_text: '-test', + text: '-test', + type: 'old', + }, + { + can_receive_suggestion: true, + line_code: null, + meta_data: null, + new_line: 5, + old_line: null, + rich_text: '+new test', + text: '+new test', + type: 'new', + }, + ], + }, + ], + noteHtml: ` + <div class="suggestion"> + <div class="line">-oldtest</div> + </div> + <div class="suggestion"> + <div class="line">+newtest</div> + </div> + `, + isApplied: false, + helpPagePath: 'path_to_docs', +}; + +describe('Suggestion component', () => { + let vm; + let diffTable; + + beforeEach(done => { + const Component = Vue.extend(SuggestionsComponent); + + vm = new Component({ + propsData: MOCK_DATA, + }).$mount(); + + diffTable = vm.generateDiff(0).$mount().$el; + + jest.spyOn(vm, 'renderSuggestions').mockImplementation(() => {}); + vm.renderSuggestions(); + Vue.nextTick(done); + }); + + describe('mounted', () => { + it('renders a flash container', () => { + expect(vm.$el.querySelector('.js-suggestions-flash')).not.toBeNull(); + }); + + it('renders a container for suggestions', () => { + expect(vm.$refs.container).not.toBeNull(); + }); + + it('renders suggestions', () => { + expect(vm.renderSuggestions).toHaveBeenCalled(); + expect(vm.$el.innerHTML.includes('oldtest')).toBe(true); + expect(vm.$el.innerHTML.includes('newtest')).toBe(true); + }); + }); + + describe('generateDiff', () => { + it('generates a diff table', () => { + expect(diffTable.querySelector('.md-suggestion-diff')).not.toBeNull(); + }); + + it('generates a diff table that contains contents the suggested lines', () => { + MOCK_DATA.suggestions[0].diff_lines.forEach(line => { + const text = line.text.substring(1); + + expect(diffTable.innerHTML.includes(text)).toBe(true); + }); + }); + + it('generates a diff table with the correct line number for each suggested line', () => { + const lines = diffTable.querySelectorAll('.old_line'); + + expect(parseInt([...lines][0].innerHTML, 10)).toBe(5); + }); + }); +}); |