2018-04-18 06:29:40 -04:00
|
|
|
import Vue from 'vue';
|
2021-01-14 19:10:45 -05:00
|
|
|
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
|
2018-04-18 06:29:40 -04:00
|
|
|
import ActivityBar from '~/ide/components/activity_bar.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { leftSidebarViews } from '~/ide/constants';
|
|
|
|
import { createStore } from '~/ide/stores';
|
2018-04-18 06:29:40 -04:00
|
|
|
|
|
|
|
describe('IDE activity bar', () => {
|
|
|
|
const Component = Vue.extend(ActivityBar);
|
|
|
|
let vm;
|
2020-07-21 05:09:34 -04:00
|
|
|
let store;
|
2018-04-18 06:29:40 -04:00
|
|
|
|
2021-01-21 01:09:03 -05:00
|
|
|
const findChangesBadge = () => vm.$el.querySelector('.badge');
|
|
|
|
|
2018-04-18 06:29:40 -04:00
|
|
|
beforeEach(() => {
|
2020-07-21 05:09:34 -04:00
|
|
|
store = createStore();
|
|
|
|
|
2018-04-18 06:29:40 -04:00
|
|
|
Vue.set(store.state.projects, 'abcproject', {
|
|
|
|
web_url: 'testing',
|
|
|
|
});
|
|
|
|
Vue.set(store.state, 'currentProjectId', 'abcproject');
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateActivityBarView', () => {
|
|
|
|
beforeEach(() => {
|
2020-04-28 17:09:35 -04:00
|
|
|
jest.spyOn(vm, 'updateActivityBarView').mockImplementation(() => {});
|
2018-04-18 06:29:40 -04:00
|
|
|
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with edit value on click', () => {
|
|
|
|
vm.$el.querySelector('.js-ide-edit-mode').click();
|
|
|
|
|
2020-02-18 01:09:06 -05:00
|
|
|
expect(vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.edit.name);
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with commit value on click', () => {
|
|
|
|
vm.$el.querySelector('.js-ide-commit-mode').click();
|
|
|
|
|
2020-02-18 01:09:06 -05:00
|
|
|
expect(vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.commit.name);
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|
2018-04-26 07:02:26 -04:00
|
|
|
|
|
|
|
it('calls updateActivityBarView with review value on click', () => {
|
|
|
|
vm.$el.querySelector('.js-ide-review-mode').click();
|
|
|
|
|
2020-02-18 01:09:06 -05:00
|
|
|
expect(vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.review.name);
|
2018-04-26 07:02:26 -04:00
|
|
|
});
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('active item', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets edit item active', () => {
|
|
|
|
expect(vm.$el.querySelector('.js-ide-edit-mode').classList).toContain('active');
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('sets commit item active', (done) => {
|
2020-02-18 01:09:06 -05:00
|
|
|
vm.$store.state.currentActivityView = leftSidebarViews.commit.name;
|
2018-04-18 06:29:40 -04:00
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.js-ide-commit-mode').classList).toContain('active');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-21 01:09:03 -05:00
|
|
|
|
|
|
|
describe('changes badge', () => {
|
|
|
|
it('is rendered when files are staged', () => {
|
|
|
|
store.state.stagedFiles = [{ path: '/path/to/file' }];
|
|
|
|
vm.$mount();
|
|
|
|
|
|
|
|
expect(findChangesBadge()).toBeTruthy();
|
|
|
|
expect(findChangesBadge().textContent.trim()).toBe('1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not rendered when no changes are present', () => {
|
|
|
|
vm.$mount();
|
|
|
|
expect(findChangesBadge()).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|