Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vue3-update-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed Oct 7, 2024
1 parent 56dc022 commit 1aadc42
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
20 changes: 19 additions & 1 deletion packages/x-components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline

### ⚠ BREAKING CHANGES

* **history-queries-switch:** remove `change` event emission in favour of `update:modelValue` in `BaseSwitch` component.
* **history-queries-switch:** remove `change` event emission in favour of `update:modelValue` in `BaseSwitch` component.

### Bug Fixes

Expand Down Expand Up @@ -87,6 +87,24 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline



## [5.0.0-alpha.83](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.82...@empathyco/x-components@5.0.0-alpha.83) (2024-10-03)


### Bug Fixes

* snippet config extra params reactivity (#1628) ([c87788a](https://github.com/empathyco/x/commit/c87788a6f194e6b8f59b520f05e9ed617c98bae6))



## [5.0.0-alpha.82](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.81...@empathyco/x-components@5.0.0-alpha.82) (2024-09-30)


### Bug Fixes

* **tagging:** query tagging and send session param (#1627) ([69dd690](https://github.com/empathyco/x/commit/69dd690c1adf9195782f4747ba5d255251f5ac3c))



## [5.0.0-alpha.81](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.80...@empathyco/x-components@5.0.0-alpha.81) (2024-08-20)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import { XPlugin } from '../../../../plugins';
import { WirePayload } from '../../../../wiring';
import SnippetConfigExtraParams from '../snippet-config-extra-params.vue';
import { SnippetConfig } from '../../../../x-installer/api/api.types';

describe('testing snippet config extra params component', () => {
function renderSnippetConfigExtraParams({
values,
excludedExtraParams
}: RenderSnippetConfigExtraParamsOptions = {}): RenderSnippetConfigExtraParamsApi {
const snippetConfig = reactive({ warehouse: 1234, callbacks: {} });

const wrapper = mount(
{
template: `
Expand All @@ -40,120 +38,98 @@ describe('testing snippet config extra params component', () => {
}
}
);

function setSnippetConfig(newValue: Dictionary<unknown>): Promise<void> {
Object.assign(snippetConfig, newValue);
return nextTick();
}

return {
wrapper,
setSnippetConfig
};
}

it('is an XComponent which has an XModule', () => {
const { wrapper } = renderSnippetConfigExtraParams();
const component = wrapper.findComponent(SnippetConfigExtraParams);
expect(isXComponent(component.vm)).toEqual(true);
expect(getXComponentXModuleName(component.vm)).toEqual('extraParams');
});

// eslint-disable-next-line max-len
it('emits the ExtraParamsProvided event when the component is loaded, when the values prop changes, and when the snippet config changes', async () => {
const { wrapper, setSnippetConfig } = renderSnippetConfigExtraParams();
const extraParamsProvidedCallback = jest.fn();

XPlugin.bus.on('ExtraParamsProvided', true).subscribe(extraParamsProvidedCallback);

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
1,
expect.objectContaining({
eventPayload: { warehouse: 1234 }
})
);

await wrapper.setProps({ values: { store: 'myStore' } });

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
2,
expect.objectContaining({
eventPayload: { warehouse: 1234, store: 'myStore' }
})
);

await setSnippetConfig({ warehouse: 45679 });

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
3,
expect.objectContaining({
eventPayload: { warehouse: 45679, store: 'myStore' }
})
);
});

// eslint-disable-next-line max-len
it('emits the ExtraParamsProvided event with the values from the snippet config and the extra params', () => {
renderSnippetConfigExtraParams({ values: { scope: 'mobile' } });

const extraParamsProvidedCallback = jest.fn();

XPlugin.bus.on('ExtraParamsProvided', true).subscribe(extraParamsProvidedCallback);

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
1,
expect.objectContaining({
eventPayload: { warehouse: 1234, scope: 'mobile' }
})
);
});

// eslint-disable-next-line max-len
it('does not emit ExtraParamsProvided when any no extra params in the snippet config changes', async () => {
const { setSnippetConfig } = renderSnippetConfigExtraParams();
const extraParamsProvidedCallback = jest.fn();

XPlugin.bus.on('ExtraParamsProvided', true).subscribe(extraParamsProvidedCallback);

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
1,
expect.objectContaining({
eventPayload: { warehouse: 1234 }
})
);

await setSnippetConfig({ warehouse: 1234 });

expect(extraParamsProvidedCallback).toHaveBeenCalledTimes(1);

await setSnippetConfig({ uiLang: 'es' });
await setSnippetConfig({ uiLang: 'es' }); // Set an excluded extra param

expect(extraParamsProvidedCallback).toHaveBeenCalledTimes(2);
expect(extraParamsProvidedCallback).toHaveBeenCalledTimes(1);

await setSnippetConfig({ warehouse: 45678 });

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
3,
2,
expect.objectContaining({
eventPayload: { warehouse: 45678 }
})
);
});

it('not includes the callback configuration as extra params', () => {
renderSnippetConfigExtraParams();
const extraParamsProvidedCallback = jest.fn();

XPlugin.bus.on('ExtraParamsProvided', true).subscribe(extraParamsProvidedCallback);

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
1,
expect.not.objectContaining({
eventPayload: { callbacks: {} }
})
);
});

it('allows to configure excluded params', () => {
renderSnippetConfigExtraParams({
values: {
Expand All @@ -162,10 +138,8 @@ describe('testing snippet config extra params component', () => {
},
excludedExtraParams: ['currency', 'warehouse', 'callbacks']
});

const extraParamsProvidedCallback = jest.fn();
XPlugin.bus.on('ExtraParamsProvided', true).subscribe(extraParamsProvidedCallback);

expect(extraParamsProvidedCallback).toHaveBeenNthCalledWith<[WirePayload<Dictionary<unknown>>]>(
1,
expect.objectContaining({
Expand All @@ -176,7 +150,6 @@ describe('testing snippet config extra params component', () => {
);
});
});

interface RenderSnippetConfigExtraParamsOptions {
/**
* Extra values to use as extra params, apart from the ones extracted from the
Expand All @@ -188,7 +161,6 @@ interface RenderSnippetConfigExtraParamsOptions {
*/
excludedExtraParams?: Array<keyof SnippetConfig>;
}

interface RenderSnippetConfigExtraParamsApi {
/** The wrapper for the snippet config component. */
wrapper: VueWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
},
setup(props) {
const snippetConfig = inject('snippetConfig') as SnippetConfig;
const extraParams = ref({});
const extraParams = ref<Record<string, any>>({});
watch(
[() => snippetConfig, () => props.values],
() => {
forEach({ ...props.values, ...snippetConfig }, (name, value) => {
if (!props.excludedExtraParams.includes(name)) {
if (!props.excludedExtraParams.includes(name) && extraParams.value[name] !== value) {
extraParams.value = { ...extraParams.value, [name]: value };
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function renderTagging({

const defaultTaggingConfig: Partial<TaggingConfig> = {
clickedResultStorageTTLMs: 30000,
clickedResultStorageKey: 'url'
clickedResultStorageKey: 'url',
queryTaggingDebounceMs: 2000
};

const stubTagginMetadata: WireMetadata = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@
/**
* The debounce time in milliseconds to track the query.
*/
queryTaggingDebounceMs: Number,
queryTaggingDebounceMs: {
type: Number,
default: 2000
},
/**
* The consent to be emitted.
*/
consent: Boolean
consent: {
type: Boolean,
default: null
}
},
setup(props) {
const xBus = useXBus();
Expand All @@ -67,7 +73,7 @@
*/
const taggingConfig = computed<TaggingConfig>(() => {
return {
queryTaggingDebounceMs: props.queryTaggingDebounceMs as number,
queryTaggingDebounceMs: props.queryTaggingDebounceMs,
sessionTTLMs: props.sessionTTLMs as number,
clickedResultStorageTTLMs: props.clickedResultStorageTTLMs,
clickedResultStorageKey: props.clickedResultStorageKey
Expand Down
2 changes: 2 additions & 0 deletions packages/x-components/tests/e2e/clear-filters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Feature: Clear selected filters
Then related results are displayed
And filters "<filter>, <filter2>, <filter3>" are shown in the selected filters list
When clear search button is pressed
When "<query>" is searched
Then related results are displayed
Then no filters are selected

Examples:
Expand Down

0 comments on commit 1aadc42

Please sign in to comment.