Commit 706f11df authored by Phil Hughes's avatar Phil Hughes

Merge branch 'refactor-notes-actions' into 'master'

Use Poll-based axios request even on one-shot request in note actions.js

See merge request gitlab-org/gitlab!59656
parents 1e2fbc86 dc073f0e
......@@ -468,15 +468,6 @@ const getFetchDataParams = (state) => {
return { endpoint, options };
};
export const fetchData = ({ commit, state, getters, dispatch }) => {
const { endpoint, options } = getFetchDataParams(state);
axios
.get(endpoint, options)
.then(({ data }) => pollSuccessCallBack(data, commit, state, getters, dispatch))
.catch(() => Flash(__('Something went wrong while fetching latest comments.')));
};
export const poll = ({ commit, state, getters, dispatch }) => {
eTagPoll = new Poll({
resource: {
......@@ -493,7 +484,7 @@ export const poll = ({ commit, state, getters, dispatch }) => {
if (!Visibility.hidden()) {
eTagPoll.makeDelayedRequest(2500);
} else {
dispatch('fetchData');
eTagPoll.makeRequest();
}
Visibility.change(() => {
......
......@@ -253,85 +253,6 @@ describe('Actions Notes Store', () => {
});
});
describe('fetchData', () => {
describe('given there are no notes', () => {
const lastFetchedAt = '13579';
beforeEach(() => {
axiosMock
.onGet(notesDataMock.notesPath)
.replyOnce(200, { notes: [], last_fetched_at: lastFetchedAt });
});
it('should commit SET_LAST_FETCHED_AT', () =>
testAction(
actions.fetchData,
undefined,
{ notesData: notesDataMock },
[{ type: 'SET_LAST_FETCHED_AT', payload: lastFetchedAt }],
[],
));
});
describe('given there are notes', () => {
const lastFetchedAt = '12358';
beforeEach(() => {
axiosMock
.onGet(notesDataMock.notesPath)
.replyOnce(200, { notes: discussionMock.notes, last_fetched_at: lastFetchedAt });
});
it('should dispatch updateOrCreateNotes, startTaskList and commit SET_LAST_FETCHED_AT', () =>
testAction(
actions.fetchData,
undefined,
{ notesData: notesDataMock },
[{ type: 'SET_LAST_FETCHED_AT', payload: lastFetchedAt }],
[
{ type: 'updateOrCreateNotes', payload: discussionMock.notes },
{ type: 'startTaskList' },
{ type: 'updateResolvableDiscussionsCounts' },
],
));
});
describe('paginated notes feature flag enabled', () => {
const lastFetchedAt = '12358';
beforeEach(() => {
window.gon = { features: { paginatedNotes: true } };
axiosMock.onGet(notesDataMock.notesPath).replyOnce(200, {
notes: discussionMock.notes,
more: false,
last_fetched_at: lastFetchedAt,
});
});
afterEach(() => {
window.gon = null;
});
it('should dispatch setFetchingState, setNotesFetchedState, setLoadingState, updateOrCreateNotes, startTaskList and commit SET_LAST_FETCHED_AT', () => {
return testAction(
actions.fetchData,
null,
{ notesData: notesDataMock, isFetching: true },
[{ type: 'SET_LAST_FETCHED_AT', payload: lastFetchedAt }],
[
{ type: 'setFetchingState', payload: false },
{ type: 'setNotesFetchedState', payload: true },
{ type: 'setLoadingState', payload: false },
{ type: 'updateOrCreateNotes', payload: discussionMock.notes },
{ type: 'startTaskList' },
{ type: 'updateResolvableDiscussionsCounts' },
],
);
});
});
});
describe('poll', () => {
beforeEach((done) => {
axiosMock
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment