diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/frontend/projects | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/frontend/projects')
-rw-r--r-- | spec/frontend/projects/compare/components/app_legacy_spec.js | 159 | ||||
-rw-r--r-- | spec/frontend/projects/terraform_notification/terraform_notification_spec.js | 27 |
2 files changed, 8 insertions, 178 deletions
diff --git a/spec/frontend/projects/compare/components/app_legacy_spec.js b/spec/frontend/projects/compare/components/app_legacy_spec.js deleted file mode 100644 index 6fdf4014575..00000000000 --- a/spec/frontend/projects/compare/components/app_legacy_spec.js +++ /dev/null @@ -1,159 +0,0 @@ -import { GlButton } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import CompareApp from '~/projects/compare/components/app_legacy.vue'; -import RevisionDropdown from '~/projects/compare/components/revision_dropdown_legacy.vue'; - -jest.mock('~/lib/utils/csrf', () => ({ token: 'mock-csrf-token' })); - -const projectCompareIndexPath = 'some/path'; -const refsProjectPath = 'some/refs/path'; -const paramsFrom = 'main'; -const paramsTo = 'some-other-branch'; - -describe('CompareApp component', () => { - let wrapper; - - const createComponent = (props = {}) => { - wrapper = shallowMount(CompareApp, { - propsData: { - projectCompareIndexPath, - refsProjectPath, - paramsFrom, - paramsTo, - projectMergeRequestPath: '', - createMrPath: '', - ...props, - }, - }); - }; - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - beforeEach(() => { - createComponent(); - }); - - const findSourceDropdown = () => wrapper.find('[data-testid="sourceRevisionDropdown"]'); - const findTargetDropdown = () => wrapper.find('[data-testid="targetRevisionDropdown"]'); - - it('renders component with prop', () => { - expect(wrapper.props()).toEqual( - expect.objectContaining({ - projectCompareIndexPath, - refsProjectPath, - paramsFrom, - paramsTo, - }), - ); - }); - - it('contains the correct form attributes', () => { - expect(wrapper.attributes('action')).toBe(projectCompareIndexPath); - expect(wrapper.attributes('method')).toBe('POST'); - }); - - it('has input with csrf token', () => { - expect(wrapper.find('input[name="authenticity_token"]').attributes('value')).toBe( - 'mock-csrf-token', - ); - }); - - it('has ellipsis', () => { - expect(wrapper.find('[data-testid="ellipsis"]').exists()).toBe(true); - }); - - describe('Source and Target BranchDropdown components', () => { - const findAllBranchDropdowns = () => wrapper.findAll(RevisionDropdown); - - it('renders the components with the correct props', () => { - expect(findAllBranchDropdowns().length).toBe(2); - expect(findSourceDropdown().props('revisionText')).toBe('Source'); - expect(findTargetDropdown().props('revisionText')).toBe('Target'); - }); - - it('sets the revision when the "selectRevision" event is emitted', async () => { - findSourceDropdown().vm.$emit('selectRevision', { - direction: 'to', - revision: 'some-source-revision', - }); - - findTargetDropdown().vm.$emit('selectRevision', { - direction: 'from', - revision: 'some-target-revision', - }); - - await wrapper.vm.$nextTick(); - - expect(findTargetDropdown().props('paramsBranch')).toBe('some-target-revision'); - expect(findSourceDropdown().props('paramsBranch')).toBe('some-source-revision'); - }); - }); - - describe('compare button', () => { - const findCompareButton = () => wrapper.find(GlButton); - - it('renders button', () => { - expect(findCompareButton().exists()).toBe(true); - }); - - it('submits form', () => { - findCompareButton().vm.$emit('click'); - expect(wrapper.find('form').element.submit).toHaveBeenCalled(); - }); - - it('has compare text', () => { - expect(findCompareButton().text()).toBe('Compare'); - }); - }); - - describe('swap revisions button', () => { - const findSwapRevisionsButton = () => wrapper.find('[data-testid="swapRevisionsButton"]'); - - it('renders the swap revisions button', () => { - expect(findSwapRevisionsButton().exists()).toBe(true); - }); - - it('has the correct text', () => { - expect(findSwapRevisionsButton().text()).toBe('Swap revisions'); - }); - - it('swaps revisions when clicked', async () => { - findSwapRevisionsButton().vm.$emit('click'); - - await wrapper.vm.$nextTick(); - - expect(findTargetDropdown().props('paramsBranch')).toBe(paramsTo); - expect(findSourceDropdown().props('paramsBranch')).toBe(paramsFrom); - }); - }); - - describe('merge request buttons', () => { - const findProjectMrButton = () => wrapper.find('[data-testid="projectMrButton"]'); - const findCreateMrButton = () => wrapper.find('[data-testid="createMrButton"]'); - - it('does not have merge request buttons', () => { - createComponent(); - expect(findProjectMrButton().exists()).toBe(false); - expect(findCreateMrButton().exists()).toBe(false); - }); - - it('has "View open merge request" button', () => { - createComponent({ - projectMergeRequestPath: 'some/project/merge/request/path', - }); - expect(findProjectMrButton().exists()).toBe(true); - expect(findCreateMrButton().exists()).toBe(false); - }); - - it('has "Create merge request" button', () => { - createComponent({ - createMrPath: 'some/create/create/mr/path', - }); - expect(findProjectMrButton().exists()).toBe(false); - expect(findCreateMrButton().exists()).toBe(true); - }); - }); -}); diff --git a/spec/frontend/projects/terraform_notification/terraform_notification_spec.js b/spec/frontend/projects/terraform_notification/terraform_notification_spec.js index be34b207c4b..71c22998b08 100644 --- a/spec/frontend/projects/terraform_notification/terraform_notification_spec.js +++ b/spec/frontend/projects/terraform_notification/terraform_notification_spec.js @@ -5,19 +5,21 @@ import TerraformNotification from '~/projects/terraform_notification/components/ jest.mock('~/lib/utils/common_utils'); -const bannerDissmisedKey = 'terraform_notification_dismissed_for_project_1'; +const terraformImagePath = '/path/to/image'; +const bannerDismissedKey = 'terraform_notification_dismissed'; describe('TerraformNotificationBanner', () => { let wrapper; - const propsData = { - projectId: 1, + const provideData = { + terraformImagePath, + bannerDismissedKey, }; const findBanner = () => wrapper.findComponent(GlBanner); beforeEach(() => { wrapper = shallowMount(TerraformNotification, { - propsData, + provide: provideData, stubs: { GlBanner }, }); }); @@ -27,19 +29,6 @@ describe('TerraformNotificationBanner', () => { parseBoolean.mockReturnValue(false); }); - describe('when the dismiss cookie is set', () => { - beforeEach(() => { - parseBoolean.mockReturnValue(true); - wrapper = shallowMount(TerraformNotification, { - propsData, - }); - }); - - it('should not render the banner', () => { - expect(findBanner().exists()).toBe(false); - }); - }); - describe('when the dismiss cookie is not set', () => { it('should render the banner', () => { expect(findBanner().exists()).toBe(true); @@ -51,8 +40,8 @@ describe('TerraformNotificationBanner', () => { await findBanner().vm.$emit('close'); }); - it('should set the cookie with the bannerDissmisedKey', () => { - expect(setCookie).toHaveBeenCalledWith(bannerDissmisedKey, true); + it('should set the cookie with the bannerDismissedKey', () => { + expect(setCookie).toHaveBeenCalledWith(bannerDismissedKey, true); }); it('should remove the banner', () => { |