debian-mirror-gitlab/spec/frontend/search/sidebar/components/scope_navigation_spec.js

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

143 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-03-04 22:38:38 +05:30
import { GlNav, GlNavItem, GlIcon } from '@gitlab/ui';
2023-01-13 00:05:48 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import { MOCK_QUERY, MOCK_NAVIGATION } from 'jest/search/mock_data';
import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue';
Vue.use(Vuex);
describe('ScopeNavigation', () => {
let wrapper;
const actionSpies = {
fetchSidebarCount: jest.fn(),
};
2023-05-27 22:25:52 +05:30
const getterSpies = {
currentScope: jest.fn(() => 'issues'),
};
2023-01-13 00:05:48 +05:30
const createComponent = (initialState) => {
const store = new Vuex.Store({
state: {
urlQuery: MOCK_QUERY,
navigation: MOCK_NAVIGATION,
...initialState,
},
actions: actionSpies,
2023-05-27 22:25:52 +05:30
getters: getterSpies,
2023-01-13 00:05:48 +05:30
});
wrapper = shallowMount(ScopeNavigation, {
store,
});
};
const findNavElement = () => wrapper.find('nav');
const findGlNav = () => wrapper.findComponent(GlNav);
const findGlNavItems = () => wrapper.findAllComponents(GlNavItem);
2023-05-27 22:25:52 +05:30
const findGlNavItemActive = () => wrapper.find('[active=true]');
const findGlNavItemActiveLabel = () => findGlNavItemActive().find('[data-testid="label"]');
const findGlNavItemActiveCount = () => findGlNavItemActive().find('[data-testid="count"]');
2023-01-13 00:05:48 +05:30
describe('scope navigation', () => {
beforeEach(() => {
createComponent();
});
it('renders section', () => {
expect(findNavElement().exists()).toBe(true);
});
it('renders nav component', () => {
expect(findGlNav().exists()).toBe(true);
});
it('renders all nav item components', () => {
expect(findGlNavItems()).toHaveLength(9);
});
2023-03-04 22:38:38 +05:30
it('has all proper links', () => {
2023-01-13 00:05:48 +05:30
const linkAtPosition = 3;
const { link } = MOCK_NAVIGATION[Object.keys(MOCK_NAVIGATION)[linkAtPosition]];
expect(findGlNavItems().at(linkAtPosition).attributes('href')).toBe(link);
});
});
2023-03-04 22:38:38 +05:30
describe('scope navigation sets proper state with url scope set', () => {
2023-01-13 00:05:48 +05:30
beforeEach(() => {
createComponent();
});
2023-03-04 22:38:38 +05:30
it('has correct active item', () => {
2023-05-27 22:25:52 +05:30
expect(findGlNavItemActive().exists()).toBe(true);
expect(findGlNavItemActiveLabel().text()).toBe('Issues');
2023-01-13 00:05:48 +05:30
});
2023-03-04 22:38:38 +05:30
it('has correct active item count', () => {
2023-01-13 00:05:48 +05:30
expect(findGlNavItemActiveCount().text()).toBe('2.4K');
});
2023-03-04 22:38:38 +05:30
it('does not have plus sign after count text', () => {
2023-05-27 22:25:52 +05:30
expect(findGlNavItemActive().findComponent(GlIcon).exists()).toBe(false);
2023-03-04 22:38:38 +05:30
});
it('has count is highlighted correctly', () => {
expect(findGlNavItemActiveCount().classes('gl-text-gray-900')).toBe(true);
});
});
describe('scope navigation sets proper state with NO url scope set', () => {
beforeEach(() => {
2023-05-27 22:25:52 +05:30
getterSpies.currentScope = jest.fn(() => 'projects');
2023-03-04 22:38:38 +05:30
createComponent({
urlQuery: {},
2023-05-27 22:25:52 +05:30
navigation: {
...MOCK_NAVIGATION,
projects: {
...MOCK_NAVIGATION.projects,
active: true,
},
issues: {
...MOCK_NAVIGATION.issues,
active: false,
},
},
2023-03-04 22:38:38 +05:30
});
});
it('has correct active item', () => {
2023-05-27 22:25:52 +05:30
expect(findGlNavItemActive().exists()).toBe(true);
expect(findGlNavItemActiveLabel().text()).toBe('Projects');
2023-03-04 22:38:38 +05:30
});
it('has correct active item count', () => {
expect(findGlNavItemActiveCount().text()).toBe('10K');
});
it('has correct active item count and over limit sign', () => {
2023-05-27 22:25:52 +05:30
expect(findGlNavItemActive().findComponent(GlIcon).exists()).toBe(true);
2023-03-04 22:38:38 +05:30
});
2023-01-13 00:05:48 +05:30
});
2023-06-20 00:43:36 +05:30
describe.each`
searchTherm | hasBeenCalled
${null} | ${0}
${'test'} | ${1}
`('fetchSidebarCount', ({ searchTherm, hasBeenCalled }) => {
beforeEach(() => {
createComponent({
urlQuery: {
search: searchTherm,
},
});
});
it('is only called when search term is set', () => {
expect(actionSpies.fetchSidebarCount).toHaveBeenCalledTimes(hasBeenCalled);
});
});
2023-01-13 00:05:48 +05:30
});