Skip to content

Commit

Permalink
chore: fix result-variants-provider test
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed Aug 14, 2024
1 parent 599b441 commit 8306709
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const result = createResultStub('jacket', { variants });
const render = ({
template = '<ResultVariantSelector/>',
result = {},
autoSelectDepth = Number.POSITIVE_INFINITY
autoSelectDepth = Number.POSITIVE_INFINITY,
queryPreviewHash = null as string | null
} = {}) => {
installNewXPlugin();
const emitSpy = jest.spyOn(XPlugin.bus, 'emit');
Expand All @@ -50,6 +51,9 @@ const render = ({
ResultVariantsProvider,
ResultVariantSelector
},
provide: {
queryPreviewHash
},
data: () => ({
result,
autoSelectDepth
Expand Down Expand Up @@ -170,6 +174,25 @@ describe('results with variants', () => {
);
});

it('emits UserSelectedAResultVariant event when a variant from a query preview is selected', async () => {
const { wrapper, emitSpy } = render({
result,
autoSelectDepth: 0,
queryPreviewHash: 'abcd'
});

const button = wrapper.find(getDataTestSelector('variant-button'));

await button.trigger('click');

expect(emitSpy).toHaveBeenCalledTimes(1);
expect(emitSpy).toHaveBeenCalledWith(
'UserSelectedAResultVariant',
{ result, variant: variants[0], level: 0, queryPreviewHash: 'abcd' },
expect.anything()
);
});

it('selects the first variant of all levels by default', () => {
const { findSelectorItemByLevel } = render({
template: `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = {
}
},
updateAQueryPreviewResult(state, { result, queryPreviewHash }) {
const queryPreviewResult = state.queriesPreview[queryPreviewHash.value].results.find(
const queryPreviewResult = state.queriesPreview[queryPreviewHash.value]?.results.find(
resultPreview => resultPreview.id === result.id
);
if (queryPreviewResult) {
Expand Down

0 comments on commit 8306709

Please sign in to comment.