From 73778b9c53d13a2e06a693c30073366deedead8f Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 15 Dec 2023 21:15:55 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../fixtures/static/whats_new_notification.html | 7 --- .../super_sidebar/components/help_center_spec.js | 7 +-- .../components/approvals/approvals_spec.js | 36 +++++++---- spec/frontend/whats_new/utils/notification_spec.js | 73 ---------------------- 4 files changed, 26 insertions(+), 97 deletions(-) delete mode 100644 spec/frontend/fixtures/static/whats_new_notification.html delete mode 100644 spec/frontend/whats_new/utils/notification_spec.js (limited to 'spec/frontend') diff --git a/spec/frontend/fixtures/static/whats_new_notification.html b/spec/frontend/fixtures/static/whats_new_notification.html deleted file mode 100644 index bc8a27c779f..00000000000 --- a/spec/frontend/fixtures/static/whats_new_notification.html +++ /dev/null @@ -1,7 +0,0 @@ -
-
-
-
-
-
-
diff --git a/spec/frontend/super_sidebar/components/help_center_spec.js b/spec/frontend/super_sidebar/components/help_center_spec.js index 8ef742ba946..8e9e3e8ba20 100644 --- a/spec/frontend/super_sidebar/components/help_center_spec.js +++ b/spec/frontend/super_sidebar/components/help_center_spec.js @@ -168,14 +168,13 @@ describe('HelpCenter component', () => { describe('showWhatsNew', () => { beforeEach(() => { - beforeEach(() => { - createWrapper({ ...sidebarData, show_version_check: true }); - }); + createWrapper({ ...sidebarData, show_version_check: true }); + findButton("What's new 5").click(); }); it('shows the "What\'s new" slideout', () => { - expect(toggleWhatsNewDrawer).toHaveBeenCalledWith(expect.any(Object)); + expect(toggleWhatsNewDrawer).toHaveBeenCalledWith(sidebarData.whats_new_version_digest); }); it('shows the existing "What\'s new" slideout instance on subsequent clicks', () => { diff --git a/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js b/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js index c81f4328d2a..c3ed131d6e3 100644 --- a/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js +++ b/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js @@ -1,11 +1,11 @@ import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import { GlButton, GlSprintf } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; import { createMockSubscription as createMockApolloSubscription } from 'mock-apollo-client'; import approvedByCurrentUser from 'test_fixtures/graphql/merge_requests/approvals/approvals.query.graphql.json'; -import { visitUrl } from '~/lib/utils/url_utility'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; +import { stubComponent } from 'helpers/stub_component'; import waitForPromises from 'helpers/wait_for_promises'; import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { createAlert } from '~/alert'; @@ -29,11 +29,6 @@ jest.mock('~/alert', () => ({ dismiss: mockAlertDismiss, })), })); -jest.mock('~/lib/utils/url_utility', () => ({ - ...jest.requireActual('~/lib/utils/url_utility'), - visitUrl: jest.fn(), -})); - const TEST_HELP_PATH = 'help/path'; const testApprovedBy = () => [1, 7, 10].map((id) => ({ id })); const testApprovals = () => ({ @@ -53,6 +48,9 @@ describe('MRWidget approvals', () => { let wrapper; let service; let mr; + const submitSpy = jest.fn().mockImplementation((e) => { + e.preventDefault(); + }); const createComponent = (options = {}, responses = { query: approvedByCurrentUser }) => { mockedSubscription = createMockApolloSubscription(); @@ -68,7 +66,7 @@ describe('MRWidget approvals', () => { apolloProvider.defaultClient.setRequestHandler(query, stream); }); - wrapper = shallowMount(Approvals, { + wrapper = shallowMountExtended(Approvals, { apolloProvider, propsData: { mr, @@ -78,7 +76,18 @@ describe('MRWidget approvals', () => { provide, stubs: { GlSprintf, + GlForm: { + data() { + return { submitSpy }; + }, + // Workaround jsdom not implementing form submit + template: '
', + }, + GlButton: stubComponent(GlButton, { + template: '', + }), }, + attachTo: document.body, }); }; @@ -257,11 +266,11 @@ describe('MRWidget approvals', () => { }); describe('when SAML auth is required and user clicks Approve with SAML', () => { - const fakeGroupSamlPath = '/example_group_saml'; + const fakeSamlPath = '/example_group_saml'; beforeEach(async () => { mr.requireSamlAuthToApprove = true; - mr.samlApprovalPath = fakeGroupSamlPath; + mr.samlApprovalPath = fakeSamlPath; createComponent({}, { query: createCanApproveResponse() }); await waitForPromises(); @@ -269,9 +278,10 @@ describe('MRWidget approvals', () => { it('redirects the user to the group SAML path', async () => { const action = findAction(); - action.vm.$emit('click'); - await nextTick(); - expect(visitUrl).toHaveBeenCalledWith(fakeGroupSamlPath); + + await action.trigger('click'); + + expect(submitSpy).toHaveBeenCalled(); }); }); diff --git a/spec/frontend/whats_new/utils/notification_spec.js b/spec/frontend/whats_new/utils/notification_spec.js deleted file mode 100644 index 020d833c578..00000000000 --- a/spec/frontend/whats_new/utils/notification_spec.js +++ /dev/null @@ -1,73 +0,0 @@ -import htmlWhatsNewNotification from 'test_fixtures_static/whats_new_notification.html'; -import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; -import { useLocalStorageSpy } from 'helpers/local_storage_helper'; -import { setNotification, getVersionDigest } from '~/whats_new/utils/notification'; - -describe('~/whats_new/utils/notification', () => { - useLocalStorageSpy(); - - let wrapper; - - const findNotificationEl = () => wrapper.querySelector('.header-help'); - const findNotificationCountEl = () => wrapper.querySelector('.js-whats-new-notification-count'); - const getAppEl = () => wrapper.querySelector('.app'); - - beforeEach(() => { - setHTMLFixture(htmlWhatsNewNotification); - wrapper = document.querySelector('.whats-new-notification-fixture-root'); - }); - - afterEach(() => { - wrapper.remove(); - resetHTMLFixture(); - }); - - describe('setNotification', () => { - const subject = () => setNotification(getAppEl()); - - it("when storage key doesn't exist it adds notifications class", () => { - const notificationEl = findNotificationEl(); - - expect(notificationEl.classList).not.toContain('with-notifications'); - - subject(); - - expect(findNotificationCountEl()).not.toBe(null); - expect(notificationEl.classList).toContain('with-notifications'); - }); - - it('removes class and count element when storage key has current digest', () => { - const notificationEl = findNotificationEl(); - - notificationEl.classList.add('with-notifications'); - localStorage.setItem('display-whats-new-notification', 'version-digest'); - - expect(findNotificationCountEl()).not.toBe(null); - - subject(); - - expect(findNotificationCountEl()).toBe(null); - expect(notificationEl.classList).not.toContain('with-notifications'); - }); - - it('removes class and count element when no records and digest undefined', () => { - const notificationEl = findNotificationEl(); - - notificationEl.classList.add('with-notifications'); - localStorage.setItem('display-whats-new-notification', 'version-digest'); - - expect(findNotificationCountEl()).not.toBe(null); - - setNotification(wrapper.querySelector('[data-testid="without-digest"]')); - - expect(findNotificationCountEl()).toBe(null); - expect(notificationEl.classList).not.toContain('with-notifications'); - }); - }); - - describe('getVersionDigest', () => { - it('retrieves the storage key data attribute from the el', () => { - expect(getVersionDigest(getAppEl())).toBe('version-digest'); - }); - }); -}); -- cgit v1.2.3