diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-02 21:12:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-02 21:12:20 +0300 |
commit | 3c4d101de003ea292be5ac5baf5d73c6c2747367 (patch) | |
tree | 5918d12b69c4bfd84f05a585d62174586a80fd18 /spec/frontend/issues | |
parent | b2c21b99c7eb52b5fd906b1e7b4b08d4eb7a296c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/issues')
-rw-r--r-- | spec/frontend/issues/show/components/title_spec.js | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/spec/frontend/issues/show/components/title_spec.js b/spec/frontend/issues/show/components/title_spec.js index 7560b733ae6..0699846e4bb 100644 --- a/spec/frontend/issues/show/components/title_spec.js +++ b/spec/frontend/issues/show/components/title_spec.js @@ -1,94 +1,99 @@ -import Vue, { nextTick } from 'vue'; +import { nextTick } from 'vue'; +import { GlButton } from '@gitlab/ui'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; -import titleComponent from '~/issues/show/components/title.vue'; +import Title from '~/issues/show/components/title.vue'; import eventHub from '~/issues/show/event_hub'; -import Store from '~/issues/show/stores'; describe('Title component', () => { - let vm; - beforeEach(() => { + let wrapper; + + const getTitleHeader = () => wrapper.findByTestId('issue-title'); + const getEditButton = () => wrapper.findComponent(GlButton); + + const createWrapper = (props) => { setHTMLFixture(`<title />`); - const Component = Vue.extend(titleComponent); - const store = new Store({ - titleHtml: '', - descriptionHtml: '', - issuableRef: '', - }); - vm = new Component({ + wrapper = shallowMountExtended(Title, { propsData: { issuableRef: '#1', titleHtml: 'Testing <img />', titleText: 'Testing', - showForm: false, - formState: store.formState, + ...props, }, - }).$mount(); - }); + }); + }; afterEach(() => { resetHTMLFixture(); }); it('renders title HTML', () => { - expect(vm.$el.querySelector('.title').innerHTML.trim()).toBe('Testing <img>'); - }); - - it('updates page title when changing titleHtml', async () => { - const spy = jest.spyOn(vm, 'setPageTitle'); - vm.titleHtml = 'test'; + createWrapper(); - await nextTick(); - expect(spy).toHaveBeenCalled(); + expect(getTitleHeader().element.innerHTML.trim()).toBe('Testing <img>'); }); it('animates title changes', async () => { - vm.titleHtml = 'test'; + createWrapper(); - await nextTick(); + await wrapper.setProps({ + titleHtml: 'test', + }); - expect(vm.$el.querySelector('.title').classList).toContain('issue-realtime-pre-pulse'); - jest.runAllTimers(); + expect(getTitleHeader().classes('issue-realtime-pre-pulse')).toBe(true); + jest.runAllTimers(); await nextTick(); - expect(vm.$el.querySelector('.title').classList).toContain('issue-realtime-trigger-pulse'); + expect(getTitleHeader().classes('issue-realtime-trigger-pulse')).toBe(true); }); it('updates page title after changing title', async () => { - vm.titleHtml = 'changed'; - vm.titleText = 'changed'; + createWrapper(); + + await wrapper.setProps({ + titleHtml: 'changed', + titleText: 'changed', + }); - await nextTick(); expect(document.querySelector('title').textContent.trim()).toContain('changed'); }); describe('inline edit button', () => { it('should not show by default', () => { - expect(vm.$el.querySelector('.btn-edit')).toBeNull(); + createWrapper(); + + expect(getEditButton().exists()).toBe(false); }); it('should not show if canUpdate is false', () => { - vm.showInlineEditButton = true; - vm.canUpdate = false; + createWrapper({ + showInlineEditButton: true, + canUpdate: false, + }); - expect(vm.$el.querySelector('.btn-edit')).toBeNull(); + expect(getEditButton().exists()).toBe(false); }); it('should show if showInlineEditButton and canUpdate', () => { - vm.showInlineEditButton = true; - vm.canUpdate = true; + createWrapper({ + showInlineEditButton: true, + canUpdate: true, + }); - expect(vm.$el.querySelector('.btn-edit')).toBeDefined(); + expect(getEditButton().exists()).toBe(true); }); it('should trigger open.form event when clicked', async () => { - jest.spyOn(eventHub, '$emit').mockImplementation(() => {}); - vm.showInlineEditButton = true; - vm.canUpdate = true; + eventHub.$emit = jest.fn(); + + createWrapper({ + showInlineEditButton: true, + canUpdate: true, + }); - await nextTick(); - vm.$el.querySelector('.btn-edit').click(); + getEditButton().vm.$emit('click'); expect(eventHub.$emit).toHaveBeenCalledWith('open.form'); }); |