diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-25 03:08:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-25 03:08:34 +0300 |
commit | 1e6730a4e32f6cbf4b84aa9fc13204778783f33c (patch) | |
tree | 6dd6c9ed98ec836432cf431397a4ef45dd78deb8 /spec/frontend/frequent_items | |
parent | 95a48f11db963bc55ab918e3eb24f8576dca4a81 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/frequent_items')
-rw-r--r-- | spec/frontend/frequent_items/utils_spec.js | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/spec/frontend/frequent_items/utils_spec.js b/spec/frontend/frequent_items/utils_spec.js index a7ab18b0d10..8c3841558f4 100644 --- a/spec/frontend/frequent_items/utils_spec.js +++ b/spec/frontend/frequent_items/utils_spec.js @@ -66,35 +66,36 @@ describe('Frequent Items utils spec', () => { }); describe('updateExistingFrequentItem', () => { - let mockedProject; - - beforeEach(() => { - mockedProject = { - ...mockProject, - frequency: 1, - lastAccessedOn: 1497979281815, - }; + const LAST_ACCESSED = 1497979281815; + const WITHIN_AN_HOUR = LAST_ACCESSED + HOUR_IN_MS; + const OVER_AN_HOUR = WITHIN_AN_HOUR + 1; + const EXISTING_ITEM = Object.freeze({ + ...mockProject, + frequency: 1, + lastAccessedOn: 1497979281815, }); - it('updates item if accessed over an hour ago', () => { - const newTimestamp = Date.now() + HOUR_IN_MS + 1; + it.each` + desc | existingProps | newProps | expected + ${'updates item if accessed over an hour ago'} | ${{}} | ${{ lastAccessedOn: OVER_AN_HOUR }} | ${{ lastAccessedOn: Date.now(), frequency: 2 }} + ${'does not update is accessed with an hour'} | ${{}} | ${{ lastAccessedOn: WITHIN_AN_HOUR }} | ${{ lastAccessedOn: EXISTING_ITEM.lastAccessedOn, frequency: 1 }} + ${'updates if lastAccessedOn not found'} | ${{ lastAccessedOn: undefined }} | ${{ lastAccessedOn: WITHIN_AN_HOUR }} | ${{ lastAccessedOn: Date.now(), frequency: 2 }} + `('$desc', ({ existingProps, newProps, expected }) => { const newItem = { - ...mockedProject, - lastAccessedOn: newTimestamp, + ...EXISTING_ITEM, + ...newProps, }; - const result = updateExistingFrequentItem(mockedProject, newItem); - - expect(result.frequency).toBe(mockedProject.frequency + 1); - }); - - it('does not update item if accessed within the hour', () => { - const newItem = { - ...mockedProject, - lastAccessedOn: mockedProject.lastAccessedOn + HOUR_IN_MS, + const existingItem = { + ...EXISTING_ITEM, + ...existingProps, }; - const result = updateExistingFrequentItem(mockedProject, newItem); - expect(result.frequency).toBe(mockedProject.frequency); + const result = updateExistingFrequentItem(existingItem, newItem); + + expect(result).toEqual({ + ...newItem, + ...expected, + }); }); }); |