2017-05-05 14:23:31 -04:00
|
|
|
import SidebarStore from '~/sidebar/stores/sidebar_store';
|
|
|
|
import Mock from './mock_data';
|
2017-05-05 15:45:14 -04:00
|
|
|
import UsersMockHelper from '../helpers/user_mock_data_helper';
|
2017-05-05 14:23:31 -04:00
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
const ASSIGNEE = {
|
|
|
|
id: 2,
|
|
|
|
name: 'gitlab user 2',
|
|
|
|
username: 'gitlab2',
|
2018-01-24 04:11:30 -05:00
|
|
|
avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
|
2017-10-31 12:15:03 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const ANOTHER_ASSINEE = {
|
|
|
|
id: 3,
|
|
|
|
name: 'gitlab user 3',
|
|
|
|
username: 'gitlab3',
|
2018-01-24 04:11:30 -05:00
|
|
|
avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
|
2017-10-31 12:15:03 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const PARTICIPANT = {
|
|
|
|
id: 1,
|
|
|
|
state: 'active',
|
|
|
|
username: 'marcene',
|
|
|
|
name: 'Allie Will',
|
|
|
|
web_url: 'foo.com',
|
|
|
|
avatar_url: 'gravatar.com/avatar/xxx',
|
|
|
|
};
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
const PARTICIPANT_LIST = [PARTICIPANT, { ...PARTICIPANT, id: 2 }, { ...PARTICIPANT, id: 3 }];
|
2017-05-05 14:23:31 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('Sidebar store', function() {
|
2017-05-05 14:23:31 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
this.store = new SidebarStore({
|
|
|
|
currentUser: {
|
|
|
|
id: 1,
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
2018-10-17 03:13:26 -04:00
|
|
|
avatar_url:
|
|
|
|
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
|
2017-05-05 14:23:31 -04:00
|
|
|
},
|
|
|
|
editable: true,
|
|
|
|
rootPath: '/',
|
|
|
|
endpoint: '/gitlab-org/gitlab-shell/issues/5.json',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
SidebarStore.singleton = null;
|
|
|
|
});
|
|
|
|
|
2017-05-17 05:50:40 -04:00
|
|
|
it('has default isFetching values', () => {
|
|
|
|
expect(this.store.isFetching.assignees).toBe(true);
|
|
|
|
});
|
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
it('adds a new assignee', () => {
|
2017-10-31 12:15:03 -04:00
|
|
|
this.store.addAssignee(ASSIGNEE);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(this.store.assignees.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes an assignee', () => {
|
2017-10-31 12:15:03 -04:00
|
|
|
this.store.removeAssignee(ASSIGNEE);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(this.store.assignees.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds an existent assignee', () => {
|
|
|
|
let foundAssignee;
|
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
this.store.addAssignee(ASSIGNEE);
|
|
|
|
foundAssignee = this.store.findAssignee(ASSIGNEE);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(foundAssignee).toBeDefined();
|
2017-10-31 12:15:03 -04:00
|
|
|
expect(foundAssignee).toEqual(ASSIGNEE);
|
|
|
|
foundAssignee = this.store.findAssignee(ANOTHER_ASSINEE);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(foundAssignee).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all assignees', () => {
|
|
|
|
this.store.removeAllAssignees();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(this.store.assignees.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
it('sets participants data', () => {
|
|
|
|
expect(this.store.participants.length).toEqual(0);
|
|
|
|
|
|
|
|
this.store.setParticipantsData({
|
|
|
|
participants: PARTICIPANT_LIST,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(this.store.isFetching.participants).toEqual(false);
|
|
|
|
expect(this.store.participants.length).toEqual(PARTICIPANT_LIST.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets subcriptions data', () => {
|
|
|
|
expect(this.store.subscribed).toEqual(null);
|
|
|
|
|
|
|
|
this.store.setSubscriptionsData({
|
|
|
|
subscribed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(this.store.isFetching.subscriptions).toEqual(false);
|
|
|
|
expect(this.store.subscribed).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
it('set assigned data', () => {
|
|
|
|
const users = {
|
|
|
|
assignees: UsersMockHelper.createNumberRandomUsers(3),
|
|
|
|
};
|
|
|
|
|
|
|
|
this.store.setAssigneeData(users);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-17 05:50:40 -04:00
|
|
|
expect(this.store.isFetching.assignees).toBe(false);
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(this.store.assignees.length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
it('sets fetching state', () => {
|
|
|
|
expect(this.store.isFetching.participants).toEqual(true);
|
|
|
|
|
|
|
|
this.store.setFetchingState('participants', false);
|
|
|
|
|
|
|
|
expect(this.store.isFetching.participants).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 21:43:10 -05:00
|
|
|
it('sets loading state', () => {
|
|
|
|
this.store.setLoadingState('assignees', true);
|
|
|
|
|
|
|
|
expect(this.store.isLoading.assignees).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
it('set time tracking data', () => {
|
|
|
|
this.store.setTimeTrackingData(Mock.time);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-05-05 14:23:31 -04:00
|
|
|
expect(this.store.timeEstimate).toEqual(Mock.time.time_estimate);
|
|
|
|
expect(this.store.totalTimeSpent).toEqual(Mock.time.total_time_spent);
|
|
|
|
expect(this.store.humanTimeEstimate).toEqual(Mock.time.human_time_estimate);
|
|
|
|
expect(this.store.humanTotalTimeSpent).toEqual(Mock.time.human_total_time_spent);
|
|
|
|
});
|
2017-08-14 03:26:19 -04:00
|
|
|
|
|
|
|
it('set autocomplete projects', () => {
|
|
|
|
const projects = [{ id: 0 }];
|
|
|
|
this.store.setAutocompleteProjects(projects);
|
|
|
|
|
|
|
|
expect(this.store.autocompleteProjects).toEqual(projects);
|
|
|
|
});
|
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
it('sets subscribed state', () => {
|
|
|
|
expect(this.store.subscribed).toEqual(null);
|
|
|
|
|
|
|
|
this.store.setSubscribedState(true);
|
|
|
|
|
|
|
|
expect(this.store.subscribed).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
it('set move to project ID', () => {
|
|
|
|
const projectId = 7;
|
|
|
|
this.store.setMoveToProjectId(projectId);
|
|
|
|
|
|
|
|
expect(this.store.moveToProjectId).toEqual(projectId);
|
|
|
|
});
|
2017-05-05 14:23:31 -04:00
|
|
|
});
|