diff --git a/packages/_vue3-migration-test/CHANGELOG.md b/packages/_vue3-migration-test/CHANGELOG.md index f09f763026..7bfa46f1bb 100644 --- a/packages/_vue3-migration-test/CHANGELOG.md +++ b/packages/_vue3-migration-test/CHANGELOG.md @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.0.0-alpha.12](https://github.com/empathyco/x/compare/vue3-migration-test@1.0.0-alpha.11...vue3-migration-test@1.0.0-alpha.12) (2024-05-23) + + +### Features + +* **search-box:** migrate search-box x-module components to Composition API (#1476) ([5c2b7bc](https://github.com/empathyco/x/commit/5c2b7bcf47281f9a3bb2ea65a1bfb73c6d850260)) + + + ## [1.0.0-alpha.11](https://github.com/empathyco/x/compare/vue3-migration-test@1.0.0-alpha.10...vue3-migration-test@1.0.0-alpha.11) (2024-05-21) diff --git a/packages/_vue3-migration-test/package.json b/packages/_vue3-migration-test/package.json index d684a1a0a3..657f9d9cdf 100644 --- a/packages/_vue3-migration-test/package.json +++ b/packages/_vue3-migration-test/package.json @@ -1,7 +1,7 @@ { "name": "vue3-migration-test", "private": "true", - "version": "1.0.0-alpha.11", + "version": "1.0.0-alpha.12", "scripts": { "dev": "vite", "preview": "vite preview", diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts index 07b1354469..7b18435b34 100644 --- a/packages/_vue3-migration-test/src/router.ts +++ b/packages/_vue3-migration-test/src/router.ts @@ -16,6 +16,7 @@ import { TestSortList, TestSortPickerList, TestBaseScroll, + TestSearchBox, TestLayoutsComposable } from './'; @@ -95,6 +96,11 @@ const routes = [ name: 'SortPickerList', component: TestSortPickerList }, + { + path: '/search-box', + name: 'SearchBox', + component: TestSearchBox + }, { path: '/elements-list', name: 'ElementsList', diff --git a/packages/_vue3-migration-test/src/x-modules/index.ts b/packages/_vue3-migration-test/src/x-modules/index.ts index 5c28632c91..821c5f1a14 100644 --- a/packages/_vue3-migration-test/src/x-modules/index.ts +++ b/packages/_vue3-migration-test/src/x-modules/index.ts @@ -1,5 +1,6 @@ export * from './facets'; export * from './next-queries'; export * from './search'; +export * from './search-box'; export { default as TestElementsList } from './test-elements-list.vue'; export * from './scroll'; diff --git a/packages/_vue3-migration-test/src/x-modules/search-box/components/index.ts b/packages/_vue3-migration-test/src/x-modules/search-box/components/index.ts new file mode 100644 index 0000000000..6e6ca5ee85 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/search-box/components/index.ts @@ -0,0 +1 @@ +export { default as TestSearchBox } from './test-search-box.vue'; diff --git a/packages/_vue3-migration-test/src/x-modules/search-box/components/test-search-box.vue b/packages/_vue3-migration-test/src/x-modules/search-box/components/test-search-box.vue new file mode 100644 index 0000000000..af6aa0caf8 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/search-box/components/test-search-box.vue @@ -0,0 +1,43 @@ + + + + + diff --git a/packages/_vue3-migration-test/src/x-modules/search-box/index.ts b/packages/_vue3-migration-test/src/x-modules/search-box/index.ts new file mode 100644 index 0000000000..07635cbbc8 --- /dev/null +++ b/packages/_vue3-migration-test/src/x-modules/search-box/index.ts @@ -0,0 +1 @@ +export * from './components'; diff --git a/packages/x-components/CHANGELOG.md b/packages/x-components/CHANGELOG.md index f4a1eef927..f0a0b0882f 100644 --- a/packages/x-components/CHANGELOG.md +++ b/packages/x-components/CHANGELOG.md @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.0.0-alpha.18](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.17...@empathyco/x-components@5.0.0-alpha.18) (2024-05-23) + + +### Features + +* **search-box:** migrate search-box x-module components to Composition API (#1476) ([5c2b7bc](https://github.com/empathyco/x/commit/5c2b7bcf47281f9a3bb2ea65a1bfb73c6d850260)) + + + ## [5.0.0-alpha.17](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.16...@empathyco/x-components@5.0.0-alpha.17) (2024-05-22) diff --git a/packages/x-components/package.json b/packages/x-components/package.json index 59d054ac55..7ae11d3145 100644 --- a/packages/x-components/package.json +++ b/packages/x-components/package.json @@ -1,6 +1,6 @@ { "name": "@empathyco/x-components", - "version": "5.0.0-alpha.17", + "version": "5.0.0-alpha.18", "description": "Empathy X Components", "author": "Empathy Systems Corporation S.L.", "license": "Apache-2.0", diff --git a/packages/x-components/src/composables/__tests__/use-state.spec.ts b/packages/x-components/src/composables/__tests__/use-state.spec.ts index 508610f9ba..771870e030 100644 --- a/packages/x-components/src/composables/__tests__/use-state.spec.ts +++ b/packages/x-components/src/composables/__tests__/use-state.spec.ts @@ -1,75 +1,54 @@ -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 { useState } from '../use-state'; -import { searchBoxXStoreModule } from '../../x-modules/search-box/index'; -import { AnyXStoreModule } from '../../store/index'; +import { XPlugin } from '../../plugins'; import { ExtractState } from '../../x-modules/x-modules.types'; - -const renderUseStateTest = (modulePropertyPaths: string[]): renderUseStateTestAPI => { - const testComponent = defineComponent({ - setup() { - const searchBoxState = useState( - 'searchBox', - modulePropertyPaths as (keyof ExtractState<'searchBox'>)[] - ); - return { - searchBoxState - }; - } - }); - - const localVue = createLocalVue(); - localVue.use(Vuex); - - const store = new Store({ - modules: { - x: { - namespaced: true, - modules: { - searchBox: { namespaced: true, ...searchBoxXStoreModule } as AnyXStoreModule - } - } - } +import { useRegisterXModule } from '../use-register-x-module'; +import { useState } from '../use-state'; +import { searchBoxXModule } from '../../x-modules/search-box/x-module'; +import { useStore } from '../use-store'; + +jest.mock('../use-store'); + +function render(modulePaths: (keyof ExtractState<'searchBox'> & string)[]) { + installNewXPlugin(); + (useStore as jest.Mock).mockReturnValue(XPlugin.store); + + const component = defineComponent({ + xModule: 'searchBox', + setup: () => { + useRegisterXModule(searchBoxXModule); + const searchBoxUseState = useState('searchBox', modulePaths); + return { searchBoxUseState }; + }, + template: `
` }); - installNewXPlugin({ store }, localVue); - const wrapper = mount(testComponent, { - localVue, - store - }); + const wrapper = mount(component); - return { - searchBoxState: (wrapper.vm as any).searchBoxState, - store - }; -}; + return (wrapper as any).vm.searchBoxUseState; +} describe('testing useState composable', () => { - it('maps store state', () => { - const { searchBoxState, store } = renderUseStateTest(['query', 'inputStatus']); - expect(searchBoxState.query.value).toEqual(''); - expect(searchBoxState.inputStatus.value).toEqual('initial'); + it('should map paths of the store state given', () => { + const { query, inputStatus } = render(['query', 'inputStatus']); + + expect(query).toBeDefined(); + expect(inputStatus).toBeDefined(); + expect(query.value).toEqual(''); + expect(inputStatus.value).toEqual('initial'); - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - store.commit('x/searchBox/setQuery', 'pork shoulder '); - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - store.commit('x/searchBox/setInputStatus', 'filled'); + XPlugin.store.commit('x/searchBox/setQuery', 'pork shoulder'); + XPlugin.store.commit('x/searchBox/setInputStatus', 'filled'); - expect(searchBoxState.query.value).toEqual('pork shoulder '); - expect(searchBoxState.inputStatus.value).toEqual('filled'); + expect(query.value).toEqual('pork shoulder'); + expect(inputStatus.value).toEqual('filled'); }); - it('does not return not requested state properties', () => { - const { searchBoxState } = renderUseStateTest(['query']); - expect(searchBoxState.query).toBeDefined(); - expect(searchBoxState.inputStatus).toBeUndefined(); + it('should not map paths which were not requested', () => { + const { query, inputStatus } = render(['query']); + + expect(query).toBeDefined(); + expect(inputStatus).toBeUndefined(); }); }); - -type renderUseStateTestAPI = { - searchBoxState: Dictionary>; - store: Store; -}; 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 a02f2c277c..c5de8dd521 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 @@ -3,7 +3,7 @@ import { createLocalVue, mount, Wrapper } from '@vue/test-utils'; import Vuex, { Store } from 'vuex'; import { getXComponentXModuleName, isXComponent } from '../../../../components/x-component.utils'; import { RootXStoreState } from '../../../../store/store.types'; -import { installNewXPlugin } from '../../../../__tests__/utils'; +import { getDataTestSelector, installNewXPlugin } from '../../../../__tests__/utils'; import { WireMetadata } from '../../../../wiring/wiring.types'; import SearchInput from '../search-input.vue'; import { resetXSearchBoxStateWith } from './utils'; @@ -28,7 +28,7 @@ function mountNewSearchInput(overrideProps: Partial = {}): Tes localVue, propsData: overrideProps }); - const input = wrapper.vm.$refs.input as HTMLInputElement; + const input = wrapper.find(getDataTestSelector('search-input')).element as HTMLInputElement; return { wrapper, diff --git a/packages/x-components/src/x-modules/search-box/components/clear-search-input.vue b/packages/x-components/src/x-modules/search-box/components/clear-search-input.vue index 2bd477d8a9..d1be96646c 100644 --- a/packages/x-components/src/x-modules/search-box/components/clear-search-input.vue +++ b/packages/x-components/src/x-modules/search-box/components/clear-search-input.vue @@ -11,13 +11,11 @@ diff --git a/packages/x-components/src/x-modules/search-box/components/search-button.vue b/packages/x-components/src/x-modules/search-box/components/search-button.vue index 35ed38f6d7..9b8ba21d96 100644 --- a/packages/x-components/src/x-modules/search-box/components/search-button.vue +++ b/packages/x-components/src/x-modules/search-box/components/search-button.vue @@ -1,5 +1,6 @@