Skip to content

Commit

Permalink
Add EntitiesInput tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougppaz committed Aug 14, 2018
1 parent 6307243 commit 4d075ba
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/unit/specs/components/example/NewExampleForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('NewExampleForm.vue', () => {
{
start: 11,
end: 18,
entity: 'name'
entity: 'name',
},
];
});
Expand Down
101 changes: 101 additions & 0 deletions test/unit/specs/components/inputs/EntitiesInput/EntitiesInput.spec.js
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);
});
});
});
});
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>
`;

0 comments on commit 4d075ba

Please sign in to comment.