Commit fc4b64a2 authored by Thomas Randolph's avatar Thomas Randolph

Add a mutation for setting the viewed status of a file

This viewed status is specifically used in the file tree
parent 97ee889c
......@@ -21,6 +21,7 @@ export const REMOVE_LINE_DISCUSSIONS_FOR_FILE = 'REMOVE_LINE_DISCUSSIONS_FOR_FIL
export const TOGGLE_FOLDER_OPEN = 'TOGGLE_FOLDER_OPEN';
export const SET_SHOW_TREE_LIST = 'SET_SHOW_TREE_LIST';
export const VIEW_DIFF_FILE = 'VIEW_DIFF_FILE';
export const SET_DIFF_FILE_VIEWED = 'SET_DIFF_FILE_VIEWED';
export const OPEN_DIFF_FILE_COMMENT_FORM = 'OPEN_DIFF_FILE_COMMENT_FORM';
export const UPDATE_DIFF_FILE_COMMENT_FORM = 'UPDATE_DIFF_FILE_COMMENT_FORM';
......
......@@ -258,6 +258,9 @@ export default {
state.currentDiffFileId = fileId;
Vue.set(state.viewedDiffFileIds, fileId, true);
},
[types.SET_DIFF_FILE_VIEWED](state, { id, seen }) {
Vue.set(state.viewedDiffFileIds, id, seen);
},
[types.OPEN_DIFF_FILE_COMMENT_FORM](state, formData) {
state.commentForms.push({
...formData,
......
......@@ -643,6 +643,26 @@ describe('DiffsStoreMutations', () => {
});
});
describe('SET_DIFF_FILE_VIEWED', () => {
let state;
beforeEach(() => {
state = {
viewedDiffFileIds: { 123: true },
};
});
it.each`
id | bool | outcome
${'abc'} | ${true} | ${{ 123: true, abc: true }}
${'123'} | ${false} | ${{ 123: false }}
`('sets the viewed files list to $bool for the id $id', ({ id, bool, outcome }) => {
mutations[types.SET_DIFF_FILE_VIEWED](state, { id, seen: bool });
expect(state.viewedDiffFileIds).toEqual(outcome);
});
});
describe('Set highlighted row', () => {
it('sets highlighted row', () => {
const state = createState();
......
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