-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import { createTestingPinia } from "@pinia/testing"; | ||
import { getLocalVue } from "@tests/jest/helpers"; | ||
import { mount } from "@vue/test-utils"; | ||
import { setActivePinia } from "pinia"; | ||
|
||
import { getGalaxyInstance } from "@/app/singleton"; | ||
import axios from "axios"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
|
||
import ResetPassword from "./ResetPassword.vue"; | ||
import assert from "assert"; | ||
|
||
const localVue = getLocalVue(true); | ||
|
||
|
@@ -26,7 +23,6 @@ jest.mock("app/singleton"); | |
jest.mock("@/composables/config", () => ({ | ||
useConfig: jest.fn(() => ({ | ||
config: configMock, | ||
|
||
isConfigLoaded: true, | ||
})), | ||
})); | ||
|
@@ -37,33 +33,84 @@ const mockRouter = (query: object) => ({ | |
}, | ||
}); | ||
|
||
(getGalaxyInstance as jest.Mock).mockReturnValue({ session_csrf_token: "session_csrf_token" }); | ||
|
||
function mountResetPassword(routerQuery: object = {}) { | ||
const pinia = createTestingPinia(); | ||
setActivePinia(pinia); | ||
|
||
return mount(ResetPassword, { | ||
localVue, | ||
pinia, | ||
attachTo: document.body, | ||
mocks: { | ||
$router: mockRouter(routerQuery), | ||
}, | ||
}); | ||
} | ||
|
||
describe("ResetPassword", () => { | ||
it("ResetPassword index attribute matching", async () => { | ||
const wrapper = mountResetPassword({ | ||
redirect: "redirect_url", | ||
}); | ||
it("query", async () => { | ||
const email = "test"; | ||
const wrapper = mountResetPassword({ email: "test" }); | ||
|
||
const emailField = wrapper.find("#reset-email"); | ||
const emailValue = (emailField.element as HTMLInputElement).value; | ||
expect(emailValue).toBe(email); | ||
}); | ||
|
||
it("button text", async () => { | ||
const wrapper = mountResetPassword(); | ||
const submitButton = wrapper.find("#reset-password"); | ||
(expect(submitButton.text()) as any).toBeLocalizationOf("Send password reset email"); | ||
}); | ||
|
||
it("validate email", async () => { | ||
const wrapper = mountResetPassword(); | ||
const submitButton = wrapper.find("#reset-password"); | ||
const testEmail = "eihfeuh"; | ||
const emailField = wrapper.find("#reset-email"); | ||
const emailElement = emailField.element as HTMLInputElement; | ||
|
||
let email = ""; | ||
await emailField.setValue(email); | ||
expect(emailElement.value).toBe(email); | ||
await submitButton.trigger("click"); | ||
expect(emailElement.checkValidity()).toBe(false); | ||
|
||
emailField.setValue(testEmail); | ||
const emailValue = emailField.element.textContent; | ||
expect(emailValue).toBe(testEmail); | ||
email = "test"; | ||
await emailField.setValue(email); | ||
expect(emailElement.value).toBe(email); | ||
await submitButton.trigger("click"); | ||
expect(emailElement.checkValidity()).toBe(false); | ||
|
||
email = "[email protected]"; | ||
await emailField.setValue(email); | ||
expect(emailElement.value).toBe(email); | ||
await submitButton.trigger("click"); | ||
expect(emailElement.checkValidity()).toBe(true); | ||
}); | ||
|
||
it("display success message", async () => { | ||
const wrapper = mountResetPassword({ email: "[email protected]" }); | ||
const mockAxios = new MockAdapter(axios); | ||
const submitButton = wrapper.find("#reset-password"); | ||
|
||
mockAxios.onPost("/user/reset_password").reply(200, { | ||
message: "Reset link has been sent to your email.", | ||
}); | ||
await submitButton.trigger("click"); | ||
setTimeout(async () => { | ||
const alertSuccess = wrapper.find("#reset-password-alert"); | ||
expect(alertSuccess.text()).toBe("Reset link has been sent to your email."); | ||
}); | ||
}); | ||
|
||
it("display error message", async () => { | ||
const wrapper = mountResetPassword({ email: "[email protected]" }); | ||
const submitButton = wrapper.find("#reset-password"); | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
mockAxios.onPost("/user/reset_password").reply(400, { | ||
err_msg: "Please provide your email.", | ||
}); | ||
await submitButton.trigger("click"); | ||
setTimeout(async () => { | ||
const alertError = wrapper.find("#reset-password-alert"); | ||
expect(alertError.text()).toBe("Please provide your email."); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters