Mrudhulraj commented on code in PR #6402:
URL: https://github.com/apache/texera/pull/6402#discussion_r3639238466
##########
frontend/src/app/hub/component/about/local-login/local-login.component.spec.ts:
##########
@@ -306,10 +323,72 @@ describe("LocalLoginComponent", () => {
expect(userServiceMock.register).not.toHaveBeenCalled();
});
+ it("sets registerErrorMessage when the email is empty", () => {
+ vi.spyOn(UserService, "validateEmail").mockReturnValue({
+ result: false,
+ message: "Email should not be empty.",
+ });
+ component.allForms.patchValue({
+ registerUsername: "alice",
+ registerEmail: "",
+ registerPassword: "abcdef",
+ registerConfirmationPassword: "abcdef",
+ });
+
+ component.register();
+
+ expect(component.registerErrorMessage).toBe("Email should not be
empty.");
+ expect(userServiceMock.register).not.toHaveBeenCalled();
+ });
+
+ it("sets registerErrorMessage when the email is malformed", () => {
+ vi.spyOn(UserService, "validateEmail").mockReturnValue({
+ result: false,
+ message: "Email format is invalid.",
+ });
+ component.allForms.patchValue({
+ registerUsername: "alice",
+ registerEmail: "not-an-email",
+ registerPassword: "abcdef",
+ registerConfirmationPassword: "abcdef",
+ });
+
+ component.register();
+
+ expect(component.registerErrorMessage).toBe("Email format is invalid.");
+ expect(userServiceMock.register).not.toHaveBeenCalled();
+ });
+
+ it("checks email validity before username validity", () => {
+ // Email validation runs before username validation in register(), so a
+ // bad email must short-circuit the flow even if username is also bad.
+ const validateUsernameSpy = vi
+ .spyOn(UserService, "validateUsername")
+ .mockReturnValue({ result: false, message: "Username should not be
empty." });
+ const validateEmailSpy = vi
+ .spyOn(UserService, "validateEmail")
+ .mockReturnValue({ result: false, message: "Email format is invalid."
});
+ component.allForms.patchValue({
+ registerUsername: "",
+ registerEmail: "not-an-email",
+ registerPassword: "abcdef",
+ registerConfirmationPassword: "abcdef",
+ });
+
+ component.register();
+
+ expect(component.registerErrorMessage).toBe("Email format is invalid.");
+ expect(validateUsernameSpy).not.toHaveBeenCalled();
+ expect(validateEmailSpy).toHaveBeenCalledWith("not-an-email");
+ expect(userServiceMock.register).not.toHaveBeenCalled();
+ });
+
it("calls UserService.register with the trimmed username and surfaces a
success notification", () => {
vi.spyOn(UserService, "validateUsername").mockReturnValue({ result:
true, message: "ok" });
+ vi.spyOn(UserService, "validateEmail").mockReturnValue({ result: true,
message: "ok" });
component.allForms.patchValue({
registerUsername: " alice ",
+ registerEmail: " [email protected] ",
registerPassword: "abcdef",
Review Comment:
The email with white-spaces is expected to check if the trim works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]