Skip to content
Snippets Groups Projects
Commit 2c75dbc1 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Fix: Added ORCID button and logout tests

parent d3d5f3ea
No related branches found
No related tags found
2 merge requests!211Fix: Fields loading when info still not present,!210Fix: Properly logging out the user on ORCID merge action
Pipeline #938742 passed
// stores/counter.spec.ts
import { setActivePinia, createPinia } from "pinia";
import useLoginStore from "./store";
describe("Login Store", () => {
beforeEach(() => {
// creates a fresh pinia and make it active so it's automatically picked
// up by any useStore() call without having to pass it to it:
// `useStore(pinia)`
setActivePinia(createPinia());
});
test("logout", () => {
const loginStore = useLoginStore();
/* Make window.location.href writable for the logout method */
Object.defineProperty(window, "location", {
value: {
href: "/",
},
writable: true, // possibility to override
});
/* Fill the local storage */
localStorage.setItem(
"coscine.clientcorrelation.id",
"f7aef8bc-77f4-4679-9f5d-5724fbdf4513"
);
localStorage.setItem(
"coscine.authorization.bearer",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
);
localStorage.setItem("coscine.locale", "en");
localStorage.setItem("coscine.banner.maintenanceVisibility", "");
localStorage.setItem("coscine.banner.pilotVisibility", "false");
localStorage.setItem("coscine.login.storedData", "");
localStorage.setItem("coscine.sidebar.active", "true");
localStorage.setItem("coscine.banner.dateString", "");
expect(localStorage.length).toBe(8);
loginStore.logout();
/* Check if prerequisites for logout are fulfilled */
expect(localStorage.length).toBeLessThan(8);
expect(localStorage.getItem("coscine.authorization.bearer")).toBeNull();
expect(sessionStorage.length).toBe(0);
expect(window.location.href).toBe(
"/coscine/api/Coscine.Api.STS/account/logout"
);
});
});
......@@ -25,6 +25,7 @@ import {
} from "@/data/mockup/testUser";
import useUserStore from "@/modules/user/store";
import type Vue from "vue";
import useLoginStore from "@/modules/login/store";
/* Create a local Vue instance */
const localVue = createLocalVue();
......@@ -152,4 +153,36 @@ describe("UserProfile.vue", () => {
"disabled"
);
});
/* Checks for correct ORCID connect button behavior */
test("orcidConnection", async () => {
testUserState.userProfile.userMemberships = [
testOrganization,
testInstitute,
];
/* Assign the test pinia store to a variable to use later */
const testingPinia = createTestingPinia({
createSpy: vitest.fn,
initialState: {
user: testUserState,
},
});
const wrapper = mount(UserProfile as unknown as typeof Vue, {
pinia: testingPinia,
i18n,
localVue,
});
// Identify the ORCID button
const orcidConnectButton = wrapper.find('button[name="orcidConnect"]');
expect(
(orcidConnectButton.element as HTMLButtonElement).disabled
).toBeFalsy();
await orcidConnectButton.trigger("click.prevent");
await wrapper.vm.$nextTick();
const loginStore = useLoginStore(testingPinia);
expect(loginStore.logout).toHaveBeenCalledOnce();
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment