Skip to content

Commit

Permalink
Cypress: User Avatar Modification (#10592)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonXavierdev authored Feb 27, 2025
1 parent 9b82db3 commit 5ffc6b3
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cypress/e2e/users_spec/user_avatar.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { UserAvatar } from "@/pageObject/Users/UserAvatar";

describe("User Profile Avatar Modification", () => {
const userAvatar = new UserAvatar("teststaff4");
beforeEach(() => {
cy.loginByApi("teststaff4");
cy.visit("/");
});
it("should modify an avatar", () => {
userAvatar
.navigateToProfile()
.interceptUploadAvatarRequest()
.clickChangeAvatarButton()
.uploadAvatar()
.clickSaveAvatarButton()
.verifyUploadAvatarApiCall()
.interceptDeleteAvatarRequest()
.clickChangeAvatarButton()
.clickDeleteAvatarButton()
.verifyDeleteAvatarApiCall();
});
});
Binary file added cypress/fixtures/avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions cypress/fixtures/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
"devdoctor": {
"username": "developdoctor",
"password": "Test@123"
},
"teststaff4": {
"username": "teststaff4",
"password": "Test@123"
}
}
59 changes: 59 additions & 0 deletions cypress/pageObject/Users/UserAvatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export class UserAvatar {
username: string;
constructor(username: string) {
this.username = username;
}

navigateToProfile() {
cy.visit(`/users/${this.username}`);
return this;
}

interceptUploadAvatarRequest() {
cy.intercept("POST", `/api/v1/users/${this.username}/profile_picture/`).as(
"uploadAvatar",
);
return this;
}

clickChangeAvatarButton() {
cy.verifyAndClickElement('[data-cy="change-avatar"]', "Change Avatar");
return this;
}

uploadAvatar() {
cy.get('input[title="changeFile"]').selectFile(
"cypress/fixtures/avatar.jpg",
{ force: true },
);
return this;
}

clickSaveAvatarButton() {
cy.verifyAndClickElement('[data-cy="save-cover-image"]', "Save");
return this;
}

verifyUploadAvatarApiCall() {
cy.wait("@uploadAvatar").its("response.statusCode").should("eq", 200);
return this;
}

interceptDeleteAvatarRequest() {
cy.intercept(
"DELETE",
`/api/v1/users/${this.username}/profile_picture/`,
).as("deleteAvatar");
return this;
}

clickDeleteAvatarButton() {
cy.verifyAndClickElement('[data-cy="delete-avatar"]', "Delete");
return this;
}

verifyDeleteAvatarApiCall() {
cy.wait("@deleteAvatar").its("response.statusCode").should("eq", 204);
return this;
}
}
2 changes: 2 additions & 0 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ const AvatarEditModal = ({
variant="destructive"
onClick={deleteAvatar}
disabled={isProcessing}
data-cy="delete-avatar"
>
{t("delete")}
</Button>
Expand All @@ -358,6 +359,7 @@ const AvatarEditModal = ({
variant="outline"
onClick={uploadAvatar}
disabled={isProcessing || !selectedFile}
data-cy="save-cover-image"
>
{isProcessing ? (
<CareIcon
Expand Down
2 changes: 2 additions & 0 deletions src/components/Users/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default function UserAvatar({ username }: { username: string }) {
onClick={() => setEditAvatar(!editAvatar)}
type="button"
id="change-avatar"
data-cy="change-avatar"
disabled
>
{t("change_avatar")}
Expand All @@ -138,6 +139,7 @@ export default function UserAvatar({ username }: { username: string }) {
onClick={() => setEditAvatar(!editAvatar)}
type="button"
id="change-avatar"
data-cy="change-avatar"
>
{t("change_avatar")}
</Button>
Expand Down

0 comments on commit 5ffc6b3

Please sign in to comment.