diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-04 18:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-04 18:09:33 +0300 |
commit | bf6d126a58a66a11b2e4b9de89986174a1885105 (patch) | |
tree | bf2912b22073ed86969a56935d81cae0b73e710b /spec/frontend/batch_comments/components | |
parent | 7928b47c8e06c1ac3f63d321a73dd527aea4e4c3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/batch_comments/components')
3 files changed, 38 insertions, 58 deletions
diff --git a/spec/frontend/batch_comments/components/drafts_count_spec.js b/spec/frontend/batch_comments/components/drafts_count_spec.js index 390ef21929c..c3a7946c85c 100644 --- a/spec/frontend/batch_comments/components/drafts_count_spec.js +++ b/spec/frontend/batch_comments/components/drafts_count_spec.js @@ -1,40 +1,36 @@ -import Vue, { nextTick } from 'vue'; -import { mountComponentWithStore } from 'helpers/vue_mount_component_helper'; +import { nextTick } from 'vue'; +import { mount } from '@vue/test-utils'; import DraftsCount from '~/batch_comments/components/drafts_count.vue'; import { createStore } from '~/batch_comments/stores'; describe('Batch comments drafts count component', () => { - let vm; - let Component; - - beforeAll(() => { - Component = Vue.extend(DraftsCount); - }); + let store; + let wrapper; beforeEach(() => { - const store = createStore(); + store = createStore(); store.state.batchComments.drafts.push('comment'); - vm = mountComponentWithStore(Component, { store }); + wrapper = mount(DraftsCount, { store }); }); afterEach(() => { - vm.$destroy(); + wrapper.destroy(); }); it('renders count', () => { - expect(vm.$el.textContent).toContain('1'); + expect(wrapper.text()).toContain('1'); }); it('renders screen reader text', async () => { - const el = vm.$el.querySelector('.sr-only'); + const el = wrapper.find('.sr-only'); - expect(el.textContent).toContain('draft'); - - vm.$store.state.batchComments.drafts.push('comment 2'); + expect(el.text()).toContain('draft'); + store.state.batchComments.drafts.push('comment 2'); await nextTick(); - expect(el.textContent).toContain('drafts'); + + expect(el.text()).toContain('drafts'); }); }); diff --git a/spec/frontend/batch_comments/components/preview_item_spec.js b/spec/frontend/batch_comments/components/preview_item_spec.js index 91e6b84a216..6a104f0c787 100644 --- a/spec/frontend/batch_comments/components/preview_item_spec.js +++ b/spec/frontend/batch_comments/components/preview_item_spec.js @@ -1,5 +1,4 @@ -import Vue from 'vue'; -import { mountComponentWithStore } from 'helpers/vue_mount_component_helper'; +import { mount } from '@vue/test-utils'; import PreviewItem from '~/batch_comments/components/preview_item.vue'; import { createStore } from '~/batch_comments/stores'; import diffsModule from '~/diffs/store/modules'; @@ -8,8 +7,7 @@ import '~/behaviors/markdown/render_gfm'; import { createDraft } from '../mock_data'; describe('Batch comments draft preview item component', () => { - let vm; - let Component; + let wrapper; let draft; function createComponent(isLast = false, extra = {}, extendStore = () => {}) { @@ -24,21 +22,17 @@ describe('Batch comments draft preview item component', () => { ...extra, }; - vm = mountComponentWithStore(Component, { store, props: { draft, isLast } }); + wrapper = mount(PreviewItem, { store, propsData: { draft, isLast } }); } - beforeAll(() => { - Component = Vue.extend(PreviewItem); - }); - afterEach(() => { - vm.$destroy(); + wrapper.destroy(); }); it('renders text content', () => { createComponent(false, { note_html: '<img src="" /><p>Hello world</p>' }); - expect(vm.$el.querySelector('.review-preview-item-content').innerHTML).toEqual( + expect(wrapper.find('.review-preview-item-content').element.innerHTML).toBe( '<p>Hello world</p>', ); }); @@ -47,9 +41,7 @@ describe('Batch comments draft preview item component', () => { it('renders file path', () => { createComponent(false, { file_path: 'index.js', file_hash: 'abc', position: {} }); - expect(vm.$el.querySelector('.review-preview-item-header-text').textContent).toContain( - 'index.js', - ); + expect(wrapper.find('.review-preview-item-header-text').text()).toContain('index.js'); }); it('renders new line position', () => { @@ -66,7 +58,7 @@ describe('Batch comments draft preview item component', () => { }, }); - expect(vm.$el.querySelector('.bold').textContent).toContain(':+1'); + expect(wrapper.find('.bold').text()).toContain(':+1'); }); it('renders old line position', () => { @@ -82,7 +74,7 @@ describe('Batch comments draft preview item component', () => { }, }); - expect(vm.$el.querySelector('.bold').textContent).toContain(':2'); + expect(wrapper.find('.bold').text()).toContain(':2'); }); it('renders image position', () => { @@ -92,7 +84,7 @@ describe('Batch comments draft preview item component', () => { position: { position_type: 'image', x: 10, y: 20 }, }); - expect(vm.$el.querySelector('.bold').textContent).toContain('10x 20y'); + expect(wrapper.find('.bold').text()).toContain('10x 20y'); }); }); @@ -113,15 +105,13 @@ describe('Batch comments draft preview item component', () => { }); it('renders title', () => { - expect(vm.$el.querySelector('.review-preview-item-header-text').textContent).toContain( + expect(wrapper.find('.review-preview-item-header-text').text()).toContain( "Author 'Nick' Name's thread", ); }); it('renders thread resolved text', () => { - expect(vm.$el.querySelector('.draft-note-resolution').textContent).toContain( - 'Thread will be resolved', - ); + expect(wrapper.find('.draft-note-resolution').text()).toContain('Thread will be resolved'); }); }); @@ -131,9 +121,7 @@ describe('Batch comments draft preview item component', () => { store.state.notes.discussions.push({}); }); - expect(vm.$el.querySelector('.review-preview-item-header-text').textContent).toContain( - 'Your new comment', - ); + expect(wrapper.find('.review-preview-item-header-text').text()).toContain('Your new comment'); }); }); }); diff --git a/spec/frontend/batch_comments/components/publish_button_spec.js b/spec/frontend/batch_comments/components/publish_button_spec.js index 9a782ec09b6..5e3fa3e9446 100644 --- a/spec/frontend/batch_comments/components/publish_button_spec.js +++ b/spec/frontend/batch_comments/components/publish_button_spec.js @@ -1,38 +1,34 @@ -import Vue, { nextTick } from 'vue'; -import { mountComponentWithStore } from 'helpers/vue_mount_component_helper'; +import { nextTick } from 'vue'; +import { mount } from '@vue/test-utils'; import PublishButton from '~/batch_comments/components/publish_button.vue'; import { createStore } from '~/batch_comments/stores'; describe('Batch comments publish button component', () => { - let vm; - let Component; - - beforeAll(() => { - Component = Vue.extend(PublishButton); - }); + let wrapper; + let store; beforeEach(() => { - const store = createStore(); + store = createStore(); - vm = mountComponentWithStore(Component, { store, props: { shouldPublish: true } }); + wrapper = mount(PublishButton, { store, propsData: { shouldPublish: true } }); - jest.spyOn(vm.$store, 'dispatch').mockImplementation(); + jest.spyOn(store, 'dispatch').mockImplementation(); }); afterEach(() => { - vm.$destroy(); + wrapper.destroy(); }); - it('dispatches publishReview on click', () => { - vm.$el.click(); + it('dispatches publishReview on click', async () => { + await wrapper.trigger('click'); - expect(vm.$store.dispatch).toHaveBeenCalledWith('batchComments/publishReview', undefined); + expect(store.dispatch).toHaveBeenCalledWith('batchComments/publishReview', undefined); }); it('sets loading when isPublishing is true', async () => { - vm.$store.state.batchComments.isPublishing = true; + store.state.batchComments.isPublishing = true; await nextTick(); - expect(vm.$el.getAttribute('disabled')).toBe('disabled'); + expect(wrapper.attributes('disabled')).toBe('disabled'); }); }); |