2018-04-18 06:29:40 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import store from '~/ide/stores';
|
2018-04-26 09:06:35 -04:00
|
|
|
import { activityBarViews } from '~/ide/constants';
|
2018-04-18 06:29:40 -04:00
|
|
|
import ActivityBar from '~/ide/components/activity_bar.vue';
|
|
|
|
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
|
|
|
|
import { resetStore } from '../helpers';
|
|
|
|
|
|
|
|
describe('IDE activity bar', () => {
|
|
|
|
const Component = Vue.extend(ActivityBar);
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.set(store.state.projects, 'abcproject', {
|
|
|
|
web_url: 'testing',
|
|
|
|
});
|
|
|
|
Vue.set(store.state, 'currentProjectId', 'abcproject');
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
|
|
|
|
resetStore(vm.$store);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('goBackUrl', () => {
|
|
|
|
it('renders the Go Back link with the referrer when present', () => {
|
|
|
|
const fakeReferrer = '/example/README.md';
|
|
|
|
spyOnProperty(document, 'referrer').and.returnValue(fakeReferrer);
|
|
|
|
|
|
|
|
vm.$mount();
|
|
|
|
|
|
|
|
expect(vm.goBackUrl).toEqual(fakeReferrer);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the Go Back link with the project url when referrer is not present', () => {
|
|
|
|
const fakeReferrer = '';
|
|
|
|
spyOnProperty(document, 'referrer').and.returnValue(fakeReferrer);
|
|
|
|
|
|
|
|
vm.$mount();
|
|
|
|
|
|
|
|
expect(vm.goBackUrl).toEqual('testing');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateActivityBarView', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(vm, 'updateActivityBarView');
|
|
|
|
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with edit value on click', () => {
|
|
|
|
vm.$el.querySelector('.js-ide-edit-mode').click();
|
|
|
|
|
2018-04-26 09:06:35 -04:00
|
|
|
expect(vm.updateActivityBarView).toHaveBeenCalledWith(activityBarViews.edit);
|
2018-04-18 06:29:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('calls updateActivityBarView with commit value on click', () => {
|
|
|
|
vm.$el.querySelector('.js-ide-commit-mode').click();
|
|
|
|
|
2018-04-26 09:06:35 -04:00
|
|
|
expect(vm.updateActivityBarView).toHaveBeenCalledWith(activityBarViews.commit);
|
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();
|
|
|
|
|
2018-04-30 04:43:23 -04:00
|
|
|
expect(vm.updateActivityBarView).toHaveBeenCalledWith(activityBarViews.review);
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets commit item active', done => {
|
2018-04-26 09:06:35 -04:00
|
|
|
vm.$store.state.currentActivityView = activityBarViews.commit;
|
2018-04-18 06:29:40 -04:00
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.js-ide-commit-mode').classList).toContain('active');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|