feat: Articles store integration (#5133)
This commit is contained in:
@@ -15,10 +15,22 @@ jest.mock('axios');
|
||||
describe('#actions', () => {
|
||||
describe('#index', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({ data: articleList });
|
||||
await actions.index({ commit });
|
||||
axios.get.mockResolvedValue({
|
||||
data: {
|
||||
payload: articleList,
|
||||
meta: {
|
||||
current_page: '1',
|
||||
articles_count: 5,
|
||||
},
|
||||
},
|
||||
});
|
||||
await actions.index(
|
||||
{ commit },
|
||||
{ pageNumber: 1, portalSlug: 'test', locale: 'en' }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_UI_FLAG, { isFetching: true }],
|
||||
[types.default.CLEAR_ARTICLES],
|
||||
[
|
||||
types.default.ADD_MANY_ARTICLES,
|
||||
[
|
||||
@@ -29,13 +41,22 @@ describe('#actions', () => {
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
types.default.SET_ARTICLES_META,
|
||||
{ current_page: '1', articles_count: 5 },
|
||||
],
|
||||
[types.default.ADD_MANY_ARTICLES_ID, [1]],
|
||||
[types.default.SET_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.index({ commit })).rejects.toThrow(Error);
|
||||
await expect(
|
||||
actions.index(
|
||||
{ commit },
|
||||
{ pageNumber: 1, portalSlug: 'test', locale: 'en' }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_UI_FLAG, { isFetching: true }],
|
||||
[types.default.SET_UI_FLAG, { isFetching: false }],
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
export default {
|
||||
meta: {
|
||||
count: 123,
|
||||
currentPage: 2,
|
||||
},
|
||||
articles: {
|
||||
byId: {
|
||||
1: {
|
||||
|
||||
@@ -5,8 +5,8 @@ describe('#getters', () => {
|
||||
beforeEach(() => {
|
||||
state = articles;
|
||||
});
|
||||
it('uiFlagsIn', () => {
|
||||
expect(getters.uiFlagsIn(state)(1)).toEqual({
|
||||
it('uiFlags', () => {
|
||||
expect(getters.uiFlags(state)(1)).toEqual({
|
||||
isFetching: false,
|
||||
isUpdating: true,
|
||||
isDeleting: false,
|
||||
@@ -34,7 +34,7 @@ describe('#getters', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('isFetchingHelpCenters', () => {
|
||||
expect(getters.isFetchingHelpCenterArticles(state)).toEqual(true);
|
||||
it('isFetchingArticles', () => {
|
||||
expect(getters.isFetching(state)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,6 +46,19 @@ describe('#mutations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ARTICLES_META', () => {
|
||||
it('add meta to state', () => {
|
||||
mutations[types.SET_ARTICLES_META](state, {
|
||||
articles_count: 3,
|
||||
current_page: 1,
|
||||
});
|
||||
expect(state.meta).toEqual({
|
||||
count: 3,
|
||||
currentPage: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_ARTICLE_ID', () => {
|
||||
it('add valid article id to state', () => {
|
||||
mutations[types.ADD_ARTICLE_ID](state, 3);
|
||||
@@ -87,4 +100,13 @@ describe('#mutations', () => {
|
||||
expect(state.articles.byId[2]).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#CLEAR_ARTICLES', () => {
|
||||
it('clears articles', () => {
|
||||
mutations[types.CLEAR_ARTICLES](state);
|
||||
expect(state.articles.allIds).toEqual([]);
|
||||
expect(state.articles.byId).toEqual({});
|
||||
expect(state.articles.uiFlags).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user