From 5c2b7bcf47281f9a3bb2ea65a1bfb73c6d850260 Mon Sep 17 00:00:00 2001
From: Andrea Delgado <114981520+andreadlgdo@users.noreply.github.com>
Date: Thu, 23 May 2024 16:00:49 +0200
Subject: [PATCH] feat(search-box): migrate search-box x-module components to
Composition API (#1476)
---
packages/_vue3-migration-test/src/router.ts | 8 +-
.../src/x-modules/index.ts | 1 +
.../x-modules/search-box/components/index.ts | 1 +
.../search-box/components/test-search-box.vue | 43 ++
.../src/x-modules/search-box/index.ts | 1 +
.../composables/__tests__/use-state.spec.ts | 103 ++--
.../components/__tests__/search-input.spec.ts | 4 +-
.../components/clear-search-input.vue | 55 +--
.../search-box/components/search-button.vue | 89 ++--
.../components/search-input-placeholder.vue | 386 +++++++--------
.../search-box/components/search-input.vue | 449 +++++++++---------
11 files changed, 602 insertions(+), 538 deletions(-)
create mode 100644 packages/_vue3-migration-test/src/x-modules/search-box/components/index.ts
create mode 100644 packages/_vue3-migration-test/src/x-modules/search-box/components/test-search-box.vue
create mode 100644 packages/_vue3-migration-test/src/x-modules/search-box/index.ts
diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts
index aa225fbdbe..743e969b07 100644
--- a/packages/_vue3-migration-test/src/router.ts
+++ b/packages/_vue3-migration-test/src/router.ts
@@ -15,7 +15,8 @@ import {
TestSortDropdown,
TestSortList,
TestSortPickerList,
- TestBaseScroll
+ TestBaseScroll,
+ TestSearchBox
} from './';
const routes = [
@@ -94,6 +95,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 @@
+
+
+ {{ value }}
+
+ {{ hasFocus ? 'Focused' : 'Unfocused' }}
+
+
+
+
+
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/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: `