-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for UPSERT_RESOURCE and UPDATE_RESOURCE
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import mutations from '../../src/store/mutations' | ||
import { cloneDeep } from 'lodash-es' | ||
|
||
const stateFixture = { | ||
files: [ | ||
{ | ||
id: 1, | ||
name: 'test1' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'test2' | ||
}, | ||
{ | ||
id: 5, | ||
name: 'test5' | ||
} | ||
] | ||
} | ||
let stateMock = {} | ||
const resetState = () => { | ||
stateMock = cloneDeep(stateFixture) | ||
} | ||
|
||
describe('vuex store mutations', () => { | ||
describe('update resources by id', () => { | ||
beforeEach(resetState) | ||
it.each([ | ||
[mutations.UPSERT_RESOURCE.name, mutations.UPSERT_RESOURCE], | ||
[mutations.UPDATE_RESOURCE.name, mutations.UPDATE_RESOURCE] | ||
])('succeeds using mutation %s', (name, m) => { | ||
expect(stateMock.files).toEqual(stateFixture.files) | ||
expect(stateMock.files[1].name).toBe('test2') | ||
m(stateMock, { | ||
id: 2, | ||
name: 'test2-updated' | ||
}) | ||
expect(stateMock.files[1].name).toBe('test2-updated') | ||
expect(stateMock.files.length).toBe(stateFixture.files.length) | ||
}) | ||
}) | ||
describe('insert resources', () => { | ||
beforeEach(resetState) | ||
it('succeeds using mutation UPSERT_RESOURCE', () => { | ||
expect(stateMock.files).toEqual(stateFixture.files) | ||
mutations.UPSERT_RESOURCE(stateMock, { | ||
id: 3, | ||
name: 'test3-inserted' | ||
}) | ||
expect(stateMock.files).toEqual([...stateFixture.files, { id: 3, name: 'test3-inserted' }]) | ||
}) | ||
it('is ignored using mutation UPDATE_RESOURCE', () => { | ||
expect(stateMock.files).toEqual(stateFixture.files) | ||
mutations.UPDATE_RESOURCE(stateMock, { | ||
id: 3, | ||
name: 'test3-inserted' | ||
}) | ||
expect(stateMock.files).toEqual(stateFixture.files) | ||
}) | ||
}) | ||
}) |