diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts index fd15497d2e..73771ed41f 100644 --- a/packages/_vue3-migration-test/src/router.ts +++ b/packages/_vue3-migration-test/src/router.ts @@ -24,6 +24,8 @@ import { TestSlidingPanel, TestBaseSuggestions, TestHighlight, + TestHistoryQueries, + TestMyHistory, TestBaseResultImages, TestBasePanel, TestBaseKeyboardNavigation, @@ -153,6 +155,16 @@ const routes = [ name: 'Highlight', component: TestHighlight }, + { + path: '/history-queries', + name: 'HistoryQueries', + component: TestHistoryQueries + }, + { + path: '/my-history', + name: 'MyHistory', + component: TestMyHistory + }, { path: '/base-result-images', name: 'BaseResultImages', diff --git a/packages/_vue3-migration-test/src/x-modules/history-queries/components/index.ts b/packages/_vue3-migration-test/src/x-modules/history-queries/components/index.ts new file mode 100644 index 0000000000..b13804333c --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/history-queries/components/index.ts @@ -0,0 +1,2 @@ +export { default as TestHistoryQueries } from './test-history-queries.vue'; +export { default as TestMyHistory } from './test-my-history.vue'; diff --git a/packages/_vue3-migration-test/src/x-modules/history-queries/components/test-history-queries.vue b/packages/_vue3-migration-test/src/x-modules/history-queries/components/test-history-queries.vue new file mode 100644 index 0000000000..6d9928394e --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/history-queries/components/test-history-queries.vue @@ -0,0 +1,16 @@ + + + diff --git a/packages/_vue3-migration-test/src/x-modules/history-queries/components/test-my-history.vue b/packages/_vue3-migration-test/src/x-modules/history-queries/components/test-my-history.vue new file mode 100644 index 0000000000..bd1eea8d94 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/history-queries/components/test-my-history.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/packages/_vue3-migration-test/src/x-modules/history-queries/index.ts b/packages/_vue3-migration-test/src/x-modules/history-queries/index.ts new file mode 100644 index 0000000000..07635cbbc8 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/history-queries/index.ts @@ -0,0 +1 @@ +export * from './components'; diff --git a/packages/_vue3-migration-test/src/x-modules/index.ts b/packages/_vue3-migration-test/src/x-modules/index.ts index f84c5d1a78..c8a11f0237 100644 --- a/packages/_vue3-migration-test/src/x-modules/index.ts +++ b/packages/_vue3-migration-test/src/x-modules/index.ts @@ -5,3 +5,4 @@ export * from './search'; export * from './search-box'; export { default as TestElementsList } from './test-elements-list.vue'; export * from './scroll'; +export * from './history-queries'; diff --git a/packages/x-components/src/composables/__tests__/use-getter.spec.ts b/packages/x-components/src/composables/__tests__/use-getter.spec.ts index 804fbbd5e0..3c103d9160 100644 --- a/packages/x-components/src/composables/__tests__/use-getter.spec.ts +++ b/packages/x-components/src/composables/__tests__/use-getter.spec.ts @@ -1,72 +1,49 @@ -import { ComputedRef, defineComponent } from 'vue'; -import Vuex, { Store } from 'vuex'; -import { createLocalVue, mount } from '@vue/test-utils'; -import { Dictionary } from '@empathyco/x-utils'; +import { defineComponent } from 'vue'; +import { mount } from '@vue/test-utils'; import { installNewXPlugin } from '../../__tests__/utils'; import { useGetter } from '../use-getter'; -import { historyQueriesXStoreModule } from '../../x-modules/history-queries'; -import { AnyXStoreModule } from '../../store/index'; +import { useRegisterXModule } from '../use-register-x-module'; import { ExtractGetters } from '../../x-modules/x-modules.types'; - -const renderUseGetterTest = (getters: string[]): renderUseGetterTestAPI => { - const testComponent = defineComponent({ - setup() { - const historyQueriesGetter = useGetter( - 'historyQueries', - getters as (keyof ExtractGetters<'historyQueries'>)[] - ); - return { - historyQueriesGetter - }; - } - }); - - const localVue = createLocalVue(); - localVue.use(Vuex); - - const store = new Store({ - modules: { - x: { - namespaced: true, - modules: { - historyQueries: { namespaced: true, ...historyQueriesXStoreModule } as AnyXStoreModule - } - } - } +import { useStore } from '../use-store'; +import { XPlugin } from '../../plugins'; +import { historyQueriesXModule } from '../../x-modules/history-queries/x-module'; + +jest.mock('../use-store'); + +function render(modulePaths: (keyof ExtractGetters<'historyQueries'>)[]) { + installNewXPlugin(); + (useStore as jest.Mock).mockReturnValue(XPlugin.store); + + const component = defineComponent({ + xModule: 'historyQueries', + setup: () => { + useRegisterXModule(historyQueriesXModule); + const historyQueriesGetter = useGetter('historyQueries', modulePaths); + return { historyQueriesGetter }; + }, + template: `
` }); - installNewXPlugin({ store }, localVue); - const wrapper = mount(testComponent, { - localVue, - store - }); + const wrapper = mount(component); - return { - store, - historyQueriesGetter: (wrapper.vm as any).historyQueriesGetter - }; -}; + return (wrapper as any).vm.historyQueriesGetter; +} describe('testing useGetter composable', () => { it('maps store getters', () => { - const { historyQueriesGetter, store } = renderUseGetterTest(['storageKey', 'historyQueries']); - expect(historyQueriesGetter.storageKey.value).toEqual('history-queries'); - expect(historyQueriesGetter.historyQueries.value).toHaveLength(0); + const { storageKey, historyQueries } = render(['storageKey', 'historyQueries']); + expect(storageKey.value).toEqual('history-queries'); + expect(historyQueries.value).toHaveLength(0); // eslint-disable-next-line @typescript-eslint/no-unsafe-call - store.dispatch('x/historyQueries/addQueryToHistory', 'chorizo'); + XPlugin.store.dispatch('x/historyQueries/addQueryToHistory', 'chorizo'); - expect(historyQueriesGetter.historyQueries.value).toHaveLength(1); + expect(historyQueries.value).toHaveLength(1); }); it('does not return not requested getters', () => { - const { historyQueriesGetter } = renderUseGetterTest(['storageKey']); - expect(historyQueriesGetter.storageKey).toBeDefined(); - expect(historyQueriesGetter.historyQueries).toBeUndefined(); + const { storageKey, historyQueries } = render(['storageKey']); + expect(storageKey).toBeDefined(); + expect(historyQueries).toBeUndefined(); }); }); - -type renderUseGetterTestAPI = { - historyQueriesGetter: Dictionary>; - store: Store; -}; diff --git a/packages/x-components/src/x-modules/history-queries/components/clear-history-queries.vue b/packages/x-components/src/x-modules/history-queries/components/clear-history-queries.vue index dfa8de8c27..b30d3b6a6a 100644 --- a/packages/x-components/src/x-modules/history-queries/components/clear-history-queries.vue +++ b/packages/x-components/src/x-modules/history-queries/components/clear-history-queries.vue @@ -13,15 +13,12 @@ diff --git a/packages/x-components/src/x-modules/history-queries/components/history-queries-switch.vue b/packages/x-components/src/x-modules/history-queries/components/history-queries-switch.vue index f32ea08109..44026e2fc9 100644 --- a/packages/x-components/src/x-modules/history-queries/components/history-queries-switch.vue +++ b/packages/x-components/src/x-modules/history-queries/components/history-queries-switch.vue @@ -3,14 +3,13 @@ diff --git a/packages/x-components/src/x-modules/history-queries/components/history-queries.vue b/packages/x-components/src/x-modules/history-queries/components/history-queries.vue index fd5fd310a5..1243fc01f6 100644 --- a/packages/x-components/src/x-modules/history-queries/components/history-queries.vue +++ b/packages/x-components/src/x-modules/history-queries/components/history-queries.vue @@ -1,7 +1,7 @@ diff --git a/packages/x-components/src/x-modules/history-queries/components/history-query.vue b/packages/x-components/src/x-modules/history-queries/components/history-query.vue index 05736a0649..e3450665c0 100644 --- a/packages/x-components/src/x-modules/history-queries/components/history-query.vue +++ b/packages/x-components/src/x-modules/history-queries/components/history-query.vue @@ -40,14 +40,11 @@ diff --git a/packages/x-components/src/x-modules/history-queries/components/my-history.vue b/packages/x-components/src/x-modules/history-queries/components/my-history.vue index 8f7135c2ec..c789d4a3bd 100644 --- a/packages/x-components/src/x-modules/history-queries/components/my-history.vue +++ b/packages/x-components/src/x-modules/history-queries/components/my-history.vue @@ -57,18 +57,16 @@