From 22e10c234044e9f60955d35baad2ac1ab42614e7 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Thu, 17 Nov 2022 17:16:50 +0100 Subject: [PATCH 1/4] unify composable naming --- client/src/components/AboutGalaxy.vue | 2 +- client/src/components/Panels/Common/ToolSection.test.js | 4 ++-- client/src/components/Panels/Common/ToolSection.vue | 2 +- client/src/components/Tool/ToolSourceMenuItem.vue | 2 +- .../Workflow/Invocation/Export/ExportToRemoteButton.vue | 2 +- .../Workflow/Invocation/Export/InvocationExportPluginCard.vue | 2 +- client/src/composables/{useConfig.js => config.js} | 0 client/src/composables/{useMarkdown.js => markdown.js} | 0 .../src/composables/{useMarkdown.test.js => markdown.test.js} | 2 +- client/src/composables/{useTaskMonitor.js => taskMonitor.js} | 0 .../{useTaskMonitor.test.js => taskMonitor.test.js} | 2 +- 11 files changed, 9 insertions(+), 9 deletions(-) rename client/src/composables/{useConfig.js => config.js} (100%) rename client/src/composables/{useMarkdown.js => markdown.js} (100%) rename client/src/composables/{useMarkdown.test.js => markdown.test.js} (94%) rename client/src/composables/{useTaskMonitor.js => taskMonitor.js} (100%) rename client/src/composables/{useTaskMonitor.test.js => taskMonitor.test.js} (97%) diff --git a/client/src/components/AboutGalaxy.vue b/client/src/components/AboutGalaxy.vue index 0337f516326..0555f27fc5c 100644 --- a/client/src/components/AboutGalaxy.vue +++ b/client/src/components/AboutGalaxy.vue @@ -5,7 +5,7 @@ import { computed } from "vue"; import { getAppRoot } from "onload/loadConfig"; -import { useConfig } from "composables/useConfig"; +import { useConfig } from "composables/config"; import UtcDate from "components/UtcDate"; import License from "components/License/License"; import ExternalLink from "components/ExternalLink"; diff --git a/client/src/components/Panels/Common/ToolSection.test.js b/client/src/components/Panels/Common/ToolSection.test.js index 864df3405bb..04e0dca33ac 100644 --- a/client/src/components/Panels/Common/ToolSection.test.js +++ b/client/src/components/Panels/Common/ToolSection.test.js @@ -2,9 +2,9 @@ import { mount } from "@vue/test-utils"; import { getLocalVue } from "jest/helpers"; import ToolSection from "./ToolSection"; -import { useConfig } from "composables/useConfig"; +import { useConfig } from "composables/config"; -jest.mock("composables/useConfig"); +jest.mock("composables/config"); useConfig.mockReturnValue({ config: { toolbox_auto_sort: true, diff --git a/client/src/components/Panels/Common/ToolSection.vue b/client/src/components/Panels/Common/ToolSection.vue index 8799d1235a7..f02fc438f18 100644 --- a/client/src/components/Panels/Common/ToolSection.vue +++ b/client/src/components/Panels/Common/ToolSection.vue @@ -53,7 +53,7 @@ import ToolPanelLabel from "./ToolPanelLabel"; import ariaAlert from "utils/ariaAlert"; import ToolPanelLinks from "./ToolPanelLinks"; -import { useConfig } from "composables/useConfig"; +import { useConfig } from "composables/config"; export default { name: "ToolSection", diff --git a/client/src/components/Tool/ToolSourceMenuItem.vue b/client/src/components/Tool/ToolSourceMenuItem.vue index def1e910370..d774c2c58eb 100644 --- a/client/src/components/Tool/ToolSourceMenuItem.vue +++ b/client/src/components/Tool/ToolSourceMenuItem.vue @@ -1,6 +1,6 @@ +``` + +You can now access the current user with `currentUser.value`. + +## Using Composables in the Options API + +Composables are not limited to the composition api. This is the same example from above, using the options api. + +```vue + +``` + +You can now access the current user with `this.currentUser` from anywhere within the component. + +## Testing Components with Composable Stores + +When writing a test which includes a component that has a composable store (like useCurrentUser), +there are two ways to test it. + +### Mocking the store + +You can provide the store in the mount function as follows: + +```js +const wrapper = shallowMount(TestedComponent, + localVue, + provide: { store }, +}); +``` + +`store` must be a Vuex store. +The `mockModule` helper can help creating a store for the required modules: + +```js +const store = new Vuex.Store({ + modules: { + user: mockModule(userStore), + }, +}); +``` + +### Mocking the composable + +The second option is to mock the composable: + +```js +import { useCurrentUser } from "composables/user"; + +jest.mock("composables/user"); +useCurrentUser.mockReturnValue({ + currentUser: {} +}); +``` + +While simpler in this example, you may need to manually mock more return values and composables than the other method, depending on the composables the component is using. + +## Using Composables for more than Stores + +Composables can be of great use to extract any reactive code from your components. For an example of this, take a look at [userFilterObjectArray](https://github.com/galaxyproject/galaxy/blob/dev/client/src/composables/utils/filter.js). + +Usage: + +```vue + +``` + +It's a simple filtering function, but fully reactive. +Whenever any of the inputs changes, the return value is re-computed, without having to call the function again. + +## Further Reading + +* [Composition API](https://vuejs.org/api/composition-api-setup.html) +* [\