-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #17616 from davelopez/23.2_fix_invocation_switch_t…
…o_history [23.2] Fix switch to history in invocations list
- Loading branch information
Showing
4 changed files
with
173 additions
and
21 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
client/src/components/History/SwitchToHistoryLink.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,100 @@ | ||
import { createTestingPinia } from "@pinia/testing"; | ||
import { getLocalVue } from "@tests/jest/helpers"; | ||
import { shallowMount } from "@vue/test-utils"; | ||
import axios from "axios"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import flushPromises from "flush-promises"; | ||
|
||
import { type HistorySummary } from "@/api"; | ||
|
||
import SwitchToHistoryLink from "./SwitchToHistoryLink.vue"; | ||
|
||
const localVue = getLocalVue(true); | ||
|
||
const selectors = { | ||
historyLink: ".history-link", | ||
} as const; | ||
|
||
function mountSwitchToHistoryLinkForHistory(history: HistorySummary) { | ||
const pinia = createTestingPinia(); | ||
|
||
const axiosMock = new MockAdapter(axios); | ||
axiosMock.onGet(`/api/histories/${history.id}`).reply(200, history); | ||
|
||
const wrapper = shallowMount(SwitchToHistoryLink as object, { | ||
propsData: { | ||
historyId: history.id, | ||
}, | ||
localVue, | ||
pinia, | ||
stubs: { | ||
FontAwesomeIcon: true, | ||
}, | ||
}); | ||
return wrapper; | ||
} | ||
|
||
async function expectOptionForHistory(option: string, history: HistorySummary) { | ||
const wrapper = mountSwitchToHistoryLinkForHistory(history); | ||
|
||
// Wait for the history to be loaded | ||
await flushPromises(); | ||
|
||
expect(wrapper.html()).toContain(option); | ||
expect(wrapper.text()).toContain(history.name); | ||
} | ||
|
||
describe("SwitchToHistoryLink", () => { | ||
it("loads the history information from the store", async () => { | ||
const history = { | ||
id: "history-id-to-load", | ||
name: "History Name", | ||
deleted: false, | ||
archived: false, | ||
purged: false, | ||
} as HistorySummary; | ||
const wrapper = mountSwitchToHistoryLinkForHistory(history); | ||
|
||
expect(wrapper.find(selectors.historyLink).exists()).toBe(false); | ||
expect(wrapper.html()).toContain("Loading"); | ||
|
||
// Wait for the history to be loaded | ||
await flushPromises(); | ||
|
||
expect(wrapper.find(selectors.historyLink).exists()).toBe(true); | ||
expect(wrapper.text()).toContain(history.name); | ||
}); | ||
|
||
it("should display the Switch option when the history can be switched to", async () => { | ||
const history = { | ||
id: "active-history-id", | ||
name: "History Active", | ||
deleted: false, | ||
purged: false, | ||
archived: false, | ||
} as HistorySummary; | ||
await expectOptionForHistory("Switch", history); | ||
}); | ||
|
||
it("should display the View option when the history is purged", async () => { | ||
const history = { | ||
id: "purged-history-id", | ||
name: "History Purged", | ||
deleted: false, | ||
purged: true, | ||
archived: false, | ||
} as HistorySummary; | ||
await expectOptionForHistory("View", history); | ||
}); | ||
|
||
it("should display the View option when the history is archived", async () => { | ||
const history = { | ||
id: "archived-history-id", | ||
name: "History Archived", | ||
deleted: false, | ||
purged: false, | ||
archived: true, | ||
} as HistorySummary; | ||
await expectOptionForHistory("View", history); | ||
}); | ||
}); |
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,69 @@ | ||
<script setup lang="ts"> | ||
import { library } from "@fortawesome/fontawesome-svg-core"; | ||
import { faArchive, faBurn } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; | ||
import { BLink } from "bootstrap-vue"; | ||
import { computed } from "vue"; | ||
import { useRouter } from "vue-router/composables"; | ||
import { HistorySummary } from "@/api"; | ||
import { useHistoryStore } from "@/stores/historyStore"; | ||
import LoadingSpan from "@/components/LoadingSpan.vue"; | ||
library.add(faArchive, faBurn); | ||
const router = useRouter(); | ||
const historyStore = useHistoryStore(); | ||
interface Props { | ||
historyId: string; | ||
} | ||
const props = defineProps<Props>(); | ||
const history = computed(() => historyStore.getHistoryById(props.historyId)); | ||
const canSwitch = computed(() => !!history.value && !history.value.archived && !history.value.purged); | ||
const actionText = computed(() => (canSwitch.value ? "Switch to" : "View in new tab")); | ||
function onClick(history: HistorySummary) { | ||
console.log("onClick", history); | ||
if (canSwitch.value) { | ||
console.log("setCurrentHistory", history.id); | ||
historyStore.setCurrentHistory(history.id); | ||
return; | ||
} | ||
console.log("viewHistoryInNewTab", history); | ||
viewHistoryInNewTab(history); | ||
} | ||
function viewHistoryInNewTab(history: HistorySummary) { | ||
const routeData = router.resolve(`/histories/view?id=${history.id}`); | ||
window.open(routeData.href, "_blank"); | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<LoadingSpan v-if="!history" /> | ||
<div v-else v-b-tooltip.hover.top.html :title="`<b>${actionText}</b><br>${history.name}`" class="history-link"> | ||
<BLink class="truncate" href="#" @click.stop="onClick(history)"> | ||
{{ history.name }} | ||
</BLink> | ||
|
||
<FontAwesomeIcon v-if="history.purged" :icon="faBurn" fixed-width /> | ||
<FontAwesomeIcon v-else-if="history.archived" :icon="faArchive" fixed-width /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.history-link { | ||
display: flex; | ||
gap: 1px; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
</style> |
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