diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-04 12:13:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-04 12:13:07 +0300 |
commit | 6cd4578a23ffe0fb94632f83a07a25d01f8d6821 (patch) | |
tree | d21e9881e4ceb8ae6f28451f0797acc59e7cd1e8 /spec/frontend | |
parent | b6a194f6625042a09e083443c3326cc61aefc4c0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
10 files changed, 410 insertions, 605 deletions
diff --git a/spec/frontend/google_cloud/aiml/service_table_spec.js b/spec/frontend/google_cloud/aiml/service_table_spec.js new file mode 100644 index 00000000000..b14db064a7f --- /dev/null +++ b/spec/frontend/google_cloud/aiml/service_table_spec.js @@ -0,0 +1,34 @@ +import { GlTable } from '@gitlab/ui'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import ServiceTable from '~/google_cloud/aiml/service_table.vue'; + +describe('google_cloud/aiml/service_table', () => { + let wrapper; + + const findTable = () => wrapper.findComponent(GlTable); + + beforeEach(() => { + const propsData = { + visionAiUrl: '#url-vision-ai', + languageAiUrl: '#url-language-ai', + translationAiUrl: '#url-translate-ai', + }; + wrapper = mountExtended(ServiceTable, { propsData }); + }); + + it('should contain a table', () => { + expect(findTable().exists()).toBe(true); + }); + + it.each` + name | testId | url + ${'key-vision-ai'} | ${'button-vision-ai'} | ${'#url-vision-ai'} + ${'key-natural-language-ai'} | ${'button-natural-language-ai'} | ${'#url-language-ai'} + ${'key-translation-ai'} | ${'button-translation-ai'} | ${'#url-translate-ai'} + `('renders $name button with correct url', ({ testId, url }) => { + const button = wrapper.findByTestId(testId); + + expect(button.exists()).toBe(true); + expect(button.attributes('href')).toBe(url); + }); +}); diff --git a/spec/frontend/search/sidebar/components/scope_new_navigation_spec.js b/spec/frontend/search/sidebar/components/scope_new_navigation_spec.js index 105beae8638..c7dd6e931b1 100644 --- a/spec/frontend/search/sidebar/components/scope_new_navigation_spec.js +++ b/spec/frontend/search/sidebar/components/scope_new_navigation_spec.js @@ -42,7 +42,7 @@ describe('ScopeNewNavigation', () => { const findNavItems = () => wrapper.findAllComponents(NavItem); const findNavItemActive = () => wrapper.find('[aria-current=page]'); const findNavItemActiveLabel = () => - findNavItemActive().find('[class="gl-pr-3 gl-text-gray-900 gl-truncate-end"]'); + findNavItemActive().find('[class="gl-pr-8 gl-text-gray-900 gl-truncate-end"]'); describe('scope navigation', () => { beforeEach(() => { diff --git a/spec/frontend/token_access/mock_data.js b/spec/frontend/token_access/mock_data.js index 67ee197b831..a4b5532108a 100644 --- a/spec/frontend/token_access/mock_data.js +++ b/spec/frontend/token_access/mock_data.js @@ -121,32 +121,6 @@ export const mockFields = [ }, ]; -export const optInJwtQueryResponse = (optInJwt) => ({ - data: { - project: { - id: '1', - ciCdSettings: { - optInJwt, - __typename: 'ProjectCiCdSetting', - }, - __typename: 'Project', - }, - }, -}); - -export const optInJwtMutationResponse = (optInJwt) => ({ - data: { - projectCiCdSettingsUpdate: { - ciCdSettings: { - optInJwt, - __typename: 'ProjectCiCdSetting', - }, - errors: [], - __typename: 'ProjectCiCdSettingsUpdatePayload', - }, - }, -}); - export const inboundJobTokenScopeEnabledResponse = { data: { project: { diff --git a/spec/frontend/token_access/opt_in_jwt_spec.js b/spec/frontend/token_access/opt_in_jwt_spec.js deleted file mode 100644 index cdb385aa743..00000000000 --- a/spec/frontend/token_access/opt_in_jwt_spec.js +++ /dev/null @@ -1,144 +0,0 @@ -import { GlLink, GlLoadingIcon, GlToggle, GlSprintf } from '@gitlab/ui'; -import Vue from 'vue'; -import VueApollo from 'vue-apollo'; -import createMockApollo from 'helpers/mock_apollo_helper'; -import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import waitForPromises from 'helpers/wait_for_promises'; -import { createAlert } from '~/alert'; -import { OPT_IN_JWT_HELP_LINK } from '~/token_access/constants'; -import OptInJwt from '~/token_access/components/opt_in_jwt.vue'; -import getOptInJwtSettingQuery from '~/token_access/graphql/queries/get_opt_in_jwt_setting.query.graphql'; -import updateOptInJwtMutation from '~/token_access/graphql/mutations/update_opt_in_jwt.mutation.graphql'; -import { optInJwtMutationResponse, optInJwtQueryResponse } from './mock_data'; - -const errorMessage = 'An error occurred'; -const error = new Error(errorMessage); - -Vue.use(VueApollo); - -jest.mock('~/alert'); - -describe('OptInJwt component', () => { - let wrapper; - - const failureHandler = jest.fn().mockRejectedValue(error); - const enabledOptInJwtHandler = jest.fn().mockResolvedValue(optInJwtQueryResponse(true)); - const disabledOptInJwtHandler = jest.fn().mockResolvedValue(optInJwtQueryResponse(false)); - const updateOptInJwtHandler = jest.fn().mockResolvedValue(optInJwtMutationResponse(true)); - - const findHelpLink = () => wrapper.findComponent(GlLink); - const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); - const findToggle = () => wrapper.findComponent(GlToggle); - const findOptInJwtExpandedSection = () => wrapper.findByTestId('opt-in-jwt-expanded-section'); - - const createMockApolloProvider = (requestHandlers) => { - return createMockApollo(requestHandlers); - }; - - const createComponent = (requestHandlers, mountFn = shallowMountExtended, options = {}) => { - wrapper = mountFn(OptInJwt, { - provide: { - fullPath: 'root/my-repo', - }, - apolloProvider: createMockApolloProvider(requestHandlers), - data() { - return { - targetProjectPath: 'root/test', - }; - }, - ...options, - }); - }; - - const createShallowComponent = (requestHandlers, options = {}) => - createComponent(requestHandlers, shallowMountExtended, options); - const createFullComponent = (requestHandlers, options = {}) => - createComponent(requestHandlers, mountExtended, options); - - describe('loading state', () => { - it('shows loading state and hides toggle while waiting on query to resolve', async () => { - createShallowComponent([[getOptInJwtSettingQuery, enabledOptInJwtHandler]]); - - expect(findLoadingIcon().exists()).toBe(true); - expect(findToggle().exists()).toBe(false); - - await waitForPromises(); - - expect(findLoadingIcon().exists()).toBe(false); - expect(findToggle().exists()).toBe(true); - }); - }); - - describe('template', () => { - it('renders help link', async () => { - createShallowComponent([[getOptInJwtSettingQuery, enabledOptInJwtHandler]], { - stubs: { - GlToggle, - GlSprintf, - GlLink, - }, - }); - await waitForPromises(); - - expect(findHelpLink().exists()).toBe(true); - expect(findHelpLink().attributes('href')).toBe(OPT_IN_JWT_HELP_LINK); - }); - }); - - describe('toggle JWT token access', () => { - it('code instruction is visible when toggle is enabled', async () => { - createShallowComponent([[getOptInJwtSettingQuery, enabledOptInJwtHandler]]); - - await waitForPromises(); - - expect(findToggle().props('value')).toBe(true); - expect(findOptInJwtExpandedSection().exists()).toBe(true); - }); - - it('code instruction is hidden when toggle is disabled', async () => { - createShallowComponent([[getOptInJwtSettingQuery, disabledOptInJwtHandler]]); - - await waitForPromises(); - - expect(findToggle().props('value')).toBe(false); - expect(findOptInJwtExpandedSection().exists()).toBe(false); - }); - - describe('update JWT token access', () => { - it('calls updateOptInJwtMutation with correct arguments', async () => { - createFullComponent([ - [getOptInJwtSettingQuery, disabledOptInJwtHandler], - [updateOptInJwtMutation, updateOptInJwtHandler], - ]); - - await waitForPromises(); - - findToggle().vm.$emit('change', true); - - expect(updateOptInJwtHandler).toHaveBeenCalledWith({ - input: { - fullPath: 'root/my-repo', - optInJwt: true, - }, - }); - }); - - it('handles update error', async () => { - createFullComponent([ - [getOptInJwtSettingQuery, enabledOptInJwtHandler], - [updateOptInJwtMutation, failureHandler], - ]); - - await waitForPromises(); - - findToggle().vm.$emit('change', false); - - await waitForPromises(); - - expect(createAlert).toHaveBeenCalledWith({ - message: 'An error occurred while update the setting. Please try again.', - }); - }); - }); - }); -}); diff --git a/spec/frontend/token_access/token_access_app_spec.js b/spec/frontend/token_access/token_access_app_spec.js index cff16fd125c..77356f1b839 100644 --- a/spec/frontend/token_access/token_access_app_spec.js +++ b/spec/frontend/token_access/token_access_app_spec.js @@ -1,7 +1,6 @@ import { shallowMount } from '@vue/test-utils'; import OutboundTokenAccess from '~/token_access/components/outbound_token_access.vue'; import InboundTokenAccess from '~/token_access/components/inbound_token_access.vue'; -import OptInJwt from '~/token_access/components/opt_in_jwt.vue'; import TokenAccessApp from '~/token_access/components/token_access_app.vue'; describe('TokenAccessApp component', () => { @@ -9,7 +8,6 @@ describe('TokenAccessApp component', () => { const findOutboundTokenAccess = () => wrapper.findComponent(OutboundTokenAccess); const findInboundTokenAccess = () => wrapper.findComponent(InboundTokenAccess); - const findOptInJwt = () => wrapper.findComponent(OptInJwt); const createComponent = () => { wrapper = shallowMount(TokenAccessApp); @@ -20,10 +18,6 @@ describe('TokenAccessApp component', () => { createComponent(); }); - it('renders the opt in jwt component', () => { - expect(findOptInJwt().exists()).toBe(true); - }); - it('renders the outbound token access component', () => { expect(findOutboundTokenAccess().exists()).toBe(true); }); diff --git a/spec/frontend/work_items/components/notes/work_item_add_note_spec.js b/spec/frontend/work_items/components/notes/work_item_add_note_spec.js index a97164f9dce..fbcf759d50f 100644 --- a/spec/frontend/work_items/components/notes/work_item_add_note_spec.js +++ b/spec/frontend/work_items/components/notes/work_item_add_note_spec.js @@ -5,21 +5,16 @@ import createMockApollo from 'helpers/mock_apollo_helper'; import { mockTracking } from 'helpers/tracking_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { clearDraft } from '~/lib/utils/autosave'; -import { config } from '~/graphql_shared/issuable_client'; import WorkItemAddNote from '~/work_items/components/notes/work_item_add_note.vue'; import WorkItemCommentLocked from '~/work_items/components/notes/work_item_comment_locked.vue'; import WorkItemCommentForm from '~/work_items/components/notes/work_item_comment_form.vue'; import createNoteMutation from '~/work_items/graphql/notes/create_work_item_note.mutation.graphql'; import { TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; -import workItemQuery from '~/work_items/graphql/work_item.query.graphql'; -import workItemNotesQuery from '~/work_items/graphql/notes/work_item_notes.query.graphql'; import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { - workItemResponseFactory, - workItemQueryResponse, - projectWorkItemResponse, createWorkItemNoteResponse, - mockWorkItemNotesResponse, + workItemByIidResponseFactory, + workItemQueryResponse, } from '../../mock_data'; jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal'); @@ -33,7 +28,6 @@ describe('Work item add note', () => { Vue.use(VueApollo); const mutationSuccessHandler = jest.fn().mockResolvedValue(createWorkItemNoteResponse); - const workItemByIidResponseHandler = jest.fn().mockResolvedValue(projectWorkItemResponse); let workItemResponseHandler; const findCommentForm = () => wrapper.findComponent(WorkItemCommentForm); @@ -42,9 +36,8 @@ describe('Work item add note', () => { const createComponent = async ({ mutationHandler = mutationSuccessHandler, canUpdate = true, - workItemResponse = workItemResponseFactory({ canUpdate }), - queryVariables = { id: workItemId }, - fetchByIid = false, + workItemResponse = workItemByIidResponseFactory({ canUpdate }), + queryVariables = { iid: '1' }, signedIn = true, isEditing = true, workItemType = 'Task', @@ -55,24 +48,10 @@ describe('Work item add note', () => { window.gon.current_user_avatar_url = 'avatar.png'; } - const apolloProvider = createMockApollo( - [ - [workItemQuery, workItemResponseHandler], - [createNoteMutation, mutationHandler], - [workItemByIidQuery, workItemByIidResponseHandler], - ], - {}, - { ...config.cacheConfig }, - ); - - apolloProvider.clients.defaultClient.writeQuery({ - query: workItemNotesQuery, - variables: { - id: workItemId, - pageSize: 100, - }, - data: mockWorkItemNotesResponse.data, - }); + const apolloProvider = createMockApollo([ + [workItemByIidQuery, workItemResponseHandler], + [createNoteMutation, mutationHandler], + ]); const { id } = workItemQueryResponse.data.workItem; wrapper = shallowMountExtended(WorkItemAddNote, { @@ -81,7 +60,6 @@ describe('Work item add note', () => { workItemId: id, fullPath: 'test-project-path', queryVariables, - fetchByIid, workItemType, markdownPreviewPath: '/group/project/preview_markdown?target_type=WorkItem', autocompleteDataSources: {}, @@ -139,9 +117,7 @@ describe('Work item add note', () => { await createComponent({ isEditing: true, signedIn: true, - queryVariables: { - id: mockWorkItemNotesResponse.data.workItem.id, - }, + queryVariables: { iid: '1' }, }); findCommentForm().vm.$emit('submitForm', 'some text'); @@ -244,23 +220,14 @@ describe('Work item add note', () => { }); }); - it('calls the global ID work item query when `fetchByIid` prop is false', async () => { - createComponent({ fetchByIid: false }); - await waitForPromises(); + it('calls the work item query', async () => { + await createComponent(); expect(workItemResponseHandler).toHaveBeenCalled(); - expect(workItemByIidResponseHandler).not.toHaveBeenCalled(); - }); - - it('calls the IID work item query when when `fetchByIid` prop is true', async () => { - await createComponent({ fetchByIid: true, isEditing: false }); - - expect(workItemResponseHandler).not.toHaveBeenCalled(); - expect(workItemByIidResponseHandler).toHaveBeenCalled(); }); - it('skips calling the handlers when missing the needed queryVariables', async () => { - await createComponent({ queryVariables: {}, fetchByIid: false, isEditing: false }); + it('skips calling the work item query when missing queryVariables', async () => { + await createComponent({ queryVariables: {}, isEditing: false }); expect(workItemResponseHandler).not.toHaveBeenCalled(); }); diff --git a/spec/frontend/work_items/components/notes/work_item_discussion_spec.js b/spec/frontend/work_items/components/notes/work_item_discussion_spec.js index 568b76150c4..28c8ea13a23 100644 --- a/spec/frontend/work_items/components/notes/work_item_discussion_spec.js +++ b/spec/frontend/work_items/components/notes/work_item_discussion_spec.js @@ -11,7 +11,7 @@ import { } from 'jest/work_items/mock_data'; import { WIDGET_TYPE_NOTES } from '~/work_items/constants'; -const mockWorkItemNotesWidgetResponseWithComments = mockWorkItemNotesResponseWithComments.data.workItem.widgets.find( +const mockWorkItemNotesWidgetResponseWithComments = mockWorkItemNotesResponseWithComments.data.workspace.workItems.nodes[0].widgets.find( (widget) => widget.type === WIDGET_TYPE_NOTES, ); @@ -28,8 +28,7 @@ describe('Work Item Discussion', () => { const createComponent = ({ discussion = [mockWorkItemCommentNote], workItemId = mockWorkItemId, - queryVariables = { id: workItemId }, - fetchByIid = false, + queryVariables = { iid: '1' }, fullPath = 'gitlab-org', workItemType = 'Task', } = {}) => { @@ -38,7 +37,6 @@ describe('Work Item Discussion', () => { discussion, workItemId, queryVariables, - fetchByIid, fullPath, workItemType, markdownPreviewPath: '/group/project/preview_markdown?target_type=WorkItem', diff --git a/spec/frontend/work_items/components/notes/work_item_note_spec.js b/spec/frontend/work_items/components/notes/work_item_note_spec.js index f8be2f5667b..956b52bb74c 100644 --- a/spec/frontend/work_items/components/notes/work_item_note_spec.js +++ b/spec/frontend/work_items/components/notes/work_item_note_spec.js @@ -11,13 +11,14 @@ import NoteBody from '~/work_items/components/notes/work_item_note_body.vue'; import NoteHeader from '~/notes/components/note_header.vue'; import NoteActions from '~/work_items/components/notes/work_item_note_actions.vue'; import WorkItemCommentForm from '~/work_items/components/notes/work_item_comment_form.vue'; -import workItemQuery from '~/work_items/graphql/work_item.query.graphql'; import updateWorkItemNoteMutation from '~/work_items/graphql/notes/update_work_item_note.mutation.graphql'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; +import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { mockAssignees, mockWorkItemCommentNote, updateWorkItemMutationResponse, + workItemByIidResponseFactory, workItemQueryResponse, } from 'jest/work_items/mock_data'; import { i18n, TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; @@ -45,7 +46,7 @@ describe('Work Item Note', () => { }, }); - const workItemResponseHandler = jest.fn().mockResolvedValue(workItemQueryResponse); + const workItemResponseHandler = jest.fn().mockResolvedValue(workItemByIidResponseFactory()); const updateWorkItemMutationSuccessHandler = jest .fn() @@ -68,8 +69,7 @@ describe('Work Item Note', () => { workItemId = mockWorkItemId, updateWorkItemMutationHandler = updateWorkItemMutationSuccessHandler, assignees = mockAssignees, - queryVariables = { id: mockWorkItemId }, - fetchByIid = false, + queryVariables = { iid: '1' }, } = {}) => { wrapper = shallowMount(WorkItemNote, { propsData: { @@ -81,11 +81,10 @@ describe('Work Item Note', () => { autocompleteDataSources: {}, assignees, queryVariables, - fetchByIid, fullPath: 'test-project-path', }, apolloProvider: mockApollo([ - [workItemQuery, workItemResponseHandler], + [workItemByIidQuery, workItemResponseHandler], [updateWorkItemNoteMutation, updateNoteMutationHandler], [updateWorkItemMutation, updateWorkItemMutationHandler], ]), diff --git a/spec/frontend/work_items/components/work_item_notes_spec.js b/spec/frontend/work_items/components/work_item_notes_spec.js index 9cbe8283468..be5861ba1e2 100644 --- a/spec/frontend/work_items/components/work_item_notes_spec.js +++ b/spec/frontend/work_items/components/work_item_notes_spec.js @@ -10,7 +10,6 @@ import WorkItemNotes from '~/work_items/components/work_item_notes.vue'; import WorkItemDiscussion from '~/work_items/components/notes/work_item_discussion.vue'; import WorkItemAddNote from '~/work_items/components/notes/work_item_add_note.vue'; import WorkItemNotesActivityHeader from '~/work_items/components/notes/work_item_notes_activity_header.vue'; -import workItemNotesQuery from '~/work_items/graphql/notes/work_item_notes.query.graphql'; import workItemNotesByIidQuery from '~/work_items/graphql/notes/work_item_notes_by_iid.query.graphql'; import deleteWorkItemNoteMutation from '~/work_items/graphql/notes/delete_work_item_notes.mutation.graphql'; import workItemNoteCreatedSubscription from '~/work_items/graphql/notes/work_item_note_created.subscription.graphql'; @@ -36,15 +35,11 @@ const mockNotesWidgetResponse = mockWorkItemNotesResponse.data.workItem.widgets. (widget) => widget.type === WIDGET_TYPE_NOTES, ); -const mockNotesByIidWidgetResponse = mockWorkItemNotesByIidResponse.data.workspace.workItems.nodes[0].widgets.find( +const mockMoreNotesWidgetResponse = mockMoreWorkItemNotesResponse.data.workspace.workItems.nodes[0].widgets.find( (widget) => widget.type === WIDGET_TYPE_NOTES, ); -const mockMoreNotesWidgetResponse = mockMoreWorkItemNotesResponse.data.workItem.widgets.find( - (widget) => widget.type === WIDGET_TYPE_NOTES, -); - -const mockWorkItemNotesWidgetResponseWithComments = mockWorkItemNotesResponseWithComments.data.workItem.widgets.find( +const mockWorkItemNotesWidgetResponseWithComments = mockWorkItemNotesResponseWithComments.data.workspace.workItems.nodes[0].widgets.find( (widget) => widget.type === WIDGET_TYPE_NOTES, ); @@ -61,7 +56,6 @@ describe('WorkItemNotes component', () => { const findAllSystemNotes = () => wrapper.findAllComponents(SystemNote); const findAllListItems = () => wrapper.findAll('ul.timeline > *'); - const findWorkItemAddNote = () => wrapper.findComponent(WorkItemAddNote); const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader); const findActivityHeader = () => wrapper.findComponent(WorkItemNotesActivityHeader); const findSystemNoteAtIndex = (index) => findAllSystemNotes().at(index); @@ -69,10 +63,7 @@ describe('WorkItemNotes component', () => { const findWorkItemCommentNoteAtIndex = (index) => findAllWorkItemCommentNotes().at(index); const findDeleteNoteModal = () => wrapper.findComponent(GlModal); - const workItemNotesQueryHandler = jest.fn().mockResolvedValue(mockWorkItemNotesResponse); - const workItemNotesByIidQueryHandler = jest - .fn() - .mockResolvedValue(mockWorkItemNotesByIidResponse); + const workItemNotesQueryHandler = jest.fn().mockResolvedValue(mockWorkItemNotesByIidResponse); const workItemMoreNotesQueryHandler = jest.fn().mockResolvedValue(mockMoreWorkItemNotesResponse); const workItemNotesWithCommentsQueryHandler = jest .fn() @@ -93,7 +84,6 @@ describe('WorkItemNotes component', () => { const createComponent = ({ workItemId = mockWorkItemId, - fetchByIid = false, workItemIid = mockWorkItemIid, defaultWorkItemNotesQueryHandler = workItemNotesQueryHandler, deleteWINoteMutationHandler = deleteWorkItemNoteMutationSuccessHandler, @@ -101,8 +91,7 @@ describe('WorkItemNotes component', () => { } = {}) => { wrapper = shallowMount(WorkItemNotes, { apolloProvider: createMockApollo([ - [workItemNotesQuery, defaultWorkItemNotesQueryHandler], - [workItemNotesByIidQuery, workItemNotesByIidQueryHandler], + [workItemNotesByIidQuery, defaultWorkItemNotesQueryHandler], [deleteWorkItemNoteMutation, deleteWINoteMutationHandler], [workItemNoteCreatedSubscription, notesCreateSubscriptionHandler], [workItemNoteUpdatedSubscription, notesUpdateSubscriptionHandler], @@ -111,11 +100,8 @@ describe('WorkItemNotes component', () => { propsData: { workItemId, workItemIid, - queryVariables: { - id: workItemId, - }, + queryVariables: { iid: '1' }, fullPath: 'test-path', - fetchByIid, workItemType: 'task', reportAbusePath: '/report/abuse/path', isModal, @@ -134,17 +120,6 @@ describe('WorkItemNotes component', () => { expect(findActivityHeader().exists()).toBe(true); }); - it('passes correct props to comment form component', async () => { - createComponent({ - workItemId: mockWorkItemId, - fetchByIid: false, - defaultWorkItemNotesQueryHandler: workItemNotesByIidQueryHandler, - }); - await waitForPromises(); - - expect(findWorkItemAddNote().props('fetchByIid')).toEqual(false); - }); - describe('when notes are loading', () => { it('renders skeleton loader', () => { expect(findSkeletonLoader().exists()).toBe(true); @@ -162,28 +137,15 @@ describe('WorkItemNotes component', () => { it('renders system notes to the length of the response', async () => { await waitForPromises(); + expect(workItemNotesQueryHandler).toHaveBeenCalledWith({ + after: undefined, + iid: '1', + pageSize: 30, + }); expect(findAllSystemNotes()).toHaveLength(mockNotesWidgetResponse.discussions.nodes.length); }); }); - describe('when the notes are fetched by `iid`', () => { - beforeEach(async () => { - createComponent({ workItemId: mockWorkItemId, fetchByIid: true }); - await waitForPromises(); - }); - - it('renders the notes list to the length of the response', () => { - expect(workItemNotesByIidQueryHandler).toHaveBeenCalled(); - expect(findAllSystemNotes()).toHaveLength( - mockNotesByIidWidgetResponse.discussions.nodes.length, - ); - }); - - it('passes correct props to comment form component', () => { - expect(findWorkItemAddNote().props('fetchByIid')).toEqual(true); - }); - }); - describe('Pagination', () => { describe('When there is no next page', () => { it('fetch more notes is not called', async () => { @@ -202,14 +164,14 @@ describe('WorkItemNotes component', () => { it('fetch more notes should be called', async () => { expect(workItemMoreNotesQueryHandler).toHaveBeenCalledWith({ pageSize: DEFAULT_PAGE_SIZE_NOTES, - id: 'gid://gitlab/WorkItem/1', + iid: '1', }); await nextTick(); expect(workItemMoreNotesQueryHandler).toHaveBeenCalledWith({ pageSize: DEFAULT_PAGE_SIZE_NOTES, - id: 'gid://gitlab/WorkItem/1', + iid: '1', after: mockMoreNotesWidgetResponse.discussions.pageInfo.endCursor, }); }); diff --git a/spec/frontend/work_items/mock_data.js b/spec/frontend/work_items/mock_data.js index 36e8d713789..2ab31908577 100644 --- a/spec/frontend/work_items/mock_data.js +++ b/spec/frontend/work_items/mock_data.js @@ -2235,186 +2235,197 @@ export const mockWorkItemNotesByIidResponse = { }; export const mockMoreWorkItemNotesResponse = { data: { - workItem: { - id: 'gid://gitlab/WorkItem/600', - iid: '60', - widgets: [ - { - __typename: 'WorkItemWidgetIteration', - }, - { - __typename: 'WorkItemWidgetWeight', - }, - { - __typename: 'WorkItemWidgetAssignees', - }, - { - __typename: 'WorkItemWidgetLabels', - }, - { - __typename: 'WorkItemWidgetDescription', - }, - { - __typename: 'WorkItemWidgetHierarchy', - }, - { - __typename: 'WorkItemWidgetStartAndDueDate', - }, - { - __typename: 'WorkItemWidgetMilestone', - }, - { - type: 'NOTES', - discussions: { - pageInfo: { - hasNextPage: true, - hasPreviousPage: false, - startCursor: null, - endCursor: 'endCursor', - __typename: 'PageInfo', - }, - nodes: [ + workspace: { + id: 'gid://gitlab/Project/6', + workItems: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/600', + iid: '60', + widgets: [ { - id: 'gid://gitlab/Discussion/8bbc4890b6ff0f2cde93a5a0947cd2b8a13d3b6e', - notes: { - nodes: [ - { - id: 'gid://gitlab/Note/2428', - body: 'added #31 as parent issue', - bodyHtml: - '<p data-sourcepos="1:1-1:25" dir="auto">added <a href="/flightjs/Flight/-/issues/31" data-reference-type="issue" data-original="#31" data-link="false" data-link-reference="false" data-project="6" data-issue="224" data-project-path="flightjs/Flight" data-iid="31" data-issue-type="issue" data-container=body data-placement="top" title="Perferendis est quae totam quia laborum tempore ut voluptatem." class="gfm gfm-issue">#31</a> as parent issue</p>', - systemNoteIconName: 'link', - createdAt: '2022-11-14T04:18:59Z', - lastEditedAt: null, - url: - 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', - lastEditedBy: null, - system: true, - internal: false, - discussion: { - id: 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da1112356a59e', - }, - userPermissions: { - adminNote: false, - awardEmoji: true, - readNote: true, - createNote: true, - resolveNote: true, - repositionNote: true, - __typename: 'NotePermissions', - }, - author: { - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - id: 'gid://gitlab/User/1', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', - }, - __typename: 'Note', - }, - ], - __typename: 'NoteConnection', - }, - __typename: 'Discussion', + __typename: 'WorkItemWidgetIteration', }, { - id: 'gid://gitlab/Discussion/7b08b89a728a5ceb7de8334246837ba1d07270dc', - notes: { - nodes: [ - { - id: 'gid://gitlab/MilestoneNote/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83823', - body: 'changed milestone to %v4.0', - bodyHtml: - '<p data-sourcepos="1:1-1:23" dir="auto">changed milestone to <a href="/flightjs/Flight/-/milestones/5" data-reference-type="milestone" data-original="%5" data-link="false" data-link-reference="false" data-project="6" data-milestone="30" data-container=body data-placement="top" title="" class="gfm gfm-milestone has-tooltip">%v4.0</a></p>', - systemNoteIconName: 'clock', - createdAt: '2022-11-14T04:18:59Z', - lastEditedAt: null, - url: - 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', - lastEditedBy: null, - system: true, - internal: false, - discussion: { - id: 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da1272356a59e', - }, - userPermissions: { - adminNote: false, - awardEmoji: true, - readNote: true, - createNote: true, - resolveNote: true, - repositionNote: true, - __typename: 'NotePermissions', - }, - author: { - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - id: 'gid://gitlab/User/1', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', - }, - __typename: 'Note', - }, - ], - __typename: 'NoteConnection', - }, - __typename: 'Discussion', + __typename: 'WorkItemWidgetWeight', }, { - id: 'gid://gitlab/Discussion/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83864', - notes: { + __typename: 'WorkItemWidgetAssignees', + }, + { + __typename: 'WorkItemWidgetLabels', + }, + { + __typename: 'WorkItemWidgetDescription', + }, + { + __typename: 'WorkItemWidgetHierarchy', + }, + { + __typename: 'WorkItemWidgetStartAndDueDate', + }, + { + __typename: 'WorkItemWidgetMilestone', + }, + { + type: 'NOTES', + discussions: { + pageInfo: { + hasNextPage: true, + hasPreviousPage: false, + startCursor: null, + endCursor: 'endCursor', + __typename: 'PageInfo', + }, nodes: [ { - id: 'gid://gitlab/WeightNote/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83864', - body: 'changed weight to **89**', - bodyHtml: '<p dir="auto">changed weight to <strong>89</strong></p>', - systemNoteIconName: 'weight', - createdAt: '2022-11-25T07:16:20Z', - lastEditedAt: null, - url: - 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', - lastEditedBy: null, - system: true, - internal: false, - discussion: { - id: 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da12723569876', + id: 'gid://gitlab/Discussion/8bbc4890b6ff0f2cde93a5a0947cd2b8a13d3b6e', + notes: { + nodes: [ + { + id: 'gid://gitlab/Note/2428', + body: 'added #31 as parent issue', + bodyHtml: + '<p data-sourcepos="1:1-1:25" dir="auto">added <a href="/flightjs/Flight/-/issues/31" data-reference-type="issue" data-original="#31" data-link="false" data-link-reference="false" data-project="6" data-issue="224" data-project-path="flightjs/Flight" data-iid="31" data-issue-type="issue" data-container=body data-placement="top" title="Perferendis est quae totam quia laborum tempore ut voluptatem." class="gfm gfm-issue">#31</a> as parent issue</p>', + systemNoteIconName: 'link', + createdAt: '2022-11-14T04:18:59Z', + lastEditedAt: null, + url: + 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', + lastEditedBy: null, + system: true, + internal: false, + discussion: { + id: + 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da1112356a59e', + }, + userPermissions: { + adminNote: false, + awardEmoji: true, + readNote: true, + createNote: true, + resolveNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + author: { + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + id: 'gid://gitlab/User/1', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + __typename: 'Note', + }, + ], + __typename: 'NoteConnection', }, - userPermissions: { - adminNote: false, - awardEmoji: true, - readNote: true, - createNote: true, - resolveNote: true, - repositionNote: true, - __typename: 'NotePermissions', + __typename: 'Discussion', + }, + { + id: 'gid://gitlab/Discussion/7b08b89a728a5ceb7de8334246837ba1d07270dc', + notes: { + nodes: [ + { + id: + 'gid://gitlab/MilestoneNote/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83823', + body: 'changed milestone to %v4.0', + bodyHtml: + '<p data-sourcepos="1:1-1:23" dir="auto">changed milestone to <a href="/flightjs/Flight/-/milestones/5" data-reference-type="milestone" data-original="%5" data-link="false" data-link-reference="false" data-project="6" data-milestone="30" data-container=body data-placement="top" title="" class="gfm gfm-milestone has-tooltip">%v4.0</a></p>', + systemNoteIconName: 'clock', + createdAt: '2022-11-14T04:18:59Z', + lastEditedAt: null, + url: + 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', + lastEditedBy: null, + system: true, + internal: false, + discussion: { + id: + 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da1272356a59e', + }, + userPermissions: { + adminNote: false, + awardEmoji: true, + readNote: true, + createNote: true, + resolveNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + author: { + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + id: 'gid://gitlab/User/1', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + __typename: 'Note', + }, + ], + __typename: 'NoteConnection', }, - author: { - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - id: 'gid://gitlab/User/1', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', + __typename: 'Discussion', + }, + { + id: 'gid://gitlab/Discussion/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83864', + notes: { + nodes: [ + { + id: 'gid://gitlab/WeightNote/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83864', + body: 'changed weight to **89**', + bodyHtml: '<p dir="auto">changed weight to <strong>89</strong></p>', + systemNoteIconName: 'weight', + createdAt: '2022-11-25T07:16:20Z', + lastEditedAt: null, + url: + 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', + lastEditedBy: null, + system: true, + internal: false, + discussion: { + id: + 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da12723569876', + }, + userPermissions: { + adminNote: false, + awardEmoji: true, + readNote: true, + createNote: true, + resolveNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + author: { + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + id: 'gid://gitlab/User/1', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + __typename: 'Note', + }, + ], + __typename: 'NoteConnection', }, - __typename: 'Note', + __typename: 'Discussion', }, ], - __typename: 'NoteConnection', + __typename: 'DiscussionConnection', }, - __typename: 'Discussion', + __typename: 'WorkItemWidgetNotes', }, ], - __typename: 'DiscussionConnection', + __typename: 'WorkItem', }, - __typename: 'WorkItemWidgetNotes', - }, - ], - __typename: 'WorkItem', + ], + }, }, }, }; @@ -2514,177 +2525,187 @@ export const mockWorkItemCommentNote = { export const mockWorkItemNotesResponseWithComments = { data: { - workItem: { - id: 'gid://gitlab/WorkItem/600', - iid: '60', - widgets: [ - { - __typename: 'WorkItemWidgetIteration', - }, - { - __typename: 'WorkItemWidgetWeight', - }, - { - __typename: 'WorkItemWidgetAssignees', - }, - { - __typename: 'WorkItemWidgetLabels', - }, - { - __typename: 'WorkItemWidgetDescription', - }, - { - __typename: 'WorkItemWidgetHierarchy', - }, - { - __typename: 'WorkItemWidgetStartAndDueDate', - }, - { - __typename: 'WorkItemWidgetMilestone', - }, - { - type: 'NOTES', - discussions: { - pageInfo: { - hasNextPage: false, - hasPreviousPage: false, - startCursor: null, - endCursor: null, - __typename: 'PageInfo', - }, - nodes: [ + workspace: { + id: 'gid://gitlab/Project/6', + workItems: { + nodes: [ + { + id: 'gid://gitlab/WorkItem/600', + iid: '60', + widgets: [ { - id: 'gid://gitlab/Discussion/8bbc4890b6ff0f2cde93a5a0947cd2b8a13d3b6e', - notes: { - nodes: [ - { - id: 'gid://gitlab/DiscussionNote/174', - body: 'Separate thread', - bodyHtml: '<p data-sourcepos="1:1-1:15" dir="auto">Separate thread</p>', - system: false, - internal: false, - systemNoteIconName: null, - createdAt: '2023-01-12T07:47:40Z', - lastEditedAt: null, - url: - 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', - lastEditedBy: null, - discussion: { - id: 'gid://gitlab/Discussion/2bb1162fd0d39297d1a68fdd7d4083d3780af0f3', - __typename: 'Discussion', - }, - author: { - id: 'gid://gitlab/User/1', - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', - }, - userPermissions: { - adminNote: true, - awardEmoji: true, - readNote: true, - createNote: true, - resolveNote: true, - repositionNote: true, - __typename: 'NotePermissions', - }, - __typename: 'Note', - }, - { - id: 'gid://gitlab/DiscussionNote/235', - body: 'Thread comment', - bodyHtml: '<p data-sourcepos="1:1-1:15" dir="auto">Thread comment</p>', - system: false, - internal: false, - systemNoteIconName: null, - createdAt: '2023-01-18T09:09:54Z', - lastEditedAt: null, - url: - 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', - lastEditedBy: null, - discussion: { - id: 'gid://gitlab/Discussion/2bb1162fd0d39297d1a68fdd7d4083d3780af0f3', - __typename: 'Discussion', - }, - author: { - id: 'gid://gitlab/User/1', - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', - }, - userPermissions: { - adminNote: true, - awardEmoji: true, - readNote: true, - createNote: true, - resolveNote: true, - repositionNote: true, - __typename: 'NotePermissions', - }, - __typename: 'Note', - }, - ], - __typename: 'NoteConnection', - }, - __typename: 'Discussion', + __typename: 'WorkItemWidgetIteration', }, { - id: 'gid://gitlab/Discussion/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83864', - notes: { + __typename: 'WorkItemWidgetWeight', + }, + { + __typename: 'WorkItemWidgetAssignees', + }, + { + __typename: 'WorkItemWidgetLabels', + }, + { + __typename: 'WorkItemWidgetDescription', + }, + { + __typename: 'WorkItemWidgetHierarchy', + }, + { + __typename: 'WorkItemWidgetStartAndDueDate', + }, + { + __typename: 'WorkItemWidgetMilestone', + }, + { + type: 'NOTES', + discussions: { + pageInfo: { + hasNextPage: false, + hasPreviousPage: false, + startCursor: null, + endCursor: null, + __typename: 'PageInfo', + }, nodes: [ { - id: 'gid://gitlab/WeightNote/0f2f195ec0d1ef95ee9d5b10446b8e96a9883864', - body: 'Main thread 2', - bodyHtml: '<p data-sourcepos="1:1-1:15" dir="auto">Main thread 2</p>', - systemNoteIconName: 'weight', - createdAt: '2022-11-25T07:16:20Z', - lastEditedAt: null, - url: - 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', - lastEditedBy: null, - system: false, - internal: false, - discussion: { - id: 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da12723560987', - }, - userPermissions: { - adminNote: false, - awardEmoji: true, - readNote: true, - createNote: true, - resolveNote: true, - repositionNote: true, - __typename: 'NotePermissions', + id: 'gid://gitlab/Discussion/8bbc4890b6ff0f2cde93a5a0947cd2b8a13d3b6e', + notes: { + nodes: [ + { + id: 'gid://gitlab/DiscussionNote/174', + body: 'Separate thread', + bodyHtml: '<p data-sourcepos="1:1-1:15" dir="auto">Separate thread</p>', + system: false, + internal: false, + systemNoteIconName: null, + createdAt: '2023-01-12T07:47:40Z', + lastEditedAt: null, + url: + 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', + lastEditedBy: null, + discussion: { + id: + 'gid://gitlab/Discussion/2bb1162fd0d39297d1a68fdd7d4083d3780af0f3', + __typename: 'Discussion', + }, + author: { + id: 'gid://gitlab/User/1', + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + userPermissions: { + adminNote: true, + awardEmoji: true, + readNote: true, + createNote: true, + resolveNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + __typename: 'Note', + }, + { + id: 'gid://gitlab/DiscussionNote/235', + body: 'Thread comment', + bodyHtml: '<p data-sourcepos="1:1-1:15" dir="auto">Thread comment</p>', + system: false, + internal: false, + systemNoteIconName: null, + createdAt: '2023-01-18T09:09:54Z', + lastEditedAt: null, + url: + 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', + lastEditedBy: null, + discussion: { + id: + 'gid://gitlab/Discussion/2bb1162fd0d39297d1a68fdd7d4083d3780af0f3', + __typename: 'Discussion', + }, + author: { + id: 'gid://gitlab/User/1', + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + userPermissions: { + adminNote: true, + awardEmoji: true, + readNote: true, + createNote: true, + resolveNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + __typename: 'Note', + }, + ], + __typename: 'NoteConnection', }, - author: { - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - id: 'gid://gitlab/User/1', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', + __typename: 'Discussion', + }, + { + id: 'gid://gitlab/Discussion/0f2f195ec0d1ef95ee9d5b10446b8e96a7d83864', + notes: { + nodes: [ + { + id: 'gid://gitlab/WeightNote/0f2f195ec0d1ef95ee9d5b10446b8e96a9883864', + body: 'Main thread 2', + bodyHtml: '<p data-sourcepos="1:1-1:15" dir="auto">Main thread 2</p>', + systemNoteIconName: 'weight', + createdAt: '2022-11-25T07:16:20Z', + lastEditedAt: null, + url: + 'http://127.0.0.1:3000/flightjs/Flight/-/work_items/37?iid_path=true#note_191', + lastEditedBy: null, + system: false, + internal: false, + discussion: { + id: + 'gid://gitlab/Discussion/9c17769ca29798eddaed539d010da12723560987', + }, + userPermissions: { + adminNote: false, + awardEmoji: true, + readNote: true, + createNote: true, + resolveNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + author: { + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + id: 'gid://gitlab/User/1', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + __typename: 'Note', + }, + ], + __typename: 'NoteConnection', }, - __typename: 'Note', + __typename: 'Discussion', }, ], - __typename: 'NoteConnection', + __typename: 'DiscussionConnection', }, - __typename: 'Discussion', + __typename: 'WorkItemWidgetNotes', }, ], - __typename: 'DiscussionConnection', + __typename: 'WorkItem', }, - __typename: 'WorkItemWidgetNotes', - }, - ], - __typename: 'WorkItem', + ], + }, }, }, }; |