diff --git a/client/src/components/Login/ChangePassword.test.js b/client/src/components/Login/ChangePassword.test.ts similarity index 81% rename from client/src/components/Login/ChangePassword.test.js rename to client/src/components/Login/ChangePassword.test.ts index a48a25107714..cc8ad816ef18 100644 --- a/client/src/components/Login/ChangePassword.test.js +++ b/client/src/components/Login/ChangePassword.test.ts @@ -1,25 +1,26 @@ -import { mount } from "@vue/test-utils"; +import { mount, Wrapper } from "@vue/test-utils"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import { getLocalVue } from "tests/jest/helpers"; -import { withPrefix } from "utils/redirect"; -import MountTarget from "./ChangePassword"; +import { withPrefix } from "@/utils/redirect"; + +import MountTarget from "./ChangePassword.vue"; -// mock routes jest.mock("utils/redirect"); + const mockSafePath = jest.fn(); -withPrefix.mockImplementation(() => mockSafePath); +(withPrefix as jest.Mock).mockImplementation(mockSafePath); const localVue = getLocalVue(true); describe("ChangePassword", () => { - let wrapper; - let axiosMock; + let wrapper: Wrapper; + let axiosMock: MockAdapter; beforeEach(() => { axiosMock = new MockAdapter(axios); - wrapper = mount(MountTarget, { + wrapper = mount(MountTarget as object, { propsData: { messageText: "message_text", messageVariant: "message_variant", @@ -35,17 +36,25 @@ describe("ChangePassword", () => { it("basics", async () => { const cardHeader = wrapper.find(".card-header"); expect(cardHeader.text()).toBe("Change your password"); + const inputs = wrapper.findAll("input"); expect(inputs.length).toBe(2); + const firstPwdField = inputs.at(0); expect(firstPwdField.attributes("type")).toBe("password"); + await firstPwdField.setValue("test_first_pwd"); + const secondPwdField = inputs.at(1); expect(secondPwdField.attributes("type")).toBe("password"); + await secondPwdField.setValue("test_second_pwd"); + const submitButton = wrapper.find("button[type='submit']"); + await submitButton.trigger("submit"); - const postedData = JSON.parse(axiosMock.history.post[0].data); + + const postedData = JSON.parse(axiosMock.history.post?.[0]?.data); expect(postedData.password).toBe("test_first_pwd"); expect(postedData.confirm).toBe("test_second_pwd"); }); @@ -55,15 +64,21 @@ describe("ChangePassword", () => { token: "test_token", expiredUser: "expired_user", }); + const input = wrapper.find("input"); expect(input.attributes("type")).toBe("password"); + await input.setValue("current_password"); + const submitButton = wrapper.find("button[type='submit']"); + await submitButton.trigger("submit"); - const postedData = JSON.parse(axiosMock.history.post[0].data); + + const postedData = JSON.parse(axiosMock.history.post?.[0]?.data); expect(postedData.token).toBe("test_token"); expect(postedData.id).toBe("expired_user"); expect(postedData.current).toBe("current_password"); + const alert = wrapper.find(".alert"); expect(alert.text()).toBe("message_text"); }); diff --git a/client/src/components/Login/ChangePassword.vue b/client/src/components/Login/ChangePassword.vue index 9f47887b0278..24575bc1d9a3 100644 --- a/client/src/components/Login/ChangePassword.vue +++ b/client/src/components/Login/ChangePassword.vue @@ -1,73 +1,67 @@ - - + + diff --git a/client/src/components/Login/LoginForm.test.js b/client/src/components/Login/LoginForm.test.ts similarity index 63% rename from client/src/components/Login/LoginForm.test.js rename to client/src/components/Login/LoginForm.test.ts index 1d35caaee6d6..9422c8af8f88 100644 --- a/client/src/components/Login/LoginForm.test.js +++ b/client/src/components/Login/LoginForm.test.ts @@ -1,27 +1,31 @@ +import { getLocalVue } from "@tests/jest/helpers"; import { mount } from "@vue/test-utils"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { getLocalVue } from "tests/jest/helpers"; -import MountTarget from "./LoginForm"; +import MountTarget from "./LoginForm.vue"; const localVue = getLocalVue(true); +async function mountLoginForm() { + const wrapper = mount(MountTarget as object, { + propsData: { + sessionCsrfToken: "sessionCsrfToken", + }, + localVue, + stubs: { + ExternalLogin: true, + }, + }); + + return wrapper; +} + describe("LoginForm", () => { - let wrapper; - let axiosMock; + let axiosMock: MockAdapter; beforeEach(() => { axiosMock = new MockAdapter(axios); - wrapper = mount(MountTarget, { - propsData: { - sessionCsrfToken: "sessionCsrfToken", - }, - localVue, - stubs: { - ExternalLogin: true, - }, - }); }); afterEach(() => { @@ -29,34 +33,50 @@ describe("LoginForm", () => { }); it("basics", async () => { + const wrapper = await mountLoginForm(); + const cardHeader = wrapper.find(".card-header"); expect(cardHeader.text()).toBe("Welcome to Galaxy, please log in"); + const inputs = wrapper.findAll("input"); expect(inputs.length).toBe(2); + const usernameField = inputs.at(0); expect(usernameField.attributes("type")).toBe("text"); + await usernameField.setValue("test_user"); + const pwdField = inputs.at(1); expect(pwdField.attributes("type")).toBe("password"); + await pwdField.setValue("test_pwd"); + const submitButton = wrapper.find("button[type='submit']"); await submitButton.trigger("submit"); - const postedData = JSON.parse(axiosMock.history.post[0].data); + + const postedData = JSON.parse(axiosMock.history.post?.[0]?.data); expect(postedData.login).toBe("test_user"); expect(postedData.password).toBe("test_pwd"); }); it("props", async () => { - const $register = "[id='register-toggle']"; + const wrapper = await mountLoginForm(); + + console.log(wrapper.html()); + + const $register = "#register-toggle"; expect(wrapper.findAll($register).length).toBe(0); + await wrapper.setProps({ allowUserCreation: true, enableOidc: true, showWelcomeWithLogin: true, welcomeUrl: "welcome_url", }); + const register = wrapper.find($register); - expect(register.text()).toBeLocalizationOf("Register here."); + (expect(register.text()) as any).toBeLocalizationOf("Register here."); + const welcomePage = wrapper.find("iframe"); expect(welcomePage.attributes("src")).toBe("welcome_url"); }); @@ -65,33 +85,46 @@ describe("LoginForm", () => { const external_email = "test@test.com"; const provider_id = "test_provider"; const provider_label = "Provider"; - await wrapper.setData({ - connectExternalEmail: external_email, - connectExternalProvider: provider_id, - connectExternalLabel: provider_label, - }); + + const originalLocation = window.location; + jest.spyOn(window, "location", "get").mockImplementation(() => ({ + ...originalLocation, + search: `?connect_external_email=${external_email}&connect_external_provider=${provider_id}&connect_external_label=${provider_label}`, + })); + + const wrapper = await mountLoginForm(); + expect(wrapper.find(".card-header").exists()).toBe(false); + const alert = wrapper.find(".alert"); expect(alert.classes()).toContain("alert-info"); expect(alert.text()).toContain(`There already exists a user with the email ${external_email}`); expect(alert.text()).toContain(`In order to associate this account with ${provider_label}`); + const inputs = wrapper.findAll("input"); expect(inputs.length).toBe(2); + const usernameField = inputs.at(0); expect(usernameField.attributes("type")).toBe("text"); - expect(usernameField.element.disabled).toBe(true); - expect(usernameField.element.value).not.toBe(""); - expect(usernameField.element.value).toContain(external_email); + expect((usernameField.element as HTMLInputElement).disabled).toBe(true); + expect((usernameField.element as HTMLInputElement).value).not.toBe(""); + expect((usernameField.element as HTMLInputElement).value).toContain(external_email); + const pwdField = inputs.at(1); expect(pwdField.attributes("type")).toBe("password"); - expect(pwdField.element.value).toBe(""); + expect((pwdField.element as HTMLInputElement).value).toBe(""); + await pwdField.setValue("test_pwd"); + const submitButton = wrapper.find("button[type='submit']"); + await submitButton.trigger("submit"); - const postedData = JSON.parse(axiosMock.history.post[0].data); + + const postedData = JSON.parse(axiosMock.history.post?.[0]?.data); expect(postedData.login).toBe(external_email); expect(postedData.password).toBe("test_pwd"); - const postedURL = axiosMock.history.post[0].url; + + const postedURL = axiosMock.history.post?.[0]?.url; expect(postedURL).toBe("/user/login"); }); }); diff --git a/client/src/components/Login/LoginForm.vue b/client/src/components/Login/LoginForm.vue index 626265bf1c9a..54e460a42c02 100644 --- a/client/src/components/Login/LoginForm.vue +++ b/client/src/components/Login/LoginForm.vue @@ -1,47 +1,207 @@ + + - - diff --git a/client/src/components/User/ExternalIdentities/ExternalIdentities.vue b/client/src/components/User/ExternalIdentities/ExternalIdentities.vue index 487a534fc824..6714b06b5da6 100644 --- a/client/src/components/User/ExternalIdentities/ExternalIdentities.vue +++ b/client/src/components/User/ExternalIdentities/ExternalIdentities.vue @@ -85,7 +85,7 @@

Connect Other External Identities

- +
diff --git a/client/src/components/User/ExternalIdentities/ExternalLogin.vue b/client/src/components/User/ExternalIdentities/ExternalLogin.vue index 12f4a28243d0..29df7f8e9d2c 100644 --- a/client/src/components/User/ExternalIdentities/ExternalLogin.vue +++ b/client/src/components/User/ExternalIdentities/ExternalLogin.vue @@ -1,70 +1,243 @@ + + -