2018-03-27 19:54:05 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import _ from 'underscore';
|
|
|
|
import { headersInterceptor } from 'spec/helpers/vue_resource_helper';
|
2018-03-17 18:26:18 +05:30
|
|
|
import * as actions from '~/notes/stores/actions';
|
2018-03-27 19:54:05 +05:30
|
|
|
import store from '~/notes/stores';
|
2018-03-17 18:26:18 +05:30
|
|
|
import testAction from '../../helpers/vuex_action_helper';
|
2018-03-27 19:54:05 +05:30
|
|
|
import { resetStore } from '../helpers';
|
2018-05-09 12:01:36 +05:30
|
|
|
import {
|
|
|
|
discussionMock,
|
|
|
|
notesDataMock,
|
|
|
|
userDataMock,
|
|
|
|
noteableDataMock,
|
|
|
|
individualNote,
|
|
|
|
} from '../mock_data';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('Actions Notes Store', () => {
|
2018-03-27 19:54:05 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetStore(store);
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('setNotesData', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set received notes data', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setNotesData,
|
|
|
|
notesDataMock,
|
|
|
|
{ notesData: {} },
|
|
|
|
[{ type: 'SET_NOTES_DATA', payload: notesDataMock }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setNoteableData', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set received issue data', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setNoteableData,
|
|
|
|
noteableDataMock,
|
|
|
|
{ noteableData: {} },
|
|
|
|
[{ type: 'SET_NOTEABLE_DATA', payload: noteableDataMock }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setUserData', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set received user data', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setUserData,
|
|
|
|
userDataMock,
|
|
|
|
{ userData: {} },
|
|
|
|
[{ type: 'SET_USER_DATA', payload: userDataMock }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setLastFetchedAt', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set received timestamp', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setLastFetchedAt,
|
|
|
|
'timestamp',
|
|
|
|
{ lastFetchedAt: {} },
|
|
|
|
[{ type: 'SET_LAST_FETCHED_AT', payload: 'timestamp' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setInitialNotes', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set initial notes', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setInitialNotes,
|
|
|
|
[individualNote],
|
|
|
|
{ notes: [] },
|
|
|
|
[{ type: 'SET_INITIAL_NOTES', payload: [individualNote] }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setTargetNoteHash', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set target note hash', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setTargetNoteHash,
|
|
|
|
'hash',
|
|
|
|
{ notes: [] },
|
|
|
|
[{ type: 'SET_TARGET_NOTE_HASH', payload: 'hash' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleDiscussion', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should toggle discussion', done => {
|
|
|
|
testAction(
|
|
|
|
actions.toggleDiscussion,
|
|
|
|
{ discussionId: discussionMock.id },
|
|
|
|
{ notes: [discussionMock] },
|
|
|
|
[{ type: 'TOGGLE_DISCUSSION', payload: { discussionId: discussionMock.id } }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
describe('async methods', () => {
|
|
|
|
const interceptor = (request, next) => {
|
2018-05-09 12:01:36 +05:30
|
|
|
next(
|
|
|
|
request.respondWith(JSON.stringify({}), {
|
|
|
|
status: 200,
|
|
|
|
}),
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Vue.http.interceptors.push(interceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('closeIssue', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('sets state as closed', done => {
|
|
|
|
store
|
|
|
|
.dispatch('closeIssue', { notesData: { closeIssuePath: '' } })
|
2018-03-27 19:54:05 +05:30
|
|
|
.then(() => {
|
|
|
|
expect(store.state.noteableData.state).toEqual('closed');
|
|
|
|
expect(store.state.isToggleStateButtonLoading).toEqual(false);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('reopenIssue', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('sets state as reopened', done => {
|
|
|
|
store
|
|
|
|
.dispatch('reopenIssue', { notesData: { reopenIssuePath: '' } })
|
2018-03-27 19:54:05 +05:30
|
|
|
.then(() => {
|
|
|
|
expect(store.state.noteableData.state).toEqual('reopened');
|
|
|
|
expect(store.state.isToggleStateButtonLoading).toEqual(false);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('emitStateChangedEvent', () => {
|
|
|
|
it('emits an event on the document', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
document.addEventListener('issuable_vue_app:change', event => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(event.detail.data).toEqual({ id: '1', state: 'closed' });
|
|
|
|
expect(event.detail.isClosed).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
store.dispatch('emitStateChangedEvent', { id: '1', state: 'closed' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleStateButtonLoading', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set loading as true', done => {
|
|
|
|
testAction(
|
|
|
|
actions.toggleStateButtonLoading,
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
[{ type: 'TOGGLE_STATE_BUTTON_LOADING', payload: true }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should set loading as false', done => {
|
|
|
|
testAction(
|
|
|
|
actions.toggleStateButtonLoading,
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
[{ type: 'TOGGLE_STATE_BUTTON_LOADING', payload: false }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleIssueLocalState', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('sets issue state as closed', done => {
|
|
|
|
testAction(actions.toggleIssueLocalState, 'closed', {}, [{ type: 'CLOSE_ISSUE' }], [], done);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('sets issue state as reopened', done => {
|
|
|
|
testAction(actions.toggleIssueLocalState, 'reopened', {}, [{ type: 'REOPEN_ISSUE' }], [], done);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('poll', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
beforeEach(done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
jasmine.clock().install();
|
|
|
|
|
|
|
|
spyOn(Vue.http, 'get').and.callThrough();
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
store
|
|
|
|
.dispatch('setNotesData', notesDataMock)
|
2018-03-27 19:54:05 +05:30
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jasmine.clock().uninstall();
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('calls service with last fetched state', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const interceptor = (request, next) => {
|
2018-05-09 12:01:36 +05:30
|
|
|
next(
|
|
|
|
request.respondWith(
|
|
|
|
JSON.stringify({
|
|
|
|
notes: [],
|
|
|
|
last_fetched_at: '123456',
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'poll-interval': '1000',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
Vue.http.interceptors.push(interceptor);
|
|
|
|
Vue.http.interceptors.push(headersInterceptor);
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
store
|
|
|
|
.dispatch('poll')
|
2018-03-27 19:54:05 +05:30
|
|
|
.then(() => new Promise(resolve => requestAnimationFrame(resolve)))
|
|
|
|
.then(() => {
|
|
|
|
expect(Vue.http.get).toHaveBeenCalledWith(jasmine.anything(), {
|
|
|
|
url: jasmine.anything(),
|
|
|
|
method: 'get',
|
|
|
|
headers: {
|
|
|
|
'X-Last-Fetched-At': undefined,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(store.state.lastFetchedAt).toBe('123456');
|
|
|
|
|
|
|
|
jasmine.clock().tick(1500);
|
|
|
|
})
|
2018-05-09 12:01:36 +05:30
|
|
|
.then(
|
|
|
|
() =>
|
|
|
|
new Promise(resolve => {
|
|
|
|
requestAnimationFrame(resolve);
|
|
|
|
}),
|
|
|
|
)
|
2018-03-27 19:54:05 +05:30
|
|
|
.then(() => {
|
|
|
|
expect(Vue.http.get.calls.count()).toBe(2);
|
|
|
|
expect(Vue.http.get.calls.mostRecent().args[1].headers).toEqual({
|
|
|
|
'X-Last-Fetched-At': '123456',
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(() => store.dispatch('stopPolling'))
|
|
|
|
.then(() => {
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, headersInterceptor);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|