From cd8520845d9205622b5acf301b68c0ac7d81aaec Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 17 May 2021 21:10:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../jira_connect/components/groups_list_spec.js | 81 ++++++++++++++++++++-- 1 file changed, 74 insertions(+), 7 deletions(-) (limited to 'spec/frontend/jira_connect') diff --git a/spec/frontend/jira_connect/components/groups_list_spec.js b/spec/frontend/jira_connect/components/groups_list_spec.js index 71eb01db7d7..4b875928a90 100644 --- a/spec/frontend/jira_connect/components/groups_list_spec.js +++ b/spec/frontend/jira_connect/components/groups_list_spec.js @@ -143,14 +143,14 @@ describe('GroupsList', () => { }); it('calls `fetchGroups` with search term', () => { - expect(fetchGroups).toHaveBeenCalledWith(mockGroupsPath, { + expect(fetchGroups).toHaveBeenLastCalledWith(mockGroupsPath, { page: 1, - perPage: 10, + perPage: DEFAULT_GROUPS_PER_PAGE, search: mockSearchTeam, }); }); - it('disables GroupListItems', async () => { + it('disables GroupListItems', () => { findAllItems().wrappers.forEach((groupListItem) => { expect(groupListItem.props('disabled')).toBe(true); }); @@ -178,6 +178,73 @@ describe('GroupsList', () => { expect(findFirstItem().props('group')).toBe(mockGroup1); }); }); + + it.each` + userSearchTerm | finalSearchTerm + ${'gitl'} | ${'gitl'} + ${'git'} | ${'git'} + ${'gi'} | ${''} + ${'g'} | ${''} + ${''} | ${''} + ${undefined} | ${undefined} + `( + 'searches for "$finalSearchTerm" when user enters "$userSearchTerm"', + async ({ userSearchTerm, finalSearchTerm }) => { + fetchGroups.mockResolvedValue({ + data: [mockGroup1], + headers: { 'X-PAGE': 1, 'X-TOTAL': 1 }, + }); + + createComponent(); + await waitForPromises(); + + const searchBox = findSearchBox(); + searchBox.vm.$emit('input', userSearchTerm); + + expect(fetchGroups).toHaveBeenLastCalledWith(mockGroupsPath, { + page: 1, + perPage: DEFAULT_GROUPS_PER_PAGE, + search: finalSearchTerm, + }); + }, + ); + }); + + describe('when page=2', () => { + beforeEach(async () => { + const totalItems = DEFAULT_GROUPS_PER_PAGE + 1; + const mockGroups = createMockGroups(totalItems); + fetchGroups.mockResolvedValue({ + headers: { 'X-TOTAL': totalItems, 'X-PAGE': 1 }, + data: mockGroups, + }); + createComponent(); + await waitForPromises(); + + const paginationEl = findPagination(); + paginationEl.vm.$emit('input', 2); + }); + + it('should load results for page 2', () => { + expect(fetchGroups).toHaveBeenLastCalledWith(mockGroupsPath, { + page: 2, + perPage: DEFAULT_GROUPS_PER_PAGE, + search: '', + }); + }); + + it('resets page to 1 on search `input` event', () => { + const mockSearchTerm = 'gitlab'; + const searchBox = findSearchBox(); + + searchBox.vm.$emit('input', mockSearchTerm); + + expect(fetchGroups).toHaveBeenLastCalledWith(mockGroupsPath, { + page: 1, + perPage: DEFAULT_GROUPS_PER_PAGE, + search: mockSearchTerm, + }); + }); }); }); @@ -195,7 +262,6 @@ describe('GroupsList', () => { data: mockGroups, }); createComponent(); - await waitForPromises(); const paginationEl = findPagination(); @@ -218,13 +284,14 @@ describe('GroupsList', () => { await waitForPromises(); }); - it('executes `fetchGroups` with correct arguments', async () => { + it('executes `fetchGroups` with correct arguments', () => { const paginationEl = findPagination(); paginationEl.vm.$emit('input', 2); - expect(fetchGroups).toHaveBeenCalledWith(mockGroupsPath, { + expect(fetchGroups).toHaveBeenLastCalledWith(mockGroupsPath, { page: 2, - perPage: 10, + perPage: DEFAULT_GROUPS_PER_PAGE, + search: '', }); }); }); -- cgit v1.2.3