2022-08-27 11:52:29 +05:30
|
|
|
import { GlBadge } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
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
|
|
|
|
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);
|
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
|
|
|
});
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper = shallowMount(ActivityBar, { store });
|
|
|
|
};
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.destroy();
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateActivityBarView', () => {
|
|
|
|
beforeEach(() => {
|
2022-08-27 11:52:29 +05:30
|
|
|
mountComponent();
|
|
|
|
jest.spyOn(wrapper.vm, 'updateActivityBarView').mockImplementation(() => {});
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with edit value on click', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.find('.js-ide-edit-mode').trigger('click');
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.edit.name);
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with commit value on click', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.find('.js-ide-commit-mode').trigger('click');
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.commit.name);
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with review value on click', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.find('.js-ide-review-mode').trigger('click');
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.review.name);
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('active item', () => {
|
|
|
|
it('sets edit item active', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(wrapper.find('.js-ide-edit-mode').classes()).toContain('active');
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it('sets commit item active', () => {
|
|
|
|
mountComponent({ currentActivityView: leftSidebarViews.commit.name });
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.find('.js-ide-commit-mode').classes()).toContain('active');
|
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().exists()).toBe(true);
|
|
|
|
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
|
|
|
});
|