debian-mirror-gitlab/spec/frontend/search/store/getters_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-09-30 23:02:18 +05:30
import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY } from '~/search/store/constants';
import * as getters from '~/search/store/getters';
import createState from '~/search/store/state';
2023-05-27 22:25:52 +05:30
import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
2023-04-23 21:23:45 +05:30
import {
MOCK_QUERY,
MOCK_GROUPS,
MOCK_PROJECTS,
MOCK_AGGREGATIONS,
MOCK_LANGUAGE_AGGREGATIONS_BUCKETS,
2023-05-27 22:25:52 +05:30
TEST_FILTER_DATA,
MOCK_NAVIGATION,
2023-06-20 00:43:36 +05:30
MOCK_NAVIGATION_ITEMS,
2023-04-23 21:23:45 +05:30
} from '../mock_data';
2021-09-30 23:02:18 +05:30
describe('Global Search Store Getters', () => {
let state;
beforeEach(() => {
state = createState({ query: MOCK_QUERY });
2023-05-27 22:25:52 +05:30
useMockLocationHelper();
2021-09-30 23:02:18 +05:30
});
describe('frequentGroups', () => {
it('returns the correct data', () => {
2023-05-27 22:25:52 +05:30
state.frequentItems[GROUPS_LOCAL_STORAGE_KEY] = MOCK_GROUPS;
2021-09-30 23:02:18 +05:30
expect(getters.frequentGroups(state)).toStrictEqual(MOCK_GROUPS);
});
});
describe('frequentProjects', () => {
it('returns the correct data', () => {
2023-05-27 22:25:52 +05:30
state.frequentItems[PROJECTS_LOCAL_STORAGE_KEY] = MOCK_PROJECTS;
2021-09-30 23:02:18 +05:30
expect(getters.frequentProjects(state)).toStrictEqual(MOCK_PROJECTS);
});
});
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
describe('languageAggregationBuckets', () => {
it('returns the correct data', () => {
2023-04-23 21:23:45 +05:30
state.aggregations.data = MOCK_AGGREGATIONS;
2023-05-27 22:25:52 +05:30
expect(getters.languageAggregationBuckets(state)).toStrictEqual(
MOCK_LANGUAGE_AGGREGATIONS_BUCKETS,
);
2023-04-23 21:23:45 +05:30
});
2023-05-27 22:25:52 +05:30
});
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
describe('queryLanguageFilters', () => {
2023-04-23 21:23:45 +05:30
it('returns the correct data', () => {
2023-05-27 22:25:52 +05:30
state.query.language = Object.keys(TEST_FILTER_DATA.filters);
expect(getters.queryLanguageFilters(state)).toStrictEqual(state.query.language);
});
});
describe('currentScope', () => {
it('returns the correct scope name', () => {
state.navigation = MOCK_NAVIGATION;
expect(getters.currentScope(state)).toBe('issues');
});
});
describe('currentUrlQueryHasLanguageFilters', () => {
it.each`
description | lang | result
${'has valid language'} | ${{ language: ['a', 'b'] }} | ${true}
${'has empty lang'} | ${{ language: [] }} | ${false}
${'has no lang'} | ${{}} | ${false}
`('$description', ({ lang, result }) => {
state.urlQuery = lang;
expect(getters.currentUrlQueryHasLanguageFilters(state)).toBe(result);
2023-04-23 21:23:45 +05:30
});
});
2023-06-20 00:43:36 +05:30
describe('navigationItems', () => {
it('returns the re-mapped navigation data', () => {
state.navigation = MOCK_NAVIGATION;
expect(getters.navigationItems(state)).toStrictEqual(MOCK_NAVIGATION_ITEMS);
});
});
2021-09-30 23:02:18 +05:30
});