Skip to content

Commit b348ca7

Browse files
committed
Refactors HistoryView component imports and updates test setup for VueRouter
1 parent cec0905 commit b348ca7

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

client/src/components/History/HistoryView.test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import flushPromises from "flush-promises";
44
import { createPinia } from "pinia";
55
import { getLocalVue } from "tests/jest/helpers";
66
import { setupMockConfig } from "tests/jest/mockConfig";
7+
import VueRouter from "vue-router";
78

89
import { useServerMock } from "@/api/client/__mocks__";
910
import { useHistoryStore } from "@/stores/historyStore";
@@ -14,15 +15,12 @@ import ContentItem from "./Content/ContentItem.vue";
1415
import HistoryView from "./HistoryView.vue";
1516

1617
const localVue = getLocalVue();
18+
localVue.use(VueRouter);
19+
1720
jest.mock("stores/services/history.services");
1821

1922
const { server, http } = useServerMock();
2023

21-
jest.mock("vue-router/composables", () => ({
22-
useRoute: jest.fn(() => ({})),
23-
useRouter: jest.fn(() => ({})),
24-
}));
25-
2624
function create_history(historyId, userId, purged = false, archived = false) {
2725
const historyName = `${userId}'s History ${historyId}`;
2826
return {
@@ -78,6 +76,9 @@ async function createWrapper(localVue, currentUserId, history) {
7876
})
7977
);
8078

79+
const router = new VueRouter();
80+
router.push(`/history/${history.id}`);
81+
8182
const wrapper = mount(HistoryView, {
8283
propsData: { id: history.id },
8384
localVue,
@@ -88,6 +89,7 @@ async function createWrapper(localVue, currentUserId, history) {
8889
},
8990
},
9091
pinia,
92+
router,
9193
});
9294
const userStore = useUserStore();
9395
userStore.currentUser = getFakeRegisteredUser({ id: currentUserId });
@@ -124,9 +126,9 @@ describe("History center panel View", () => {
124126
await historyStore.setCurrentHistory(history.id);
125127

126128
// switch/import buttons: current history, should be a disabled switch
127-
const switchButton = wrapper.find("[data-description='switch to history button']");
129+
const switchButton = wrapper.find("[data-description='switch to history button']").classes();
128130
const importButton = wrapper.find("[data-description='import history button']");
129-
expect(switchButton.attributes("disabled")).toBeTruthy();
131+
expect(switchButton.includes("g-disabled")).toBeTruthy();
130132
expect(importButton.exists()).toBe(false);
131133

132134
// parts of the layout that should be similar for all cases
@@ -169,9 +171,9 @@ describe("History center panel View", () => {
169171
expect(wrapper.vm.history).toEqual(history);
170172

171173
// switch/import buttons: not current history, switchable
172-
const switchButton = wrapper.find("[data-description='switch to history button']");
174+
const switchButton = wrapper.find("[data-description='switch to history button']").classes();
173175
const importButton = wrapper.find("[data-description='import history button']");
174-
expect(switchButton.attributes("disabled")).toBeFalsy();
176+
expect(switchButton.includes("g-disabled")).toBeFalsy();
175177
expect(importButton.exists()).toBe(false);
176178

177179
// storage dashboard button should be enabled
@@ -187,9 +189,9 @@ describe("History center panel View", () => {
187189
expect(wrapper.vm.history).toEqual(history);
188190

189191
// history purged, is switchable but not importable
190-
const switchButton = wrapper.find("[data-description='switch to history button']");
192+
const switchButton = wrapper.find("[data-description='switch to history button']").classes();
191193
const importButton = wrapper.find("[data-description='import history button']");
192-
expect(switchButton.attributes("disabled")).toBeFalsy();
194+
expect(switchButton.includes("g-disabled")).toBeFalsy();
193195
expect(importButton.exists()).toBe(false);
194196

195197
// storage dashboard button can be accessed

client/src/components/History/HistoryView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<script>
4646
import { faFileImport } from "@fortawesome/free-solid-svg-icons";
47-
import FontAwesomeIcon from "@fortawesome/vue-fontawesome";
47+
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
4848
import { mapActions, mapState } from "pinia";
4949
5050
import { isAnonymousUser } from "@/api";

0 commit comments

Comments
 (0)