Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/super_sidebar/components/global_search/command_palette/command_palette_items_spec.js')
-rw-r--r--spec/frontend/super_sidebar/components/global_search/command_palette/command_palette_items_spec.js93
1 files changed, 90 insertions, 3 deletions
diff --git a/spec/frontend/super_sidebar/components/global_search/command_palette/command_palette_items_spec.js b/spec/frontend/super_sidebar/components/global_search/command_palette/command_palette_items_spec.js
index 21d085dc0fb..85eb7e2e241 100644
--- a/spec/frontend/super_sidebar/components/global_search/command_palette/command_palette_items_spec.js
+++ b/spec/frontend/super_sidebar/components/global_search/command_palette/command_palette_items_spec.js
@@ -6,18 +6,22 @@ import CommandPaletteItems from '~/super_sidebar/components/global_search/comman
import {
COMMAND_HANDLE,
USERS_GROUP_TITLE,
+ PATH_GROUP_TITLE,
USER_HANDLE,
+ PATH_HANDLE,
SEARCH_SCOPE,
+ MAX_ROWS,
} from '~/super_sidebar/components/global_search/command_palette/constants';
import {
commandMapper,
linksReducer,
+ fileMapper,
} from '~/super_sidebar/components/global_search/command_palette/utils';
import { getFormattedItem } from '~/super_sidebar/components/global_search/utils';
import axios from '~/lib/utils/axios_utils';
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
import waitForPromises from 'helpers/wait_for_promises';
-import { COMMANDS, LINKS, USERS } from './mock_data';
+import { COMMANDS, LINKS, USERS, FILES } from './mock_data';
const links = LINKS.reduce(linksReducer, []);
@@ -25,6 +29,8 @@ describe('CommandPaletteItems', () => {
let wrapper;
const autocompletePath = '/autocomplete';
const searchContext = { project: { id: 1 }, group: { id: 2 } };
+ const projectFilesPath = 'project/files/path';
+ const projectBlobPath = '/blob/main';
const createComponent = (props) => {
wrapper = shallowMount(CommandPaletteItems, {
@@ -42,6 +48,8 @@ describe('CommandPaletteItems', () => {
commandPaletteLinks: LINKS,
autocompletePath,
searchContext,
+ projectFilesPath,
+ projectBlobPath,
},
});
};
@@ -50,7 +58,7 @@ describe('CommandPaletteItems', () => {
const findGroups = () => wrapper.findAllComponents(GlDisclosureDropdownGroup);
const findLoader = () => wrapper.findComponent(GlLoadingIcon);
- describe('COMMANDS & LINKS', () => {
+ describe('Commands and links', () => {
it('renders all commands initially', () => {
createComponent();
const commandGroup = COMMANDS.map(commandMapper)[0];
@@ -90,7 +98,7 @@ describe('CommandPaletteItems', () => {
});
});
- describe('USERS, ISSUES, PROJECTS', () => {
+ describe('Users, issues, and projects', () => {
let mockAxios;
beforeEach(() => {
@@ -140,4 +148,83 @@ describe('CommandPaletteItems', () => {
expect(wrapper.text()).toBe('No results found');
});
});
+
+ describe('Project files', () => {
+ let mockAxios;
+
+ beforeEach(() => {
+ mockAxios = new MockAdapter(axios);
+ });
+
+ it('should request project files on first search', () => {
+ jest.spyOn(axios, 'get');
+ const searchQuery = 'gitlab-ci.yml';
+ createComponent({ handle: PATH_HANDLE, searchQuery });
+
+ expect(axios.get).toHaveBeenCalledWith(projectFilesPath);
+ expect(findLoader().exists()).toBe(true);
+ });
+
+ it(`should render all items when returned number of items is less than ${MAX_ROWS}`, async () => {
+ const numberOfItems = MAX_ROWS - 1;
+ const items = FILES.slice(0, numberOfItems).map(fileMapper.bind(null, projectBlobPath));
+ mockAxios.onGet().replyOnce(HTTP_STATUS_OK, FILES.slice(0, numberOfItems));
+ jest.spyOn(fuzzaldrinPlus, 'filter').mockReturnValue(items);
+
+ const searchQuery = 'gitlab-ci.yml';
+ createComponent({ handle: PATH_HANDLE, searchQuery });
+
+ await waitForPromises();
+
+ expect(findGroups().at(0).props('group')).toMatchObject({
+ name: PATH_GROUP_TITLE,
+ items: items.slice(0, MAX_ROWS),
+ });
+
+ expect(findItems()).toHaveLength(numberOfItems);
+ });
+
+ it(`should render first ${MAX_ROWS} returned items when number of returned items exceeds ${MAX_ROWS}`, async () => {
+ const items = FILES.map(fileMapper.bind(null, projectBlobPath));
+ mockAxios.onGet().replyOnce(HTTP_STATUS_OK, FILES);
+ jest.spyOn(fuzzaldrinPlus, 'filter').mockReturnValue(items);
+
+ const searchQuery = 'gitlab-ci.yml';
+ createComponent({ handle: PATH_HANDLE, searchQuery });
+
+ await waitForPromises();
+
+ expect(findItems()).toHaveLength(MAX_ROWS);
+ expect(findGroups().at(0).props('group')).toMatchObject({
+ name: PATH_GROUP_TITLE,
+ items: items.slice(0, MAX_ROWS),
+ });
+ });
+
+ it('should display no results message when no files matched the search query', async () => {
+ mockAxios.onGet().replyOnce(HTTP_STATUS_OK, []);
+ const searchQuery = 'gitlab-ci.yml';
+ createComponent({ handle: PATH_HANDLE, searchQuery });
+ await waitForPromises();
+ expect(wrapper.text()).toBe('No results found');
+ });
+
+ it('should not make additional server call on the search query change', async () => {
+ const searchQuery = 'gitlab-ci.yml';
+ const newSearchQuery = 'package.json';
+
+ jest.spyOn(axios, 'get');
+
+ createComponent({ handle: PATH_HANDLE, searchQuery });
+
+ mockAxios.onGet().replyOnce(HTTP_STATUS_OK, FILES);
+ await waitForPromises();
+
+ expect(axios.get).toHaveBeenCalledTimes(1);
+
+ await wrapper.setProps({ searchQuery: newSearchQuery });
+
+ expect(axios.get).toHaveBeenCalledTimes(1);
+ });
+ });
});