Commit 810cf932 authored by mfluharty's avatar mfluharty

Recache coverage data when it gets loaded

Add `coverageLoaded` boolean to diffs store (default to `false)
Set it to `true` when coverage data is loaded successfully
Use it as part of the cache key so that inline coverage gets updated
when we get a 200 response after a 204 response from polling
parent e012c40f
...@@ -42,6 +42,11 @@ export default { ...@@ -42,6 +42,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
coverageLoaded: {
type: Boolean,
required: false,
default: false,
},
inline: { inline: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -83,14 +88,15 @@ export default { ...@@ -83,14 +88,15 @@ export default {
if (!props.inline || !props.line.left) return {}; if (!props.inline || !props.line.left) return {};
return props.fileLineCoverage(props.filePath, props.line.left.new_line); return props.fileLineCoverage(props.filePath, props.line.left.new_line);
}, },
(props) => [props.inline, props.filePath, props.line.left?.new_line].join(':'), (props) =>
[props.inline, props.filePath, props.line.left?.new_line, props.coverageLoaded].join(':'),
), ),
coverageStateRight: memoize( coverageStateRight: memoize(
(props) => { (props) => {
if (!props.line.right) return {}; if (!props.line.right) return {};
return props.fileLineCoverage(props.filePath, props.line.right.new_line); return props.fileLineCoverage(props.filePath, props.line.right.new_line);
}, },
(props) => [props.line.right?.new_line, props.filePath].join(':'), (props) => [props.line.right?.new_line, props.filePath, props.coverageLoaded].join(':'),
), ),
showCodequalityLeft: memoize( showCodequalityLeft: memoize(
(props) => { (props) => {
......
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
}, },
computed: { computed: {
...mapGetters('diffs', ['commitId', 'fileLineCoverage']), ...mapGetters('diffs', ['commitId', 'fileLineCoverage']),
...mapState('diffs', ['codequalityDiff', 'highlightedRow']), ...mapState('diffs', ['codequalityDiff', 'highlightedRow', 'coverageLoaded']),
...mapState({ ...mapState({
selectedCommentPosition: ({ notes }) => notes.selectedCommentPosition, selectedCommentPosition: ({ notes }) => notes.selectedCommentPosition,
selectedCommentPositionHover: ({ notes }) => notes.selectedCommentPositionHover, selectedCommentPositionHover: ({ notes }) => notes.selectedCommentPositionHover,
...@@ -180,6 +180,7 @@ export default { ...@@ -180,6 +180,7 @@ export default {
:index="index" :index="index"
:is-highlighted="isHighlighted(line)" :is-highlighted="isHighlighted(line)"
:file-line-coverage="fileLineCoverage" :file-line-coverage="fileLineCoverage"
:coverage-loaded="coverageLoaded"
@showCommentForm="(code) => singleLineComment(code, line)" @showCommentForm="(code) => singleLineComment(code, line)"
@setHighlightedRow="setHighlightedRow" @setHighlightedRow="setHighlightedRow"
@toggleLineDiscussions=" @toggleLineDiscussions="
......
...@@ -21,6 +21,7 @@ export default () => ({ ...@@ -21,6 +21,7 @@ export default () => ({
startVersion: null, // Null unless a target diff is selected for comparison that is not the "base" diff startVersion: null, // Null unless a target diff is selected for comparison that is not the "base" diff
diffFiles: [], diffFiles: [],
coverageFiles: {}, coverageFiles: {},
coverageLoaded: false,
mergeRequestDiffs: [], mergeRequestDiffs: [],
mergeRequestDiff: null, mergeRequestDiff: null,
diffViewType: getViewTypeFromQueryString() || viewTypeFromCookie || defaultViewType, diffViewType: getViewTypeFromQueryString() || viewTypeFromCookie || defaultViewType,
......
...@@ -86,7 +86,7 @@ export default { ...@@ -86,7 +86,7 @@ export default {
}, },
[types.SET_COVERAGE_DATA](state, coverageFiles) { [types.SET_COVERAGE_DATA](state, coverageFiles) {
Object.assign(state, { coverageFiles }); Object.assign(state, { coverageFiles, coverageLoaded: true });
}, },
[types.RENDER_FILE](state, file) { [types.RENDER_FILE](state, file) {
......
...@@ -294,17 +294,19 @@ describe('coverage state memoization', () => { ...@@ -294,17 +294,19 @@ describe('coverage state memoization', () => {
const noCoverageProps = { const noCoverageProps = {
fileLineCoverage: () => lineWithoutCoverage, fileLineCoverage: () => lineWithoutCoverage,
coverageLoaded: false,
...unchangedProps, ...unchangedProps,
}; };
const coverageProps = { const coverageProps = {
fileLineCoverage: () => lineWithCoverage, fileLineCoverage: () => lineWithCoverage,
coverageLoaded: true,
...unchangedProps, ...unchangedProps,
}; };
// this caches no coverage for the line // this caches no coverage for the line
expect(DiffRow.coverageStateLeft(noCoverageProps)).toStrictEqual(lineWithoutCoverage); expect(DiffRow.coverageStateLeft(noCoverageProps)).toStrictEqual(lineWithoutCoverage);
// then this retrieves no coverage for the line from the cache // this retrieves coverage for the line because it has been recached
expect(DiffRow.coverageStateLeft(coverageProps)).toStrictEqual(lineWithCoverage); expect(DiffRow.coverageStateLeft(coverageProps)).toStrictEqual(lineWithCoverage);
}); });
}); });
...@@ -112,6 +112,7 @@ describe('DiffsStoreMutations', () => { ...@@ -112,6 +112,7 @@ describe('DiffsStoreMutations', () => {
mutations[types.SET_COVERAGE_DATA](state, coverage); mutations[types.SET_COVERAGE_DATA](state, coverage);
expect(state.coverageFiles).toEqual(coverage); expect(state.coverageFiles).toEqual(coverage);
expect(state.coverageLoaded).toEqual(true);
}); });
}); });
......
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