-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
263 additions
and
13 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,77 @@ | ||
import Vuex from 'vuex'; | ||
import { createLocalVue, shallow } from 'vue-test-utils'; | ||
|
||
import { mapMultiRowFields, getField, updateField } from '../src'; | ||
|
||
const localVue = createLocalVue(); | ||
|
||
localVue.use(Vuex); | ||
|
||
describe(`Component initialized with multi row setup.`, () => { | ||
let Component; | ||
let store; | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
Component = { | ||
template: ` | ||
<div> | ||
<div v-for="user in users"> | ||
<input v-model="user.name"> | ||
<input v-model="user.email"> | ||
</div> | ||
</div> | ||
`, | ||
computed: { | ||
...mapMultiRowFields([`users`]), | ||
}, | ||
}; | ||
|
||
store = new Vuex.Store({ | ||
state: { | ||
users: [ | ||
{ | ||
name: `Foo`, | ||
email: `[email protected]`, | ||
}, | ||
{ | ||
name: `Bar`, | ||
email: `[email protected]`, | ||
}, | ||
], | ||
}, | ||
getters: { | ||
getField, | ||
}, | ||
mutations: { | ||
updateField, | ||
}, | ||
}); | ||
|
||
wrapper = shallow(Component, { localVue, store }); | ||
}); | ||
|
||
test(`It should render the component.`, () => { | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
test(`It should update field values when the store is updated.`, () => { | ||
store.state.users[0].name = `New Name`; | ||
store.state.users[1].email = `[email protected]`; | ||
wrapper.update(); | ||
|
||
expect(wrapper.find(`input`).element.value).toBe(`New Name`); | ||
expect(wrapper.find(`div:nth-child(2) input:nth-child(2)`).element.value).toBe(`[email protected]`); | ||
}); | ||
|
||
test(`It should update the store when the field values are updated.`, () => { | ||
wrapper.find(`input`).element.value = `New Name`; | ||
wrapper.find(`input`).trigger(`input`); | ||
|
||
wrapper.find(`div:nth-child(2) input:nth-child(2)`).element.value = `[email protected]`; | ||
wrapper.find(`div:nth-child(2) input:nth-child(2)`).trigger(`input`); | ||
|
||
expect(store.state.users[0].name).toBe(`New Name`); | ||
expect(store.state.users[1].email).toBe(`[email protected]`); | ||
}); | ||
}); |