forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request galaxyproject#17119 from davelopez/migrate_job_des…
…tination_params_store_pinia Migrate job destination parameters store to Pinia
- Loading branch information
Showing
8 changed files
with
142 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { fetcher } from "@/api/schema"; | ||
import { components, fetcher } from "@/api/schema"; | ||
|
||
export type JobDestinationParams = components["schemas"]["JobDestinationParams"]; | ||
|
||
export const jobLockStatus = fetcher.path("/api/job_lock").method("get").create(); | ||
export const jobLockUpdate = fetcher.path("/api/job_lock").method("put").create(); | ||
|
||
export const fetchJobDestinationParams = fetcher.path("/api/jobs/{job_id}/destination_params").method("get").create(); |
80 changes: 0 additions & 80 deletions
80
client/src/components/JobDestinationParams/JobDestinationParams.test.js
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
client/src/components/JobDestinationParams/JobDestinationParams.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { shallowMount } from "@vue/test-utils"; | ||
import flushPromises from "flush-promises"; | ||
import { createPinia } from "pinia"; | ||
import { getLocalVue } from "tests/jest/helpers"; | ||
|
||
import { mockFetcher } from "@/api/schema/__mocks__"; | ||
import { useUserStore } from "@/stores/userStore"; | ||
|
||
import jobDestinationResponseData from "./testData/jobDestinationResponse.json"; | ||
|
||
import JobDestinationParams from "./JobDestinationParams.vue"; | ||
|
||
const JOB_ID = "foo_job_id"; | ||
|
||
jest.mock("@/api/schema"); | ||
|
||
const localVue = getLocalVue(); | ||
|
||
const jobDestinationResponse = jobDestinationResponseData as Record<string, string | null>; | ||
|
||
async function mountJobDestinationParams() { | ||
mockFetcher.path("/api/jobs/{job_id}/destination_params").method("get").mock({ data: jobDestinationResponse }); | ||
|
||
const pinia = createPinia(); | ||
const wrapper = shallowMount(JobDestinationParams as object, { | ||
propsData: { | ||
jobId: JOB_ID, | ||
}, | ||
localVue, | ||
pinia, | ||
}); | ||
|
||
const userStore = useUserStore(); | ||
userStore.currentUser = { | ||
email: "admin@email", | ||
id: "1", | ||
tags_used: [], | ||
isAnonymous: false, | ||
total_disk_usage: 1048576, | ||
is_admin: true, | ||
}; | ||
|
||
await flushPromises(); | ||
|
||
return wrapper; | ||
} | ||
|
||
describe("JobDestinationParams/JobDestinationParams.vue", () => { | ||
const responseKeys = Object.keys(jobDestinationResponse); | ||
expect(responseKeys.length > 0).toBeTruthy(); | ||
|
||
it("should render destination parameters", async () => { | ||
const wrapper = await mountJobDestinationParams(); | ||
|
||
const paramsTable = wrapper.find("#destination_parameters"); | ||
expect(paramsTable.exists()).toBe(true); | ||
const params = paramsTable.findAll("tbody > tr"); | ||
expect(params.length).toBe(responseKeys.length); | ||
|
||
for (let counter = 0; counter < responseKeys.length - 1; counter++) { | ||
const parameter = params.at(counter).findAll("td"); | ||
const parameterTitle = parameter.at(0).text(); | ||
const parameterValue = parameter.at(1).text(); | ||
|
||
expect(responseKeys.includes(parameterTitle)).toBeTruthy(); | ||
// since we render null as an empty string, rendered empty string should always equal null in test data | ||
expect( | ||
jobDestinationResponse[parameterTitle] === (parameterValue === "" ? null : parameterValue) | ||
).toBeTruthy(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { defineStore } from "pinia"; | ||
import { computed, del, ref, set } from "vue"; | ||
|
||
import { fetchJobDestinationParams, type JobDestinationParams } from "@/api/jobs"; | ||
|
||
export const useJobDestinationParametersStore = defineStore("jobDestinationParametersStore", () => { | ||
const storedJobDestinationParameters = ref<{ [key: string]: JobDestinationParams }>({}); | ||
const loadingParameters = ref<{ [key: string]: boolean }>({}); | ||
|
||
const getJobDestinationParams = computed(() => { | ||
return (jobId: string) => { | ||
const destinationParams = storedJobDestinationParameters.value[jobId]; | ||
if (!destinationParams && !loadingParameters.value[jobId]) { | ||
fetchJobDestinationParamsByJobId({ id: jobId }); | ||
} | ||
return destinationParams ?? null; | ||
}; | ||
}); | ||
|
||
const isLoadingJobDestinationParams = computed(() => { | ||
return (jobId: string) => { | ||
return loadingParameters.value[jobId] ?? false; | ||
}; | ||
}); | ||
|
||
async function fetchJobDestinationParamsByJobId(params: { id: string }) { | ||
const jobId = params.id; | ||
set(loadingParameters.value, jobId, true); | ||
try { | ||
const { data: destinationParams } = await fetchJobDestinationParams({ job_id: jobId }); | ||
set(storedJobDestinationParameters.value, jobId, destinationParams); | ||
return destinationParams; | ||
} finally { | ||
del(loadingParameters.value, jobId); | ||
} | ||
} | ||
|
||
return { | ||
storedJobDestinationParameters, | ||
getJobDestinationParams, | ||
isLoadingJobDestinationParams, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters