-
Notifications
You must be signed in to change notification settings - Fork 4
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
3 changed files
with
139 additions
and
1 deletion.
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
101 changes: 101 additions & 0 deletions
101
test/unit/specs/components/inputs/EntitiesInput/EntitiesInput.spec.js
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,101 @@ | ||
import { shallowMount, createLocalVue } from '@vue/test-utils'; | ||
import BH from 'bh'; | ||
|
||
import EntitiesInput from '@/components/inputs/EntitiesInput'; | ||
|
||
|
||
const localVue = createLocalVue(); | ||
localVue.use(BH); | ||
|
||
describe('NewExampleForm.vue', () => { | ||
let wrapper; | ||
beforeEach(() => { | ||
wrapper = shallowMount(EntitiesInput, { | ||
localVue, | ||
propsData: { | ||
repository: {}, | ||
text: 'my name is douglas', | ||
}, | ||
}); | ||
}); | ||
|
||
test('renders correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
describe('newEntity emit new event', () => { | ||
let newEntity; | ||
const entity = { | ||
start: 11, | ||
end: 18, | ||
entity: 'name', | ||
}; | ||
|
||
beforeEach(() => { | ||
newEntity = wrapper.find({ ref: 'newEntity' }); | ||
newEntity.vm.$emit('new', entity); | ||
}); | ||
|
||
test('renders correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('new event emitted by newEntity', () => { | ||
expect(newEntity.emitted('new')).toBeDefined(); | ||
}); | ||
|
||
test('entity added to entities', () => { | ||
expect(wrapper.vm.entities).toHaveLength(1); | ||
}); | ||
|
||
test('input event emitted', () => { | ||
expect(wrapper.emitted('input')).toBeDefined(); | ||
}); | ||
|
||
describe('change text to "the name is douglas"', () => { | ||
beforeEach(() => { | ||
wrapper.setProps({ text: 'the name is douglas' }); | ||
}); | ||
|
||
test('update entity position', () => { | ||
const e = wrapper.vm.entities[0]; | ||
expect(e.start).toBe(12); | ||
expect(e.end).toBe(19); | ||
}); | ||
}); | ||
|
||
describe('change text to "my name is"', () => { | ||
beforeEach(() => { | ||
wrapper.setProps({ text: 'the name is' }); | ||
}); | ||
|
||
test('renders correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('entity deleted', () => { | ||
expect(wrapper.vm.entities).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
describe('remove entity', () => { | ||
beforeEach(() => { | ||
wrapper.vm.removeEntity(entity); | ||
}); | ||
|
||
test('entity deleted', () => { | ||
expect(wrapper.vm.entities).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
describe('edit entity', () => { | ||
beforeEach(async () => { | ||
await wrapper.vm.editEntity(entity); | ||
}); | ||
|
||
test('entity deleted', () => { | ||
expect(wrapper.vm.entities).toHaveLength(0); | ||
}); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
test/unit/specs/components/inputs/EntitiesInput/__snapshots__/EntitiesInput.spec.js.snap
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,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NewExampleForm.vue newEntity emit new event change text to "my name is" renders correctly 1`] = ` | ||
<bhinput-stub> | ||
<div class="entities-input__badges"></div> | ||
<div class="entities-input__new-entity"> | ||
<newentity-stub class="entities-input__new-entity__wrapper"></newentity-stub> | ||
</div> | ||
</bhinput-stub> | ||
`; | ||
|
||
exports[`NewExampleForm.vue newEntity emit new event renders correctly 1`] = ` | ||
<bhinput-stub> | ||
<div class="entities-input__badges"> | ||
<bhbadge-stub class="entities-input__badges__badge entity-sunflower"><span><span><strong>name</strong></span> | ||
<!----> | ||
</span> | ||
<bhdropdown-stub> | ||
<bhdropdownitem-stub>Edit</bhdropdownitem-stub> | ||
<bhdropdownitem-stub>Remove</bhdropdownitem-stub> | ||
</bhdropdown-stub> | ||
</bhbadge-stub> | ||
</div> | ||
<div class="entities-input__new-entity"> | ||
<newentity-stub class="entities-input__new-entity__wrapper"></newentity-stub> | ||
</div> | ||
</bhinput-stub> | ||
`; | ||
|
||
exports[`NewExampleForm.vue renders correctly 1`] = ` | ||
<bhinput-stub> | ||
<div class="entities-input__badges"></div> | ||
<div class="entities-input__new-entity"> | ||
<newentity-stub class="entities-input__new-entity__wrapper"></newentity-stub> | ||
</div> | ||
</bhinput-stub> | ||
`; |