Commit ec7b1214 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'jswain_whats_new_stale_content' into 'master'

Bust the cache for /whats-new

See merge request gitlab-org/gitlab!61081
parents f3761e02 db1766f5
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
}, },
mounted() { mounted() {
this.openDrawer(this.versionDigest); this.openDrawer(this.versionDigest);
this.fetchItems(); this.fetchFreshItems();
const body = document.querySelector('body'); const body = document.querySelector('body');
const namespaceId = body.getAttribute('data-namespace-id'); const namespaceId = body.getAttribute('data-namespace-id');
...@@ -42,13 +42,18 @@ export default { ...@@ -42,13 +42,18 @@ export default {
bottomReached() { bottomReached() {
const page = this.pageInfo.nextPage; const page = this.pageInfo.nextPage;
if (page) { if (page) {
this.fetchItems({ page }); this.fetchFreshItems(page);
} }
}, },
handleResize() { handleResize() {
const height = getDrawerBodyHeight(this.$refs.drawer.$el); const height = getDrawerBodyHeight(this.$refs.drawer.$el);
this.setDrawerBodyHeight(height); this.setDrawerBodyHeight(height);
}, },
fetchFreshItems(page) {
const { versionDigest } = this;
this.fetchItems({ page, versionDigest });
},
}, },
}; };
</script> </script>
......
...@@ -14,17 +14,19 @@ export default { ...@@ -14,17 +14,19 @@ export default {
localStorage.setItem(STORAGE_KEY, versionDigest); localStorage.setItem(STORAGE_KEY, versionDigest);
} }
}, },
fetchItems({ commit, state }, { page } = { page: null }) { fetchItems({ commit, state }, { page, versionDigest } = { page: null, versionDigest: null }) {
if (state.fetching) { if (state.fetching) {
return false; return false;
} }
commit(types.SET_FETCHING, true); commit(types.SET_FETCHING, true);
const v = versionDigest;
return axios return axios
.get('/-/whats_new', { .get('/-/whats_new', {
params: { params: {
page, page,
v,
}, },
}) })
.then(({ data, headers }) => { .then(({ data, headers }) => {
......
---
title: Bust the cache for /whats-new
merge_request: 61081
author:
type: fixed
...@@ -149,7 +149,10 @@ describe('App', () => { ...@@ -149,7 +149,10 @@ describe('App', () => {
wrapper.vm.$store.state.pageInfo = { nextPage: 840 }; wrapper.vm.$store.state.pageInfo = { nextPage: 840 };
emitBottomReached(); emitBottomReached();
expect(actions.fetchItems).toHaveBeenCalledWith(expect.anything(), { page: 840 }); expect(actions.fetchItems).toHaveBeenCalledWith(expect.anything(), {
page: 840,
versionDigest: 'version-digest',
});
}); });
it('when nextPage does not exist it does not call fetchItems', () => { it('when nextPage does not exist it does not call fetchItems', () => {
......
...@@ -44,16 +44,33 @@ describe('whats new actions', () => { ...@@ -44,16 +44,33 @@ describe('whats new actions', () => {
axiosMock.restore(); axiosMock.restore();
}); });
it("doesn't require arguments", () => {
axiosMock.reset();
axiosMock
.onGet('/-/whats_new', { params: { page: undefined, v: undefined } })
.replyOnce(200, [{ title: 'GitLab Stories' }]);
testAction(
actions.fetchItems,
{},
{},
expect.arrayContaining([
{ type: types.ADD_FEATURES, payload: [{ title: 'GitLab Stories' }] },
]),
);
});
it('passes arguments', () => { it('passes arguments', () => {
axiosMock.reset(); axiosMock.reset();
axiosMock axiosMock
.onGet('/-/whats_new', { params: { page: 8 } }) .onGet('/-/whats_new', { params: { page: 8, v: 42 } })
.replyOnce(200, [{ title: 'GitLab Stories' }]); .replyOnce(200, [{ title: 'GitLab Stories' }]);
testAction( testAction(
actions.fetchItems, actions.fetchItems,
{ page: 8 }, { page: 8, versionDigest: 42 },
{}, {},
expect.arrayContaining([ expect.arrayContaining([
{ type: types.ADD_FEATURES, payload: [{ title: 'GitLab Stories' }] }, { type: types.ADD_FEATURES, payload: [{ title: 'GitLab Stories' }] },
......
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