Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • coscine/frontend/apps/ui
1 result
Select Git revision
Loading items
Show changes
Commits on Source (4)
{
"name": "ui",
"version": "1.26.0",
"version": "1.26.1",
"private": true,
"scripts": {
"dev": "vite",
......
// 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();
});
});
......@@ -370,6 +370,7 @@ import "@/plugins/deprecated/vue-multiselect";
// import the store for current module
import useUserStore from "../store";
import useLoginStore from "@/modules/login/store";
import useNotificationStore from "@/store/notification";
import type {
ContactChangeObject,
......@@ -383,11 +384,12 @@ import type { OrganizationObject } from "@coscine/api-client/dist/types/Coscine.
export default defineComponent({
components: { AccessToken },
setup() {
const userStore = useUserStore();
const loginStore = useLoginStore();
const notificationStore = useNotificationStore();
const userStore = useUserStore();
const v$ = useVuelidate();
return { userStore, notificationStore, v$ };
return { loginStore, notificationStore, userStore, v$ };
},
data() {
return {
......@@ -545,8 +547,9 @@ export default defineComponent({
}
},
async clickConnect(provider: string) {
await this.userStore.storeMergeToken(provider);
location.href = "/coscine/api/Coscine.Api.STS/account/logout";
await this.userStore.storeMergeToken(provider); // Merge JWT token stored in the cookies for STS
// Log user out. After initiating an ORCID login, the STS will do the merge job.
this.loginStore.logout();
},
async clickSave() {
this.v$.form.$touch();
......