debian-mirror-gitlab/spec/frontend/ide/components/activity_bar_spec.js

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

82 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { nextTick } from 'vue';
2022-08-27 11:52:29 +05:30
import { GlBadge } from '@gitlab/ui';
2023-06-20 00:43:36 +05:30
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
2018-10-15 14:42:47 +05:30
import ActivityBar from '~/ide/components/activity_bar.vue';
2021-03-11 19:13:27 +05:30
import { leftSidebarViews } from '~/ide/constants';
import { createStore } from '~/ide/stores';
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
const { edit, ...VIEW_OBJECTS_WITHOUT_EDIT } = leftSidebarViews;
const MODES_WITHOUT_EDIT = Object.keys(VIEW_OBJECTS_WITHOUT_EDIT);
const MODES = Object.keys(leftSidebarViews);
2022-08-27 11:52:29 +05:30
describe('IDE ActivityBar component', () => {
let wrapper;
2020-10-24 23:57:45 +05:30
let store;
2018-10-15 14:42:47 +05:30
2022-08-27 11:52:29 +05:30
const findChangesBadge = () => wrapper.findComponent(GlBadge);
2023-06-20 00:43:36 +05:30
const findModeButton = (mode) => wrapper.findByTestId(`${mode}-mode-button`);
2021-03-11 19:13:27 +05:30
2022-08-27 11:52:29 +05:30
const mountComponent = (state) => {
2020-10-24 23:57:45 +05:30
store = createStore();
2022-08-27 11:52:29 +05:30
store.replaceState({
...store.state,
projects: { abcproject: { web_url: 'testing' } },
currentProjectId: 'abcproject',
...state,
2018-10-15 14:42:47 +05:30
});
2023-06-20 00:43:36 +05:30
wrapper = shallowMountExtended(ActivityBar, { store });
2022-08-27 11:52:29 +05:30
};
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
describe('active item', () => {
// Test that mode button does not have 'active' class before click,
// and does have 'active' class after click
const testSettingActiveItem = async (mode) => {
const button = findModeButton(mode);
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
expect(button.classes('active')).toBe(false);
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
button.trigger('click');
await nextTick();
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
expect(button.classes('active')).toBe(true);
};
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
it.each(MODES)('is initially set to %s mode', (mode) => {
mountComponent({ currentActivityView: leftSidebarViews[mode].name });
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
const button = findModeButton(mode);
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
expect(button.classes('active')).toBe(true);
2018-10-15 14:42:47 +05:30
});
2023-06-20 00:43:36 +05:30
it.each(MODES_WITHOUT_EDIT)('is correctly set after clicking %s mode button', (mode) => {
2022-08-27 11:52:29 +05:30
mountComponent();
2023-06-20 00:43:36 +05:30
testSettingActiveItem(mode);
2018-10-15 14:42:47 +05:30
});
2023-06-20 00:43:36 +05:30
it('is correctly set after clicking edit mode button', () => {
// The default currentActivityView is leftSidebarViews.edit.name,
// so for the 'edit' mode, we pass a different currentActivityView.
mountComponent({ currentActivityView: leftSidebarViews.review.name });
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
testSettingActiveItem('edit');
2018-10-15 14:42:47 +05:30
});
});
2021-03-11 19:13:27 +05:30
describe('changes badge', () => {
it('is rendered when files are staged', () => {
2022-08-27 11:52:29 +05:30
mountComponent({ stagedFiles: [{ path: '/path/to/file' }] });
2021-03-11 19:13:27 +05:30
2022-08-27 11:52:29 +05:30
expect(findChangesBadge().text()).toBe('1');
2021-03-11 19:13:27 +05:30
});
it('is not rendered when no changes are present', () => {
2022-08-27 11:52:29 +05:30
mountComponent();
expect(findChangesBadge().exists()).toBe(false);
2021-03-11 19:13:27 +05:30
});
});
2018-10-15 14:42:47 +05:30
});