From 0f35e7caf529e7a06252abe0ea64b119c1206566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Antonio=20Caba=C3=B1eros?= Date: Tue, 24 Sep 2024 15:25:26 +0200 Subject: [PATCH] test: active and fix linter for tests (#1616) --- packages/x-components/.eslintrc.js | 13 ++--- .../__tests__/base-event-button.spec.ts | 6 +-- .../components/__tests__/highlight.spec.ts | 16 ++---- .../composables/__tests__/use-x-bus.spec.ts | 2 +- .../api/__tests__/default-api.spec.ts | 10 ++-- .../x-installer/__tests__/x-installer.spec.ts | 19 ++++--- .../__tests__/device-detector.spec.ts | 4 +- .../__tests__/experience-controls.spec.ts | 3 +- .../__tests__/renderless-extra-params.spec.ts | 6 +-- .../__tests__/preselected-filters.spec.ts | 4 +- .../filters/__tests__/all-filter.spec.ts | 4 +- .../__tests__/hierarchical-filter.spec.ts | 9 ++-- .../exclude-filters-with-no-results.spec.ts | 38 +++---------- .../lists/__tests__/filters-list.spec.ts | 34 +++--------- .../lists/__tests__/filters-search.spec.ts | 2 +- .../__tests__/selected-filters-list.spec.ts | 50 ++++++----------- .../lists/__tests__/selected-filters.spec.ts | 4 +- .../lists/__tests__/sliced-filters.spec.ts | 3 +- .../service/__tests__/facets-service.spec.ts | 8 +-- .../__tests__/clear-history-queries.spec.ts | 6 +-- .../components/__tests__/next-query.spec.ts | 34 ++++++------ .../__tests__/query-preview.spec.ts | 8 +-- .../components/__tests__/related-tags.spec.ts | 17 +++--- .../__tests__/scroll-to-top.spec.ts | 53 ++++++------------- .../__tests__/clear-search-input.spec.ts | 6 +-- .../components/__tests__/search-input.spec.ts | 6 +-- .../__tests__/partial-query-button.spec.ts | 4 +- .../__tests__/partial-results-list.spec.ts | 24 +++------ .../components/__tests__/redirection.spec.ts | 49 +++++++---------- .../x-modules/url/store/__tests__/utils.ts | 1 + .../tests/unit/base-events-modal.spec.ts | 2 - .../x-components/tests/unit/base-grid.spec.ts | 2 - .../tests/unit/base-modal.spec.ts | 2 - .../tests/unit/main-scroll.spec.ts | 2 - .../tests/unit/search-input.spec.ts | 2 - .../tests/unit/sliding-panel.spec.ts | 2 - 36 files changed, 157 insertions(+), 298 deletions(-) diff --git a/packages/x-components/.eslintrc.js b/packages/x-components/.eslintrc.js index 1e20c248d9..91454f1566 100644 --- a/packages/x-components/.eslintrc.js +++ b/packages/x-components/.eslintrc.js @@ -1,13 +1,6 @@ module.exports = { extends: ['plugin:@empathyco/x/all'], - // TODO - Reactivate linter for unit and e2e tests once they pass. - ignorePatterns: [ - 'cypress.config.ts', - '**/__tests__/**/*.spec.ts', - '**/tests/**/*.spec.ts', - '**/__tests__/**/utils.ts', - '**/tests/**/utils.ts' - ], + ignorePatterns: ['cypress.config.ts'], parserOptions: { tsconfigRootDir: __dirname, project: 'tsconfig.eslint.json' @@ -43,7 +36,9 @@ module.exports = { { files: ['*.spec.ts'], rules: { - 'max-len': 'off' + 'max-len': 'off', + '@typescript-eslint/no-unsafe-argument': 'off', + 'vue/one-component-per-file': 'off' } } ] diff --git a/packages/x-components/src/components/__tests__/base-event-button.spec.ts b/packages/x-components/src/components/__tests__/base-event-button.spec.ts index 65dafa3ed6..931dbdffa2 100644 --- a/packages/x-components/src/components/__tests__/base-event-button.spec.ts +++ b/packages/x-components/src/components/__tests__/base-event-button.spec.ts @@ -1,12 +1,10 @@ import { ComponentMountingOptions, mount } from '@vue/test-utils'; import { installNewXPlugin } from '../../__tests__/utils'; import { XPlugin } from '../../plugins'; -import { WireMetadata } from '../../wiring/wiring.types'; +import { WireMetadata, XEventsTypes } from '../../wiring'; import BaseEventButton from '../base-event-button.vue'; -import { XEventsTypes } from 'src/wiring'; -const stubSlot = `button text - `; +const stubSlot = `button text`; function render(options: ComponentMountingOptions = {}) { const wrapper = mount(BaseEventButton, { diff --git a/packages/x-components/src/components/__tests__/highlight.spec.ts b/packages/x-components/src/components/__tests__/highlight.spec.ts index d03b53dc4f..f96c12cf72 100644 --- a/packages/x-components/src/components/__tests__/highlight.spec.ts +++ b/packages/x-components/src/components/__tests__/highlight.spec.ts @@ -22,18 +22,10 @@ function renderHighlight({ }); return { wrapper, - getStartPart() { - return wrapper.find(getDataTestSelector('highlight-start')); - }, - getMatchingPart() { - return wrapper.find(getDataTestSelector('matching-part')); - }, - getEndPart() { - return wrapper.find(getDataTestSelector('highlight-end')); - }, - async setHighlight(highlight: string) { - return await wrapper.setProps({ highlight } as any); - } + getStartPart: () => wrapper.find(getDataTestSelector('highlight-start')), + getMatchingPart: () => wrapper.find(getDataTestSelector('matching-part')), + getEndPart: () => wrapper.find(getDataTestSelector('highlight-end')), + setHighlight: (highlight: string) => wrapper.setProps({ highlight } as any) }; } diff --git a/packages/x-components/src/composables/__tests__/use-x-bus.spec.ts b/packages/x-components/src/composables/__tests__/use-x-bus.spec.ts index 01939b9b06..84de606847 100644 --- a/packages/x-components/src/composables/__tests__/use-x-bus.spec.ts +++ b/packages/x-components/src/composables/__tests__/use-x-bus.spec.ts @@ -39,7 +39,7 @@ describe('testing useXBus', () => { onColumnsNumberProvidedMock.mockReset(); }); - it('should emit and on subscription in the bus for registered events', async () => { + it('should emit and on subscription in the bus for registered events', () => { const { emitSpy, onSpy } = render(); const metadata = { customMetadata: 'custom', diff --git a/packages/x-components/src/x-installer/api/__tests__/default-api.spec.ts b/packages/x-components/src/x-installer/api/__tests__/default-api.spec.ts index ef43731523..027ded3301 100644 --- a/packages/x-components/src/x-installer/api/__tests__/default-api.spec.ts +++ b/packages/x-components/src/x-installer/api/__tests__/default-api.spec.ts @@ -72,16 +72,16 @@ describe('testing default X API', () => { lang: 'es' }; const rootComponent = defineComponent({ - template: `
-

{{ lang }}

-

{{ store }}

-
`, setup: () => { const snippetConfig = inject('snippetConfig'); const lang = computed(() => snippetConfig?.lang ?? ''); const store = computed(() => snippetConfig?.store ?? ''); return { lang, store }; - } + }, + template: `
+

{{ lang }}

+

{{ store }}

+
` }); const { api } = await new XInstaller({ diff --git a/packages/x-components/src/x-installer/x-installer/__tests__/x-installer.spec.ts b/packages/x-components/src/x-installer/x-installer/__tests__/x-installer.spec.ts index a7287a412b..2ede7a056a 100644 --- a/packages/x-components/src/x-installer/x-installer/__tests__/x-installer.spec.ts +++ b/packages/x-components/src/x-installer/x-installer/__tests__/x-installer.spec.ts @@ -23,9 +23,11 @@ const getMinimumSnippetConfig = (): SnippetConfig => ({ }); const component = defineComponent({ - template: '

', - setup: () => {}, - mounted: jest.fn() + setup: () => { + // empty setup + }, + mounted: jest.fn(), + template: '

' }); /** @@ -36,12 +38,12 @@ const component = defineComponent({ */ function createSnippetConfigComponent(snippetProperty: keyof SnippetConfig = 'instance') { return defineComponent({ - template: '

{{ snippetConfigValue }}

', setup: () => { const snippetConfig = inject('snippetConfig'); const snippetConfigValue = computed(() => snippetConfig?.[snippetProperty] ?? ''); return { snippetConfigValue }; - } + }, + template: '

{{ snippetConfigValue }}

' }); } @@ -98,6 +100,7 @@ describe('testing `XInstaller` utility', () => { getMinimumSnippetConfig() ); + // eslint-disable-next-line @typescript-eslint/unbound-method expect(component?.mounted).toHaveBeenCalledTimes(1); }); @@ -229,8 +232,10 @@ describe('testing `XInstaller` utility', () => { */ const componentApp = defineComponent({ - template: '
', - setup: () => {} + setup: () => { + // emtpy setup + }, + template: '
' }); function installX( diff --git a/packages/x-components/src/x-modules/device/components/__tests__/device-detector.spec.ts b/packages/x-components/src/x-modules/device/components/__tests__/device-detector.spec.ts index 61641f858b..99752092a6 100644 --- a/packages/x-components/src/x-modules/device/components/__tests__/device-detector.spec.ts +++ b/packages/x-components/src/x-modules/device/components/__tests__/device-detector.spec.ts @@ -25,7 +25,7 @@ async function renderDeviceDetector({ } = {}) { Object.assign(window, { innerWidth: initialWidth }); const xBus = new XDummyBus(); - let emitSpy = jest.spyOn(xBus, 'emit'); + const emitSpy = jest.spyOn(xBus, 'emit'); const wrapper = mount(DeviceDetector, { props: { @@ -45,7 +45,7 @@ async function renderDeviceDetector({ Object.assign(window, { innerWidth: width }); window.dispatchEvent(new UIEvent('resize')); }, - waitForThrottle() { + waitForThrottle: () => { jest.advanceTimersByTime(throttleMs); return nextTick(); } diff --git a/packages/x-components/src/x-modules/experience-controls/components/__tests__/experience-controls.spec.ts b/packages/x-components/src/x-modules/experience-controls/components/__tests__/experience-controls.spec.ts index 00c3f877d0..70482e7e34 100644 --- a/packages/x-components/src/x-modules/experience-controls/components/__tests__/experience-controls.spec.ts +++ b/packages/x-components/src/x-modules/experience-controls/components/__tests__/experience-controls.spec.ts @@ -24,9 +24,8 @@ describe('testing experience controls component', () => { expect(getXComponentXModuleName(wrapper.vm)).toEqual('experienceControls'); }); - // eslint-disable-next-line max-len it('listens to the event ExperienceControlsEventsChanged and emits the events on the payload', () => { - const { wrapper } = renderExperienceControls(); + renderExperienceControls(); const eventsFromExperienceControls = { ExtraParamsProvided: { diff --git a/packages/x-components/src/x-modules/extra-params/components/__tests__/renderless-extra-params.spec.ts b/packages/x-components/src/x-modules/extra-params/components/__tests__/renderless-extra-params.spec.ts index ef87a44a4e..7d72cbf9e1 100644 --- a/packages/x-components/src/x-modules/extra-params/components/__tests__/renderless-extra-params.spec.ts +++ b/packages/x-components/src/x-modules/extra-params/components/__tests__/renderless-extra-params.spec.ts @@ -8,11 +8,7 @@ import { extraParamsXModule } from '../../x-module'; import RenderlessExtraParam from '../renderless-extra-param.vue'; import { resetXExtraParamStateWith } from './utils'; -function render({ - template = ``, - name = 'warehouse', - params = {} -} = {}) { +function render({ template = ``, name = 'warehouse' } = {}) { const wrapper = mount( { template, diff --git a/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts b/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts index b9d321abd7..a90cd7c61f 100644 --- a/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts @@ -147,11 +147,11 @@ describe('testing Preselected filters component', () => { // Create a test component to check the injected provide value const TestComponent = defineComponent({ - template: '
{{ snippetConfig.filters.join(\',\') }}
', setup() { const snippetConfig = inject('snippetConfig'); return { snippetConfig }; - } + }, + template: '
{{ snippetConfig.filters.join(\',\') }}
' }); // Mount the original component with TestComponent inside the slot to test provide diff --git a/packages/x-components/src/x-modules/facets/components/filters/__tests__/all-filter.spec.ts b/packages/x-components/src/x-modules/facets/components/filters/__tests__/all-filter.spec.ts index f83a54c351..60726466e4 100644 --- a/packages/x-components/src/x-modules/facets/components/filters/__tests__/all-filter.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/filters/__tests__/all-filter.spec.ts @@ -51,11 +51,11 @@ function renderAllFilter({ template = `` } wrapper, allFilterWrapper, facet, - toggleFirstFilter() { + toggleFirstFilter: () => { XPlugin.bus.emit('UserClickedAFilter', store.state.x.facets.filters[facet.filters[0].id]); return nextTick(); }, - clickAllFilter() { + clickAllFilter: () => { allFilterWrapper.trigger('click'); return nextTick(); } diff --git a/packages/x-components/src/x-modules/facets/components/filters/__tests__/hierarchical-filter.spec.ts b/packages/x-components/src/x-modules/facets/components/filters/__tests__/hierarchical-filter.spec.ts index 7bf05c9329..1481fc1a3a 100644 --- a/packages/x-components/src/x-modules/facets/components/filters/__tests__/hierarchical-filter.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/filters/__tests__/hierarchical-filter.spec.ts @@ -333,13 +333,12 @@ describe('testing `HierarchicalFilter` component', () => { getFiltersWrappers().forEach((filterWrapper, index) => { const filter = getFilters()[index]; + const classes = ['x-facet-filter', 'x-hierarchical-filter']; if (partiallySelectedIds.includes(filter.id)) { - expect(filterWrapper.classes()).toContain('x-hierarchical-filter--is-partially-selected'); - } else { - expect(filterWrapper.classes()).not.toContain( - 'x-hierarchical-filter--is-partially-selected' - ); + classes.push('x-hierarchical-filter--is-partially-selected'); + classes.push('x-facet-filter--is-partially-selected'); } + expect(filterWrapper.classes()).toEqual(expect.arrayContaining(classes)); }); }); diff --git a/packages/x-components/src/x-modules/facets/components/lists/__tests__/exclude-filters-with-no-results.spec.ts b/packages/x-components/src/x-modules/facets/components/lists/__tests__/exclude-filters-with-no-results.spec.ts index 4ca2d2c263..5533548297 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/__tests__/exclude-filters-with-no-results.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/lists/__tests__/exclude-filters-with-no-results.spec.ts @@ -1,27 +1,18 @@ -import { Filter } from '@empathyco/x-types'; -import { mount, VueWrapper, DOMWrapper } from '@vue/test-utils'; -import Vue from 'vue'; -import { getSimpleFilterStub } from '../../../../../__stubs__/filters-stubs.factory'; +import { SimpleFilter } from '@empathyco/x-types'; +import { mount } from '@vue/test-utils'; +import { getSimpleFilterStub } from '../../../../../__stubs__'; import { getXComponentXModuleName, isXComponent } from '../../../../../components'; import ExcludeFiltersWithNoResults from '../exclude-filters-with-no-results.vue'; -/** - * Renders a {@link ExcludeFiltersWithNoResults} component with the provided options, and returns - * a small API to test it. - * - * @param options - Options to test the {@link ExcludeFiltersWithNoResults} component with. - * @returns A {@link RenderExcludeFiltersWithNoResultsAPI} object to test the - * {@link ExcludeFiltersWithNoResults}. - */ function renderExcludeFiltersWithNoResults({ - filters = [], + filters = [] as SimpleFilter[], template = `
{{ filter.label }}
` -}: RenderExcludeFiltersWithNoResultsOptions = {}): RenderExcludeFiltersWithNoResultsAPI { +} = {}) { const templateWrapper = mount( { props: ['filters'], @@ -38,9 +29,7 @@ function renderExcludeFiltersWithNoResults({ const wrapper = templateWrapper.findComponent(ExcludeFiltersWithNoResults); return { wrapper, - getRenderedFilters() { - return templateWrapper.findAll('.filter'); - } + getRenderedFilters: () => templateWrapper.findAll('.filter') }; } @@ -70,18 +59,3 @@ describe('testing Filters component', () => { expect(renderedFilters.map(wrapper => wrapper.text())).toEqual(['Women', 'Kids']); }); }); - -interface RenderExcludeFiltersWithNoResultsOptions { - /** The filters data to render. */ - filters?: Filter[]; - /** The template to render. Receives the `filters` via prop, and has registered the - * {@link ExcludeFiltersWithNoResults} component. */ - template?: string; -} - -interface RenderExcludeFiltersWithNoResultsAPI { - /** Retrieves the testing wrappers of the filters. */ - getRenderedFilters: () => DOMWrapper[]; - /** The Vue testing utils wrapper for the {@link ExcludeFiltersWithNoResults} component. */ - wrapper: VueWrapper; -} diff --git a/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-list.spec.ts b/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-list.spec.ts index 1fd6259f4b..be3fe3e06b 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-list.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-list.spec.ts @@ -1,21 +1,14 @@ -import { Filter } from '@empathyco/x-types'; -import { mount, VueWrapper } from '@vue/test-utils'; -import Vue from 'vue'; -import { createSimpleFacetStub } from '../../../../../__stubs__/facets-stubs.factory'; +import { SimpleFilter } from '@empathyco/x-types'; +import { mount } from '@vue/test-utils'; +import { createSimpleFacetStub } from '../../../../../__stubs__'; import { getDataTestSelector } from '../../../../../__tests__/utils'; import { getXComponentXModuleName, isXComponent } from '../../../../../components'; import FiltersList from '../filters-list.vue'; -/** - * Function that returns a Filters wrapper. - * - * @param filters - Filters filters props. - * @returns FiltersList vue-test-utils wrapper. - */ function renderFilters({ - filters = [], + filters = [] as SimpleFilter[], template = '' -}: RenderFiltersOptions = {}): RenderFiltersAPI { +} = {}) { const wrapperTemplate = mount( { props: ['filters'], @@ -65,7 +58,7 @@ describe('testing Filters component', () => { filters, template: ` -

{{ filter.label }}

+

{{ filter.label }}

` }); @@ -76,18 +69,3 @@ describe('testing Filters component', () => { }); }); }); - -interface RenderFiltersOptions { - /** The filters data to render. */ - filters?: Filter[]; - /** The template to render. Receives the `filters` via prop, and has registered the - * {@link FiltersComponent} as `Filters`. */ - template?: string; -} - -interface RenderFiltersAPI { - /** The rendered filters data. */ - filters: Filter[]; - /** The Vue testing utils wrapper for the {@link FiltersComponent}. */ - wrapper: VueWrapper; -} diff --git a/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-search.spec.ts b/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-search.spec.ts index c7af2e046a..05a2ebfac3 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-search.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/lists/__tests__/filters-search.spec.ts @@ -1,7 +1,7 @@ import { Filter } from '@empathyco/x-types'; import { Dictionary } from '@empathyco/x-utils'; import { mount, VueWrapper, DOMWrapper } from '@vue/test-utils'; -import Vue, { nextTick } from 'vue'; +import { nextTick } from 'vue'; import { getXComponentXModuleName, isXComponent } from '../../../../../components'; import { getSimpleFilterStub } from '../../../../../__stubs__/filters-stubs.factory'; import { getDataTestSelector } from '../../../../../__tests__/utils'; diff --git a/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters-list.spec.ts b/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters-list.spec.ts index eebd7d5cd3..df329b0211 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters-list.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters-list.spec.ts @@ -1,9 +1,9 @@ import { BooleanFilter, Facet } from '@empathyco/x-types'; import { DeepPartial } from '@empathyco/x-utils'; -import { mount, VueWrapper, DOMWrapper } from '@vue/test-utils'; +import { mount } from '@vue/test-utils'; import { nextTick } from 'vue'; import { Store } from 'vuex'; -import { createSimpleFacetStub } from '../../../../../__stubs__/facets-stubs.factory'; +import { createSimpleFacetStub } from '../../../../../__stubs__'; import { getDataTestSelector, installNewXPlugin } from '../../../../../__tests__/utils'; import { getXComponentXModuleName, isXComponent } from '../../../../../components'; import { XPlugin } from '../../../../../plugins'; @@ -20,8 +20,8 @@ import SelectedFiltersList from '../../lists/selected-filters-list.vue'; */ function renderSelectedFiltersList({ template = '', - facetsIds = undefined -}: RenderSelectedFiltersListOptions = {}): RenderSelectedFiltersAPI { + facetsIds = undefined as undefined | string[] +} = {}) { const facets: Record = { gender: createSimpleFacetStub('gender', createFilter => [ createFilter('Men', false), @@ -69,14 +69,13 @@ function renderSelectedFiltersList({ return { wrapper, selectedFiltersListWrapper, - toggleFacetNthFilter(facetId, nth) { + toggleFacetNthFilter: (facetId: string, nth: number) => { const filter = (store.getters['x/facets/facets']![facetId].filters as BooleanFilter[])[nth]; filter.selected = !filter.selected; return nextTick(); }, - selectedFiltersItems() { - return selectedFiltersListWrapper.findAll(getDataTestSelector('selected-filters-list-item')); - } + selectedFiltersItems: () => + selectedFiltersListWrapper.findAll(getDataTestSelector('selected-filters-list-item')) }; } @@ -105,8 +104,8 @@ describe('testing SelectedFiltersList component', () => { getDataTestSelector('selected-filters-list-item') ); - expect(selectedFiltersItems.at(0)?.text()).toBe('Men'); - expect(selectedFiltersItems.at(1)?.text()).toBe('BMW'); + expect(selectedFiltersItems.at(0)?.text()).toEqual('Men'); + expect(selectedFiltersItems.at(1)?.text()).toEqual('BMW'); }); it('renders custom default slot and custom facetId slot', async () => { @@ -128,9 +127,9 @@ describe('testing SelectedFiltersList component', () => { getDataTestSelector('selected-filters-list-item') ); - expect(selectedFiltersItems.at(0)?.text()).toBe('Men selected!'); - expect(selectedFiltersItems.at(1)?.text()).toBe('Which one? BMW'); - expect(selectedFiltersItems.at(2)?.text()).toBe('Much better: Meat'); + expect(selectedFiltersItems.at(0)?.text()).toEqual('Men selected!'); + expect(selectedFiltersItems.at(1)?.text()).toEqual('Which one? BMW'); + expect(selectedFiltersItems.at(2)?.text()).toEqual('Much better: Meat'); expect(selectedFiltersItems).toHaveLength(3); }); @@ -140,15 +139,15 @@ describe('testing SelectedFiltersList component', () => { facetsIds: ['brand', 'gender'] }); - expect(selectedFiltersListWrapper.text()).toBe(''); + expect(selectedFiltersListWrapper.text()).toEqual(''); await toggleFacetNthFilter('brand', 0); await toggleFacetNthFilter('rootCategories', 1); await toggleFacetNthFilter('gender', 1); expect(selectedFiltersItems()).toHaveLength(2); - expect(selectedFiltersItems().at(0)?.text()).toBe('Audi'); - expect(selectedFiltersItems().at(1)?.text()).toBe('Women'); + expect(selectedFiltersItems().at(0)?.text()).toEqual('Audi'); + expect(selectedFiltersItems().at(1)?.text()).toEqual('Women'); }); it('renders the component if alwaysVisible is true and no selected filters', () => { @@ -166,22 +165,3 @@ describe('testing SelectedFiltersList component', () => { expect(selectedFiltersListWrapper.html()).toBe(''); }); }); - -interface RenderSelectedFiltersListOptions { - /** The template to be rendered. */ - template?: string; - /** Array of facets ids. */ - facetsIds?: Array; -} - -interface RenderSelectedFiltersAPI { - /** The wrapper of the container element. */ - wrapper: VueWrapper; - /** The `selectedFilters` wrapper component. */ - selectedFiltersListWrapper: VueWrapper; - /** Toggle nth filter of the facet provided. */ - toggleFacetNthFilter: (facetId: string, nth: number) => Promise; - /** Retrieves the wrapper for the items of the list rendered by the {@link SelectedFiltersList} - * component. */ - selectedFiltersItems: () => DOMWrapper[]; -} diff --git a/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters.spec.ts b/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters.spec.ts index a250606e9f..348205389a 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/lists/__tests__/selected-filters.spec.ts @@ -1,6 +1,8 @@ import { Facet } from '@empathyco/x-types'; import { mount } from '@vue/test-utils'; import { nextTick } from 'vue'; +import { Store } from 'vuex'; +import { DeepPartial } from '@empathyco/x-utils'; import { createSimpleFacetStub } from '../../../../../__stubs__/facets-stubs.factory'; import { installNewXPlugin } from '../../../../../__tests__/utils'; import { getXComponentXModuleName, isXComponent } from '../../../../../components'; @@ -8,8 +10,6 @@ import { facetsXModule } from '../../../x-module'; import { resetXFacetsStateWith } from '../../__tests__/utils'; import SelectedFilters from '../selected-filters.vue'; import { resetFacetsService } from '../../../__tests__/utils'; -import { Store } from 'vuex'; -import { DeepPartial } from '@empathyco/x-utils'; import { RootXStoreState } from '../../../../../store/index'; async function render({ template = '', facetsIds = [] as string[] } = {}) { diff --git a/packages/x-components/src/x-modules/facets/components/lists/__tests__/sliced-filters.spec.ts b/packages/x-components/src/x-modules/facets/components/lists/__tests__/sliced-filters.spec.ts index 78669b4ef3..4404d2c80f 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/__tests__/sliced-filters.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/lists/__tests__/sliced-filters.spec.ts @@ -1,7 +1,6 @@ import { Filter } from '@empathyco/x-types'; import { mount, VueWrapper, DOMWrapper } from '@vue/test-utils'; -import Vue from 'vue'; -import { createSimpleFilter } from '../../../../../__stubs__/filters-stubs.factory'; +import { createSimpleFilter } from '../../../../../__stubs__'; import { getDataTestSelector } from '../../../../../__tests__/utils'; import { getXComponentXModuleName, isXComponent } from '../../../../../components'; import SlicedFilters from '../sliced-filters.vue'; diff --git a/packages/x-components/src/x-modules/facets/service/__tests__/facets-service.spec.ts b/packages/x-components/src/x-modules/facets/service/__tests__/facets-service.spec.ts index d7b1ff9b97..9c57555487 100644 --- a/packages/x-components/src/x-modules/facets/service/__tests__/facets-service.spec.ts +++ b/packages/x-components/src/x-modules/facets/service/__tests__/facets-service.spec.ts @@ -739,10 +739,10 @@ interface FacetsServiceTestAPI { /** * Excludes the filters property from the given facet. * - * @param filters - The filters available for the facet. - * @param facet - The full facet from whom exclude its filter property. + * @param facet - The full facet. * @returns The given facet without the `filters` property. */ -function omitFiltersProperty({ filters, ...facet }: Facet): Omit { - return facet; +function omitFiltersProperty(facet: Facet): Omit { + const { filters, ...rest } = facet; + return rest; } diff --git a/packages/x-components/src/x-modules/history-queries/components/__tests__/clear-history-queries.spec.ts b/packages/x-components/src/x-modules/history-queries/components/__tests__/clear-history-queries.spec.ts index 8e3dc7e8c3..93e7515a5a 100644 --- a/packages/x-components/src/x-modules/history-queries/components/__tests__/clear-history-queries.spec.ts +++ b/packages/x-components/src/x-modules/history-queries/components/__tests__/clear-history-queries.spec.ts @@ -88,9 +88,9 @@ describe('testing ClearHistoryQueries component', () => { } } }); - const renderedSlotHTML = wrapper.element.querySelector('.x-clear-history-queries__text'); + const renderedSlot = wrapper.find('.x-clear-history-queries__text'); - expect(renderedSlotHTML).toBeDefined(); - expect(renderedSlotHTML!.textContent).toEqual('Clear'); + expect(renderedSlot).toBeDefined(); + expect(renderedSlot.text()).toEqual('Clear'); }); }); diff --git a/packages/x-components/src/x-modules/next-queries/components/__tests__/next-query.spec.ts b/packages/x-components/src/x-modules/next-queries/components/__tests__/next-query.spec.ts index a5935cc434..531a6db82b 100644 --- a/packages/x-components/src/x-modules/next-queries/components/__tests__/next-query.spec.ts +++ b/packages/x-components/src/x-modules/next-queries/components/__tests__/next-query.spec.ts @@ -1,12 +1,13 @@ import { mount } from '@vue/test-utils'; import { NextQuery } from '@empathyco/x-types'; import { nextTick } from 'vue'; -import { createNextQueryStub } from '../../../../__stubs__/next-queries-stubs.factory'; +import { createNextQueryStub } from '../../../../__stubs__'; import { getDataTestSelector, installNewXPlugin } from '../../../../__tests__/utils'; -import { getXComponentXModuleName, isXComponent } from '../../../../components/x-component.utils'; -import { WireMetadata } from '../../../../wiring/wiring.types'; +import { getXComponentXModuleName, isXComponent } from '../../../../components'; +import { WireMetadata } from '../../../../wiring'; import { default as NextQueryComponent } from '../next-query.vue'; import { XPlugin } from '../../../../plugins/index'; + function renderNextQuery({ suggestion = createNextQueryStub('milk'), template = '' @@ -32,15 +33,11 @@ function renderNextQuery({ wrapper, wrapperTemplate, suggestion, - async clickNextQuery(): Promise { - wrapper.trigger('click'); - await nextTick(); - }, - hasIsCuratedClass(): boolean { - return wrapperTemplate + clickNextQuery: async () => await wrapper.trigger('click'), + hasIsCuratedClass: () => + wrapperTemplate .find(getDataTestSelector('next-query')) - .element.classList.contains('x-next-query--is-curated'); - } + .element.classList.contains('x-next-query--is-curated') }; } @@ -79,13 +76,12 @@ describe('testing next query item component', () => { const template = ` - - `; + `; const { wrapper, suggestion } = renderNextQuery({ template @@ -99,14 +95,14 @@ describe('testing next query item component', () => { it('highlights NQ if curated and indicated via prop', async () => { const { wrapperTemplate, suggestion, hasIsCuratedClass } = renderNextQuery(); - expect(hasIsCuratedClass()).toBe(false); + expect(hasIsCuratedClass()).toEqual(false); suggestion.isCurated = true; - expect(hasIsCuratedClass()).toBe(false); + expect(hasIsCuratedClass()).toEqual(false); await wrapperTemplate.setProps({ highlightCurated: true }); await nextTick(); - expect(hasIsCuratedClass()).toBe(true); + expect(hasIsCuratedClass()).toEqual(true); }); }); diff --git a/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts b/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts index dc8cf03f83..90a9afa6af 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts +++ b/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts @@ -233,7 +233,7 @@ describe('query preview', () => { it('renders the results names in the default slot', async () => { const { getQueryPreviewItemWrappers, queryPreviewInState } = await render(); - queryPreviewInState!.results.forEach((result, index) => { + queryPreviewInState.results.forEach((result, index) => { expect(getQueryPreviewItemWrappers().at(index)?.element).toHaveTextContent(result.name!); }); }); @@ -264,11 +264,11 @@ describe('query preview', () => { ).toHaveTextContent(queryPreviewInfo.query); expect( queryPreviewWrapper.find(getDataTestSelector('total-results')).element - ).toHaveTextContent(queryPreviewInState!.totalResults.toString()); + ).toHaveTextContent(queryPreviewInState.totalResults.toString()); const resultsWrappers = findTestDataById(queryPreviewWrapper, 'result-name'); - queryPreviewInState!.results.forEach((result, index) => { + queryPreviewInState.results.forEach((result, index) => { expect(resultsWrappers.at(index)?.element).toHaveTextContent(result.name!); }); }); @@ -283,7 +283,7 @@ describe('query preview', () => { const resultsWrapper = findTestDataById(queryPreviewWrapper, 'result-content'); - queryPreviewInState!.results.forEach((result, index) => { + queryPreviewInState.results.forEach((result, index) => { expect(resultsWrapper.at(index)?.element).toHaveTextContent(`${result.id} - ${result.name!}`); }); }); diff --git a/packages/x-components/src/x-modules/related-tags/components/__tests__/related-tags.spec.ts b/packages/x-components/src/x-modules/related-tags/components/__tests__/related-tags.spec.ts index 9c005bf436..8e236fde6a 100644 --- a/packages/x-components/src/x-modules/related-tags/components/__tests__/related-tags.spec.ts +++ b/packages/x-components/src/x-modules/related-tags/components/__tests__/related-tags.spec.ts @@ -1,5 +1,5 @@ import { DeepPartial } from '@empathyco/x-utils'; -import { mount } from '@vue/test-utils'; +import { DOMWrapper, mount } from '@vue/test-utils'; import { nextTick } from 'vue'; import { Store } from 'vuex'; import { getXComponentXModuleName, isXComponent } from '../../../../components'; @@ -49,7 +49,7 @@ describe('testing related tags component', () => { it('is an XComponent', async () => { const { relatedTagsWrapper } = await renderRelatedTags(); - expect(isXComponent(relatedTagsWrapper.vm)).toBeTruthy(); + expect(isXComponent(relatedTagsWrapper.vm)).toEqual(true); expect(getXComponentXModuleName(relatedTagsWrapper.vm)).toEqual('relatedTags'); }); @@ -84,16 +84,19 @@ describe('testing related tags component', () => { ` }); - function expectToHaveOverriddenContent(relatedTagItemWrapper: any, index: number): void { + function expectToHaveOverriddenContent( + relatedTagItemWrapper: DOMWrapper, + index: number + ): void { const labelWrapper = relatedTagItemWrapper.find(getDataTestSelector('related-tag-label')); const crossWrapper = relatedTagItemWrapper.find(getDataTestSelector('related-tag-cross')); const chevronWrapper = relatedTagItemWrapper.find(getDataTestSelector('related-tag-chevron')); @@ -119,7 +122,7 @@ describe('testing related tags component', () => { await wrapper.setProps({ highlightCurated: true } as any); relatedTagsWrappers = getRelatedTagItems(); const chevron = relatedTagsWrappers[0].find(getDataTestSelector('related-tag-chevron')); - expect(chevron.exists()).toBeTruthy(); + expect(chevron.exists()).toEqual(true); }); it('allows changing the whole component for each related tag', async () => { diff --git a/packages/x-components/src/x-modules/scroll/components/__tests__/scroll-to-top.spec.ts b/packages/x-components/src/x-modules/scroll/components/__tests__/scroll-to-top.spec.ts index 3e4349251a..1bc6fd3cac 100644 --- a/packages/x-components/src/x-modules/scroll/components/__tests__/scroll-to-top.spec.ts +++ b/packages/x-components/src/x-modules/scroll/components/__tests__/scroll-to-top.spec.ts @@ -1,9 +1,9 @@ -import { mount, VueWrapper } from '@vue/test-utils'; +import { mount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import { installNewXPlugin } from '../../../../__tests__/utils'; -import { XEvent, XEventPayload } from '../../../../wiring/events.types'; +import { XEvent, XEventPayload } from '../../../../wiring'; import { scrollXModule } from '../../x-module'; import ScrollToTop from '../scroll-to-top.vue'; -import { nextTick } from 'vue'; import { XPlugin } from '../../../../plugins'; /** @@ -15,8 +15,8 @@ import { XPlugin } from '../../../../plugins'; function renderScrollToTop({ defaultSlot = 'Top', scrollId = 'scrollId', - thresholdPx -}: RenderScrollToTopOptions = {}): RenderScrollToTopAPI { + thresholdPx = undefined as undefined | number +} = {}) { const wrapper = mount(ScrollToTop, { propsData: { scrollId, thresholdPx }, global: { plugins: [installNewXPlugin({ initialXModules: [scrollXModule] })] }, @@ -29,10 +29,8 @@ function renderScrollToTop({ return { scrollToTopWrapper, - async click() { - await scrollToTopWrapper.trigger('click'); - }, - emitXEvent(event, payload) { + click: async () => await scrollToTopWrapper.trigger('click'), + emitXEvent: (event: Event, payload: XEventPayload) => { XPlugin.bus.emit(event, payload, { id: 'scrollId', moduleName: null }); return nextTick(); } @@ -49,24 +47,24 @@ describe('testing Scroll To Top component', () => { it('shows if a scroll is almost reaching the end and there is no threshold', async () => { const { scrollToTopWrapper, emitXEvent } = renderScrollToTop(); - expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toBe(false); + expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toEqual(false); await emitXEvent('UserAlmostReachedScrollEnd', true); await emitXEvent('UserChangedScrollDirection', 'DOWN'); - expect(scrollToTopWrapper.html()).not.toBe(''); + expect(scrollToTopWrapper.html()).not.toEqual(''); }); it('shows if the scroll is over the threshold and user scrolls up', async () => { const { scrollToTopWrapper, emitXEvent } = renderScrollToTop({ thresholdPx: 200 }); - expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toBe(false); + expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toEqual(false); await emitXEvent('UserScrolled', 250); await emitXEvent('UserChangedScrollDirection', 'UP'); - expect(scrollToTopWrapper.html()).not.toBe(''); + expect(scrollToTopWrapper.html()).not.toEqual(''); }); it("emits event with the component's id as payload when clicked", async () => { - const { scrollToTopWrapper, emitXEvent, click } = renderScrollToTop(); + const { emitXEvent, click } = renderScrollToTop(); const listener = jest.fn(); XPlugin.bus.on('UserClickedScrollToTop').subscribe(listener); @@ -78,16 +76,15 @@ describe('testing Scroll To Top component', () => { expect(listener).toHaveBeenCalledWith('scrollId'); }); - // eslint-disable-next-line max-len it('hides when the scroll direction is up once the scroll has almost reached the end', async () => { const { scrollToTopWrapper, emitXEvent } = renderScrollToTop(); await emitXEvent('UserChangedScrollDirection', 'DOWN'); await emitXEvent('UserAlmostReachedScrollEnd', true); - expect(scrollToTopWrapper.html()).not.toBe(''); + expect(scrollToTopWrapper.html()).not.toEqual(''); await emitXEvent('UserChangedScrollDirection', 'UP'); - expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toBe(false); + expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toEqual(false); }); it('hides when the scroll gets lesser than the threshold', async () => { @@ -95,27 +92,9 @@ describe('testing Scroll To Top component', () => { await emitXEvent('UserScrolled', 1100); await emitXEvent('UserChangedScrollDirection', 'UP'); - expect(scrollToTopWrapper.html()).not.toBe(''); + expect(scrollToTopWrapper.html()).not.toEqual(''); await emitXEvent('UserScrolled', 900); - expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toBe(false); + expect(scrollToTopWrapper.find('.x-scroll-to-top').exists()).toEqual(false); }); }); - -interface RenderScrollToTopOptions { - /** The default slot for the component. */ - defaultSlot?: string; - /** The id of the scroll referring the scroll to top. */ - scrollId?: string; - /** The number of pixels of threshold from the top to show the component. */ - thresholdPx?: number; -} - -interface RenderScrollToTopAPI { - /** The wrapper for the base scroll to top component. */ - scrollToTopWrapper: VueWrapper; - /** Clicks the button. */ - click: () => Promise; - /** Emits an XEvent with the id in metadata. */ - emitXEvent: (event: Event, payload: XEventPayload) => Promise; -} diff --git a/packages/x-components/src/x-modules/search-box/components/__tests__/clear-search-input.spec.ts b/packages/x-components/src/x-modules/search-box/components/__tests__/clear-search-input.spec.ts index 1813099cc7..c0c4994350 100644 --- a/packages/x-components/src/x-modules/search-box/components/__tests__/clear-search-input.spec.ts +++ b/packages/x-components/src/x-modules/search-box/components/__tests__/clear-search-input.spec.ts @@ -42,9 +42,9 @@ describe('testing ClearSearchInput component', () => { } } }); - const renderedSlotHTML = clearSearchInput.element.querySelector('.x-clear-search-input__text'); + const renderedSlot = clearSearchInput.find('.x-clear-search-input__text'); - expect(renderedSlotHTML).toBeDefined(); - expect(renderedSlotHTML!.textContent).toEqual('Clear'); + expect(renderedSlot).toBeDefined(); + expect(renderedSlot.text()).toEqual('Clear'); }); }); diff --git a/packages/x-components/src/x-modules/search-box/components/__tests__/search-input.spec.ts b/packages/x-components/src/x-modules/search-box/components/__tests__/search-input.spec.ts index b70b637640..1cd08efd47 100644 --- a/packages/x-components/src/x-modules/search-box/components/__tests__/search-input.spec.ts +++ b/packages/x-components/src/x-modules/search-box/components/__tests__/search-input.spec.ts @@ -79,14 +79,14 @@ describe('testing search input component', () => { expect(listener).toHaveBeenCalled(); }); - it('emits UserFocusedSearchBox if input autofocus true', async () => { + it('emits UserFocusedSearchBox if input autofocus true', () => { const { listener } = renderSearchInput({ autofocus: true }); XPlugin.bus.on('UserFocusedSearchBox').subscribe(listener); expect(listener).toHaveBeenCalledTimes(1); expect(listener).toHaveBeenCalledWith(undefined); }); - it('does not emit UserFocusedSearchBox when mounting if autofocus is false', async () => { + it('does not emit UserFocusedSearchBox when mounting if autofocus is false', () => { const { listener } = renderSearchInput({ autofocus: false }); XPlugin.bus.on('UserFocusedSearchBox').subscribe(listener); expect(listener).not.toHaveBeenCalled(); @@ -197,7 +197,7 @@ describe('testing search input component', () => { } ); - it('focus the input when UserPressedClearSearchBoxButton event is emitted', async () => { + it('focus the input when UserPressedClearSearchBoxButton event is emitted', () => { const { input } = renderSearchInput(); input.blur(); expect(input).not.toBe(document.activeElement); diff --git a/packages/x-components/src/x-modules/search/components/__tests__/partial-query-button.spec.ts b/packages/x-components/src/x-modules/search/components/__tests__/partial-query-button.spec.ts index 5e25e577aa..53d65c94cd 100644 --- a/packages/x-components/src/x-modules/search/components/__tests__/partial-query-button.spec.ts +++ b/packages/x-components/src/x-modules/search/components/__tests__/partial-query-button.spec.ts @@ -31,9 +31,7 @@ function renderPartialQueryButton({ return { partialQueryButtonWrapper, - async click() { - await wrapper.trigger('click'); - } + click: async () => await wrapper.trigger('click') }; } diff --git a/packages/x-components/src/x-modules/search/components/__tests__/partial-results-list.spec.ts b/packages/x-components/src/x-modules/search/components/__tests__/partial-results-list.spec.ts index d55f5c9f9c..b6bf8ea4eb 100644 --- a/packages/x-components/src/x-modules/search/components/__tests__/partial-results-list.spec.ts +++ b/packages/x-components/src/x-modules/search/components/__tests__/partial-results-list.spec.ts @@ -1,11 +1,10 @@ -import { PartialResult } from '@empathyco/x-types'; import { DeepPartial } from '@empathyco/x-utils'; import { mount } from '@vue/test-utils'; import { Store } from 'vuex'; import { nextTick } from 'vue'; -import { getPartialResultsStub } from '../../../../__stubs__/partials-results-stubs.factory'; -import { getXComponentXModuleName, isXComponent } from '../../../../components/x-component.utils'; -import { RootXStoreState } from '../../../../store/store.types'; +import { getPartialResultsStub } from '../../../../__stubs__'; +import { getXComponentXModuleName, isXComponent } from '../../../../components'; +import { RootXStoreState } from '../../../../store'; import { getDataTestSelector, installNewXPlugin } from '../../../../__tests__/utils'; import PartialResultsList from '../partial-results-list.vue'; import { searchXModule } from '../../x-module'; @@ -20,7 +19,7 @@ import { resetXSearchStateWith } from './utils'; function renderPartialResultsList({ template = '', partialResults = getPartialResultsStub() -}: RenderPartialResultsListOptions = {}) { +} = {}) { const store = new Store>({}); const wrapper = mount( @@ -44,9 +43,7 @@ function renderPartialResultsList({ return { partialResultsListWrapper, - getPartialResults() { - return partialResults; - } + getPartialResults: () => partialResults }; } describe('testing Partial results list component', () => { @@ -88,18 +85,11 @@ describe('testing Partial results list component', () => { await nextTick(); - expect(partialResultsListWrapper.find(getDataTestSelector('partial-results')).exists()).toBe( + expect(partialResultsListWrapper.find(getDataTestSelector('partial-results')).exists()).toEqual( true ); expect( partialResultsListWrapper.find(getDataTestSelector('partial-slot-overridden')).exists() - ).toBe(true); + ).toEqual(true); }); }); - -interface RenderPartialResultsListOptions { - /** The template to be rendered. */ - template?: string; - /** The `partialResults` to be rendered. */ - partialResults?: PartialResult[]; -} diff --git a/packages/x-components/src/x-modules/search/components/__tests__/redirection.spec.ts b/packages/x-components/src/x-modules/search/components/__tests__/redirection.spec.ts index 781605a836..b305f01a29 100644 --- a/packages/x-components/src/x-modules/search/components/__tests__/redirection.spec.ts +++ b/packages/x-components/src/x-modules/search/components/__tests__/redirection.spec.ts @@ -1,15 +1,16 @@ import { Store } from 'vuex'; import { Redirection as RedirectionModel } from '@empathyco/x-types'; -import { DOMWrapper, mount } from '@vue/test-utils'; +import { mount } from '@vue/test-utils'; import { DeepPartial } from '@empathyco/x-utils'; import { nextTick } from 'vue'; -import { createRedirectionStub } from '../../../../__stubs__/redirections-stubs.factory'; +import { createRedirectionStub, getEmptySearchResponseStub } from '../../../../__stubs__'; +import { XComponentsAdapterDummy } from '../../../../__tests__/adapter.dummy'; import { getDataTestSelector, installNewXPlugin } from '../../../../__tests__/utils'; -import { getXComponentXModuleName, isXComponent } from '../../../../components/x-component.utils'; -import { XPlugin } from '../../../../plugins/x-plugin'; -import { WirePayload } from '../../../../wiring/wiring.types'; +import { getXComponentXModuleName, isXComponent } from '../../../../components'; +import { XPlugin } from '../../../../plugins'; +import { WirePayload } from '../../../../wiring'; import Redirection from '../redirection.vue'; -import { RootXStoreState } from '../../../../store/index'; +import { RootXStoreState } from '../../../../store'; import { XDummyBus } from '../../../../__tests__/bus.dummy'; import { searchXModule } from '../../x-module'; import { resetXSearchStateWith } from './utils'; @@ -32,21 +33,17 @@ function renderRedirection({ delayInSeconds = 1 } = {}) { const store = new Store>({}); + (XComponentsAdapterDummy.search as jest.Mock).mockResolvedValueOnce({ + ...getEmptySearchResponseStub() + }); const wrapper = mount( { - components: { - Redirection - }, + components: { Redirection }, template }, { - data() { - return { - mode, - delayInSeconds - }; - }, + data: () => ({ mode, delayInSeconds }), global: { plugins: [installNewXPlugin({ store, initialXModules: [searchXModule] }, bus)] } @@ -62,11 +59,11 @@ function renderRedirection({ return { wrapper: wrapper.findComponent(Redirection), - acceptRedirection: () => { - (wrapper.find(getDataTestSelector('redirection-accept')) as DOMWrapper).element.click(); + acceptRedirection: async () => { + await wrapper.find(getDataTestSelector('redirection-accept')).trigger('click'); }, - abortRedirection: () => { - (wrapper.find(getDataTestSelector('redirection-abort')) as DOMWrapper).element.click(); + abortRedirection: async () => { + await wrapper.find(getDataTestSelector('redirection-abort')).trigger('click'); }, onUserClickedARedirection, onUserAbortedARedirection @@ -125,14 +122,11 @@ describe('testing Redirection component', () => { ); }); - //eslint-disable-next-line max-len it('redirects and emits the `UserClickedARedirection` event in manual mode when the user click the button', async () => { - // eslint-disable-next-line @typescript-eslint/unbound-method const { onUserClickedARedirection, acceptRedirection } = renderRedirection({ mode: 'manual' }); await nextTick(); - - acceptRedirection(); + await acceptRedirection(); expect(onUserClickedARedirection).toHaveBeenCalledTimes(1); expect(onUserClickedARedirection).toHaveBeenCalledWith<[WirePayload]>({ @@ -147,7 +141,6 @@ describe('testing Redirection component', () => { expect(spy).toHaveBeenCalledWith(stubRedirections[0].url); }); - //eslint-disable-next-line max-len it("doesn't redirect and doesn't emit the event `UserClickedARedirection` in manual when the user doesn't click the button", () => { const { onUserClickedARedirection } = renderRedirection({ mode: 'manual' }); @@ -157,12 +150,11 @@ describe('testing Redirection component', () => { expect(spy).not.toHaveBeenCalled(); }); - //eslint-disable-next-line max-len it('redirects and emits the `UserClickedARedirection` event in auto mode and 0 seconds of delay', async () => { const { onUserClickedARedirection } = renderRedirection({ delayInSeconds: 0 }); await nextTick(); - // The delay 0 runs so fast the we need to force the test to simulate a wait. + // The delay 0 runs so fast, we need to force the test to simulate a wait. jest.advanceTimersByTime(1); expect(onUserClickedARedirection).toHaveBeenCalledTimes(1); @@ -179,13 +171,11 @@ describe('testing Redirection component', () => { }); it('emits the redirection event `UserClickedAbortARedirection`', async () => { - // eslint-disable-next-line @typescript-eslint/unbound-method const { onUserClickedARedirection, onUserAbortedARedirection, abortRedirection } = renderRedirection(); await nextTick(); - - abortRedirection(); + await abortRedirection(); jest.runAllTicks(); expect(onUserClickedARedirection).not.toHaveBeenCalled(); @@ -193,7 +183,6 @@ describe('testing Redirection component', () => { expect(spy).not.toHaveBeenCalled(); }); - //eslint-disable-next-line max-len it("doesn't redirect and doesn't emit the `UserClickedARedirection` event if there is a new query accepted", () => { const { onUserClickedARedirection } = renderRedirection(); XPlugin.bus.emit('UserAcceptedAQuery', 'lego'); diff --git a/packages/x-components/src/x-modules/url/store/__tests__/utils.ts b/packages/x-components/src/x-modules/url/store/__tests__/utils.ts index e38a2e9d0a..dd39d10aa6 100644 --- a/packages/x-components/src/x-modules/url/store/__tests__/utils.ts +++ b/packages/x-components/src/x-modules/url/store/__tests__/utils.ts @@ -26,6 +26,7 @@ export function resetUrlStateWith(store: Store, state?: DeepPartial): Store { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const store = new Store(urlXStoreModule as any); resetUrlStateWith(store, state); return store; diff --git a/packages/x-components/tests/unit/base-events-modal.spec.ts b/packages/x-components/tests/unit/base-events-modal.spec.ts index 5318847906..f35b78c201 100644 --- a/packages/x-components/tests/unit/base-events-modal.spec.ts +++ b/packages/x-components/tests/unit/base-events-modal.spec.ts @@ -1,5 +1,4 @@ import { mount } from 'cypress/vue2'; -import Vue from 'vue'; import BaseEventsModalClose from '../../src/components/modals/base-events-modal-close.vue'; import BaseEventsModalOpen from '../../src/components/modals/base-events-modal-open.vue'; import BaseEventsModal from '../../src/components/modals/base-events-modal.vue'; @@ -39,7 +38,6 @@ function mountBaseEventsModal({ ` }, { - vue: Vue.extend({}), plugins: [[new XPlugin(new XDummyBus()), { adapter: e2eAdapter }]], propsData: { bodyClickEvent, eventsToCloseModal, eventsToOpenModal } } diff --git a/packages/x-components/tests/unit/base-grid.spec.ts b/packages/x-components/tests/unit/base-grid.spec.ts index 5d9d155f44..5301fd62ed 100644 --- a/packages/x-components/tests/unit/base-grid.spec.ts +++ b/packages/x-components/tests/unit/base-grid.spec.ts @@ -1,5 +1,4 @@ import { mount } from 'cypress/vue2'; -import Vue from 'vue'; import { getNextQueriesStub, getSearchResponseStub } from '../../src/__stubs__'; import BaseGrid from '../../src/components/base-grid.vue'; import { XPlugin } from '../../src/plugins/x-plugin'; @@ -64,7 +63,6 @@ function renderBaseGrid({ } }, { - vue: Vue.extend({}), plugins: [[new XPlugin(new XDummyBus()), { adapter: e2eAdapter }]], propsData: { items: items ?? defaultItems, diff --git a/packages/x-components/tests/unit/base-modal.spec.ts b/packages/x-components/tests/unit/base-modal.spec.ts index bbb6e8471b..fc198eed95 100644 --- a/packages/x-components/tests/unit/base-modal.spec.ts +++ b/packages/x-components/tests/unit/base-modal.spec.ts @@ -1,5 +1,4 @@ import { mount } from 'cypress/vue2'; -import Vue from 'vue'; import BaseModal from '../../src/components/modals/base-modal.vue'; import { XPlugin } from '../../src/plugins/x-plugin'; import { e2eAdapter } from '../../src/adapter/e2e-adapter'; @@ -55,7 +54,6 @@ function renderBaseModal({ props: ['referenceSelector'] }, { - vue: Vue.extend({}), plugins: [[new XPlugin(new XDummyBus()), { adapter: e2eAdapter }]], propsData: { referenceSelector diff --git a/packages/x-components/tests/unit/main-scroll.spec.ts b/packages/x-components/tests/unit/main-scroll.spec.ts index b3f99e43c7..fc114c2d71 100644 --- a/packages/x-components/tests/unit/main-scroll.spec.ts +++ b/packages/x-components/tests/unit/main-scroll.spec.ts @@ -1,5 +1,4 @@ import { mount } from 'cypress/vue2'; -import Vue from 'vue'; import StaggeredFadeAndSlide from '../../src/components/animations/staggered-fade-and-slide.vue'; import { XPlugin } from '../../src/plugins/x-plugin'; import { UrlParams } from '../../src/types/url-params'; @@ -95,7 +94,6 @@ function renderMainScroll({ } }, { - vue: Vue.extend({}), plugins: [ [new XPlugin(new XDummyBus()), { adapter: e2eAdapter, initialXModules: [scrollXModule] }] ] diff --git a/packages/x-components/tests/unit/search-input.spec.ts b/packages/x-components/tests/unit/search-input.spec.ts index 4f43c4ca63..2b732b7013 100644 --- a/packages/x-components/tests/unit/search-input.spec.ts +++ b/packages/x-components/tests/unit/search-input.spec.ts @@ -1,5 +1,4 @@ import { mount } from 'cypress/vue2'; -import Vue from 'vue'; import { XPlugin } from '../../src/plugins/x-plugin'; import { e2eAdapter } from '../../src/adapter/e2e-adapter'; import SearchInput from '../../src/x-modules/search-box/components/search-input.vue'; @@ -23,7 +22,6 @@ function mountSearchInput(): MountSearchInputAPI { ` }, { - vue: Vue.extend({}), plugins: [ [new XPlugin(new XDummyBus()), { adapter: e2eAdapter, initialXModules: [searchBoxXModule] }] ] diff --git a/packages/x-components/tests/unit/sliding-panel.spec.ts b/packages/x-components/tests/unit/sliding-panel.spec.ts index 3f1ec3143a..644da3daaa 100644 --- a/packages/x-components/tests/unit/sliding-panel.spec.ts +++ b/packages/x-components/tests/unit/sliding-panel.spec.ts @@ -1,5 +1,4 @@ import { mount } from 'cypress/vue2'; -import Vue from 'vue'; import SlidingPanel from '../../src/components/sliding-panel.vue'; import { XPlugin } from '../../src/plugins/x-plugin'; import { e2eAdapter } from '../../src/adapter/e2e-adapter'; @@ -67,7 +66,6 @@ function renderSlidingPanel({ } }, { - vue: Vue.extend({}), plugins: [[new XPlugin(new XDummyBus()), { adapter: e2eAdapter }]], propsData: { scrollFactor,