debian-mirror-gitlab/spec/frontend/super_sidebar/components/user_bar_spec.js

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

85 lines
3.2 KiB
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import { GlBadge } from '@gitlab/ui';
2023-03-17 16:20:25 +05:30
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { __ } from '~/locale';
2023-04-23 21:23:45 +05:30
import CreateMenu from '~/super_sidebar/components/create_menu.vue';
import MergeRequestMenu from '~/super_sidebar/components/merge_request_menu.vue';
2023-03-17 16:20:25 +05:30
import Counter from '~/super_sidebar/components/counter.vue';
import UserBar from '~/super_sidebar/components/user_bar.vue';
import { sidebarData } from '../mock_data';
describe('UserBar component', () => {
let wrapper;
2023-04-23 21:23:45 +05:30
const findCreateMenu = () => wrapper.findComponent(CreateMenu);
2023-03-17 16:20:25 +05:30
const findCounter = (at) => wrapper.findAllComponents(Counter).at(at);
2023-04-23 21:23:45 +05:30
const findMergeRequestMenu = () => wrapper.findComponent(MergeRequestMenu);
2023-05-27 22:25:52 +05:30
const findBrandLogo = () => wrapper.findByTestId('brand-header-custom-logo');
2023-03-17 16:20:25 +05:30
2023-05-27 22:25:52 +05:30
const createWrapper = (extraSidebarData = {}) => {
2023-03-17 16:20:25 +05:30
wrapper = shallowMountExtended(UserBar, {
propsData: {
2023-05-27 22:25:52 +05:30
sidebarData: { ...sidebarData, ...extraSidebarData },
2023-03-17 16:20:25 +05:30
},
provide: {
rootPath: '/',
toggleNewNavEndpoint: '/-/profile/preferences',
},
});
};
describe('default', () => {
beforeEach(() => {
createWrapper();
});
2023-04-23 21:23:45 +05:30
it('passes the "Create new..." menu groups to the create-menu component', () => {
expect(findCreateMenu().props('groups')).toBe(sidebarData.create_new_menu_groups);
});
it('passes the "Merge request" menu groups to the merge_request_menu component', () => {
expect(findMergeRequestMenu().props('items')).toBe(sidebarData.merge_request_menu);
});
2023-03-17 16:20:25 +05:30
it('renders issues counter', () => {
expect(findCounter(0).props('count')).toBe(sidebarData.assigned_open_issues_count);
expect(findCounter(0).props('href')).toBe(sidebarData.issues_dashboard_path);
expect(findCounter(0).props('label')).toBe(__('Issues'));
});
2023-04-23 21:23:45 +05:30
it('renders merge requests counter', () => {
expect(findCounter(1).props('count')).toBe(sidebarData.total_merge_requests_count);
expect(findCounter(1).props('label')).toBe(__('Merge requests'));
});
2023-03-17 16:20:25 +05:30
it('renders todos counter', () => {
expect(findCounter(2).props('count')).toBe(sidebarData.todos_pending_count);
expect(findCounter(2).props('href')).toBe('/dashboard/todos');
expect(findCounter(2).props('label')).toBe(__('To-Do list'));
});
2023-05-27 22:25:52 +05:30
it('renders branding logo', () => {
expect(findBrandLogo().exists()).toBe(true);
expect(findBrandLogo().attributes('src')).toBe(sidebarData.logo_url);
});
});
describe('GitLab Next badge', () => {
describe('when on canary', () => {
it('should render a badge to switch off GitLab Next', () => {
createWrapper({ gitlab_com_and_canary: true });
const badge = wrapper.findComponent(GlBadge);
expect(badge.text()).toBe('Next');
expect(badge.attributes('href')).toBe(sidebarData.canary_toggle_com_url);
});
});
describe('when not on canary', () => {
it('should not render the GitLab Next badge', () => {
createWrapper({ gitlab_com_and_canary: false });
const badge = wrapper.findComponent(GlBadge);
expect(badge.exists()).toBe(false);
});
});
2023-03-17 16:20:25 +05:30
});
});