gitlab-org--gitlab-foss/spec/javascripts/sidebar/sidebar_mediator_spec.js

120 lines
4 KiB
JavaScript
Raw Normal View History

2017-12-19 05:12:32 -05:00
import _ from 'underscore';
2017-05-05 14:23:31 -04:00
import Vue from 'vue';
import SidebarMediator from '~/sidebar/sidebar_mediator';
import SidebarStore from '~/sidebar/stores/sidebar_store';
import SidebarService from '~/sidebar/services/sidebar_service';
import Mock from './mock_data';
describe('Sidebar mediator', function() {
2017-05-05 14:23:31 -04:00
beforeEach(() => {
Vue.http.interceptors.push(Mock.sidebarMockInterceptor);
this.mediator = new SidebarMediator(Mock.mediator);
});
afterEach(() => {
SidebarService.singleton = null;
SidebarStore.singleton = null;
SidebarMediator.singleton = null;
Vue.http.interceptors = _.without(Vue.http.interceptors, Mock.sidebarMockInterceptor);
2017-05-05 14:23:31 -04:00
});
it('assigns yourself ', () => {
this.mediator.assignYourself();
expect(this.mediator.store.currentUser).toEqual(Mock.mediator.currentUser);
expect(this.mediator.store.assignees[0]).toEqual(Mock.mediator.currentUser);
});
2018-10-17 03:13:26 -04:00
it('saves assignees', done => {
this.mediator
.saveAssignees('issue[assignee_ids]')
.then(resp => {
2017-05-05 15:45:14 -04:00
expect(resp.status).toEqual(200);
done();
})
.catch(done.fail);
2017-05-05 14:23:31 -04:00
});
2018-10-17 03:13:26 -04:00
it('fetches the data', done => {
const mockData =
Mock.responseMap.GET['/gitlab-org/gitlab-shell/issues/5.json?serializer=sidebar_extras'];
spyOn(this.mediator, 'processFetchedData').and.callThrough();
2018-10-17 03:13:26 -04:00
this.mediator
.fetch()
.then(() => {
expect(this.mediator.processFetchedData).toHaveBeenCalledWith(mockData);
})
.then(done)
.catch(done.fail);
});
it('processes fetched data', () => {
2018-10-17 03:13:26 -04:00
const mockData =
Mock.responseMap.GET['/gitlab-org/gitlab-shell/issues/5.json?serializer=sidebar_extras'];
this.mediator.processFetchedData(mockData);
expect(this.mediator.store.assignees).toEqual(mockData.assignees);
expect(this.mediator.store.humanTimeEstimate).toEqual(mockData.human_time_estimate);
expect(this.mediator.store.humanTotalTimeSpent).toEqual(mockData.human_total_time_spent);
expect(this.mediator.store.participants).toEqual(mockData.participants);
expect(this.mediator.store.subscribed).toEqual(mockData.subscribed);
expect(this.mediator.store.timeEstimate).toEqual(mockData.time_estimate);
expect(this.mediator.store.totalTimeSpent).toEqual(mockData.total_time_spent);
2017-05-05 14:23:31 -04:00
});
it('sets moveToProjectId', () => {
const projectId = 7;
spyOn(this.mediator.store, 'setMoveToProjectId').and.callThrough();
this.mediator.setMoveToProjectId(projectId);
expect(this.mediator.store.setMoveToProjectId).toHaveBeenCalledWith(projectId);
});
2018-10-17 03:13:26 -04:00
it('fetches autocomplete projects', done => {
const searchTerm = 'foo';
spyOn(this.mediator.service, 'getProjectsAutocomplete').and.callThrough();
spyOn(this.mediator.store, 'setAutocompleteProjects').and.callThrough();
2018-10-17 03:13:26 -04:00
this.mediator
.fetchAutocompleteProjects(searchTerm)
.then(() => {
expect(this.mediator.service.getProjectsAutocomplete).toHaveBeenCalledWith(searchTerm);
expect(this.mediator.store.setAutocompleteProjects).toHaveBeenCalled();
})
2017-10-31 12:15:03 -04:00
.then(done)
.catch(done.fail);
});
2018-10-17 03:13:26 -04:00
it('moves issue', done => {
const moveToProjectId = 7;
this.mediator.store.setMoveToProjectId(moveToProjectId);
spyOn(this.mediator.service, 'moveIssue').and.callThrough();
const visitUrl = spyOnDependency(SidebarMediator, 'visitUrl');
2018-10-17 03:13:26 -04:00
this.mediator
.moveIssue()
.then(() => {
expect(this.mediator.service.moveIssue).toHaveBeenCalledWith(moveToProjectId);
expect(visitUrl).toHaveBeenCalledWith('/root/some-project/issues/5');
})
2017-10-31 12:15:03 -04:00
.then(done)
.catch(done.fail);
});
2018-10-17 03:13:26 -04:00
it('toggle subscription', done => {
2017-10-31 12:15:03 -04:00
this.mediator.store.setSubscribedState(false);
spyOn(this.mediator.service, 'toggleSubscription').and.callThrough();
2018-10-17 03:13:26 -04:00
this.mediator
.toggleSubscription()
2017-10-31 12:15:03 -04:00
.then(() => {
expect(this.mediator.service.toggleSubscription).toHaveBeenCalled();
expect(this.mediator.store.subscribed).toEqual(true);
})
.then(done)
.catch(done.fail);
});
2017-05-05 14:23:31 -04:00
});