Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjae-lee committed Apr 20, 2021
1 parent db7c593 commit cfe0e4c
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/__tests__/HierarchicalMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ it('exposes send-event method for insights middleware', () => {
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Click</button>
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
Expand Down
23 changes: 22 additions & 1 deletion src/components/__tests__/Hits.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ it('exposes insights prop to the default slot', () => {
default: `
<ul slot-scope="{ items, insights }">
<li v-for="(item, itemIndex) in items" >
<button :id="'add-to-cart-' + item.objectID" @click="insights('clickedObjectIDsAfterSearch', {eventName: 'Add to cart', objectIDs: [item.objectID]})">
Add to cart
</button>
Expand Down Expand Up @@ -100,3 +100,24 @@ it('exposes insights prop to the item slot', () => {
objectIDs: ['two'],
});
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(Hits, {
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});
21 changes: 21 additions & 0 deletions src/components/__tests__/InfiniteHits.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,24 @@ it('exposes insights prop to the item slot', () => {
objectIDs: ['00002'],
});
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(InfiniteHits, {
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});
22 changes: 22 additions & 0 deletions src/components/__tests__/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@ it('calls the Panel mixin with `canRefine`', () => {
expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(Menu, {
propsData: defaultProps,
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});

describe('custom default render', () => {
const defaultScopedSlot = `
<div
Expand Down
22 changes: 22 additions & 0 deletions src/components/__tests__/MenuSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ it('calls the Panel mixin with `canRefine`', () => {
expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(MenuSelect, {
propsData: defaultProps,
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});

describe('custom item slot', () => {
// can not be <template>
// https://github.com/vuejs/vue-test-utils/pull/507
Expand Down
22 changes: 22 additions & 0 deletions src/components/__tests__/NumericMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ it('calls the Panel mixin with `hasNoResults`', () => {
expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(NumericMenu, {
propsData: defaultProps,
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});

describe('custom default render', () => {
const defaultScopedSlot = `
<ul
Expand Down
22 changes: 22 additions & 0 deletions src/components/__tests__/RangeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,28 @@ it('calls the Panel mixin with `range`', () => {
expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(RangeInput, {
propsData: defaultProps,
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});

describe('refinement', () => {
it('uses the value of the inputs when the form is submited', () => {
const refine = jest.fn();
Expand Down
23 changes: 23 additions & 0 deletions src/components/__tests__/RatingMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,26 @@ it('calls the Panel mixin with `hasNoResults`', () => {

expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
createURL: () => '#',
items: [],
sendEvent,
});

const wrapper = mount(RatingMenu, {
propsData: defaultProps,
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});
22 changes: 22 additions & 0 deletions src/components/__tests__/RefinementList.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,25 @@ it('calls the Panel mixin with `canRefine`', () => {

expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(RefinementList, {
propsData: { attribute: 'something' },
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});
22 changes: 22 additions & 0 deletions src/components/__tests__/ToggleRefinement.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ it('calls the Panel mixin with `value.count`', () => {
expect(wrapper.vm.mapStateToCanRefine({})).toBe(false);
});

it('exposes send-event method for insights middleware', () => {
const sendEvent = jest.fn();
__setState({
...defaultState,
sendEvent,
});

const wrapper = mount(Toggle, {
propsData: defaultProps,
scopedSlots: {
default: `
<div slot-scope="{ sendEvent }">
<button @click="sendEvent()">Send Event</button>
</div>
`,
},
});

wrapper.find('button').trigger('click');
expect(sendEvent).toHaveBeenCalledTimes(1);
});

describe('custom default render', () => {
const defaultScopedSlot = `
<a
Expand Down

0 comments on commit cfe0e4c

Please sign in to comment.