Skip to content

Commit 7e84ab6

Browse files
feat: add test mock for solid in Home.vue
1 parent 96b43e6 commit 7e84ab6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+457
-183
lines changed

apps/auth/jest-setup.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
import * as buffer from "node:buffer";
2-
import { TextDecoder, TextEncoder } from "node:util"; // (ESM style imports)
1+
import { TextDecoder, TextEncoder } from 'node:util'; // (ESM style imports)
32

43
global.TextEncoder = TextEncoder;
54
global.TextDecoder = TextDecoder as any;
65
global.Notification = class {} as any;
76

8-
declare global {
9-
interface Crypto {
10-
randomUUID: () => `${string}-${string}-${string}-${string}-${string}`;
11-
}
12-
}
13-
14-
jest.mock("axios", () => ({}));
15-
jest.mock("hackathon-demo/libs/components", () => ({}));

apps/auth/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
testEnvironment: "jsdom",
33
verbose: false,
4-
setupFilesAfterEnv: ["<rootDir>/../../jest-setup.ts"],
4+
setupFilesAfterEnv: ["<rootDir>/jest-setup.ts"],
55
transform: {
66
"^.+\\.vue$": "@vue/vue3-jest",
77
"^.+\\.svg": "<rootDir>/scripts/jest-string-transformer.js",

apps/auth/tests/unit/App.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import App from "@/App.vue";
22
import router from "@/router";
3-
import { mount } from "@vue/test-utils";
3+
import { mount, shallowMount } from "@vue/test-utils";
44
import PrimeVue from "primevue/config";
55
import ConfirmationService from "primevue/confirmationservice";
66
import ToastService from "primevue/toastservice";
77

8+
jest.mock("hackathon-demo/libs/components", () => ({}));
9+
810
test("App should render 401 by default", async () => {
911
const wrapper = mount(App, {
1012
global: {
1113
plugins: [PrimeVue, ToastService, ConfirmationService, router],
1214
mocks: {
1315
$t: (key: string): string => key,
1416
},
15-
stubs: {
16-
Toolbar: true,
17-
Avatar: true,
18-
AccessRequestCallback: true,
19-
},
2017
},
2118
});
2219
expect(wrapper.text()).toMatch(`error.401-unauthenticated`);

apps/auth/tests/unit/Home.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import de from "@/assets/i18n/de.json";
2+
import en from "@/assets/i18n/en.json";
3+
import router from "@/router";
4+
import Home from "@/views/Home.vue";
5+
import { mount } from "@vue/test-utils";
6+
import PrimeVue from "primevue/config";
7+
import ConfirmationService from "primevue/confirmationservice";
8+
import ToastService from "primevue/toastservice";
9+
import { createI18n } from "vue-i18n";
10+
11+
const rdpCapableSessionMock = {
12+
authFetch: jest.fn(() =>
13+
Promise.resolve({
14+
status: 200,
15+
data: "",
16+
statusText: "OK",
17+
headers: {},
18+
config: {},
19+
request: {},
20+
})
21+
),
22+
updateSessionWithRDP: jest.fn(),
23+
login: jest.fn(() => Promise.resolve(undefined)),
24+
logout: jest.fn(),
25+
handleRedirectFromLogin: jest.fn(() => Promise.resolve(undefined)),
26+
rdp: "",
27+
isActive: true,
28+
};
29+
const primeVueStubs = {
30+
Toolbar: true,
31+
Avatar: true,
32+
AccessRequestCallback: true,
33+
Button: true,
34+
Card: true,
35+
Skeleton: true,
36+
};
37+
test("Home should render 401 by default", async () => {
38+
const i18n = createI18n({
39+
locale: "en",
40+
messages: {
41+
en: en,
42+
de: de,
43+
},
44+
});
45+
const wrapper = mount(Home, {
46+
global: {
47+
plugins: [PrimeVue, ToastService, ConfirmationService, router, i18n],
48+
provide: {
49+
"useSolidSession:RdpCapableSession": rdpCapableSessionMock,
50+
},
51+
stubs: primeVueStubs,
52+
},
53+
});
54+
55+
expect(wrapper.text()).toMatch("Access Manager");
56+
});

libs/components/dist/AuthAppHeaderBar.common.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/components/dist/AuthAppHeaderBar.common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/components/dist/AuthAppHeaderBar.umd.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/components/dist/AuthAppHeaderBar.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/components/dist/DacklHeaderBar.common.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/components/dist/DacklHeaderBar.common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)