Commit c0b28915 authored by Phil Hughes's avatar Phil Hughes

Merge branch '345987-rememoize-inline-coverage-when-finished-loading' into 'master'

Recache coverage data when it's fully loaded

See merge request gitlab-org/gitlab!76808
parents 3552280a 810cf932
...@@ -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) {
......
...@@ -277,3 +277,36 @@ describe('DiffRow', () => { ...@@ -277,3 +277,36 @@ describe('DiffRow', () => {
}); });
}); });
}); });
describe('coverage state memoization', () => {
it('updates when coverage is loaded', () => {
const lineWithoutCoverage = {};
const lineWithCoverage = {
text: 'Test coverage: 5 hits',
class: 'coverage',
};
const unchangedProps = {
inline: true,
filePath: 'file/path',
line: { left: { new_line: 3 } },
};
const noCoverageProps = {
fileLineCoverage: () => lineWithoutCoverage,
coverageLoaded: false,
...unchangedProps,
};
const coverageProps = {
fileLineCoverage: () => lineWithCoverage,
coverageLoaded: true,
...unchangedProps,
};
// this caches no coverage for the line
expect(DiffRow.coverageStateLeft(noCoverageProps)).toStrictEqual(lineWithoutCoverage);
// this retrieves coverage for the line because it has been recached
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