Skip to content

Commit

Permalink
testing: E2E for setting username field
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Kabo committed Feb 8, 2024
1 parent ab3ad2f commit 68344c5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
7 changes: 5 additions & 2 deletions client/components/mma/identity/idapi/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,11 @@ export const read = async (): Promise<User> => {

export const setUsername = async (user: Partial<User>): Promise<User> => {
const url = '/idapi/user/username';
const body = toUserApiRequest(user);
console.log('sending', body);
const body = {
publicFields: {
username: user.username,
},
};
try {
const response: UserAPIResponse = await fetchWithDefaultParameters(
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export const PublicProfile = (_: { path?: string }) => {
const usernameDisplay = (u: User) => (
<>
<WithStandardTopMargin>
<PageSection title="Username">{u.username}</PageSection>
<PageSection title="Username">
<span data-cy="username-display">{u.username}</span>
</PageSection>
</WithStandardTopMargin>
<WithStandardTopMargin>
<Lines n={1} />
Expand Down
1 change: 1 addition & 0 deletions cypress/lib/signInOkta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const signInOkta = () => {
cy.visit('/');
cy.createTestUser({
isUserEmailValidated: true,
doNotSetUsername: true,
})?.then(({ emailAddress, finalPassword }) => {
cy.get('input[name=email]').type(emailAddress);
cy.get('input[name=password]').type(finalPassword);
Expand Down
3 changes: 3 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type IDAPITestUserOptions = {
password?: string;
deleteAfterMinute?: boolean;
isGuestUser?: boolean;
doNotSetUsername?: boolean;
};
type IDAPITestUserResponse = [
{
Expand Down Expand Up @@ -128,6 +129,7 @@ export const createTestUser = ({
isUserEmailValidated = false,
deleteAfterMinute = true,
isGuestUser = false,
doNotSetUsername = false,
}: IDAPITestUserOptions) => {
// Generate a random email address if none is provided.
const finalEmail = primaryEmailAddress || randomMailosaurEmail();
Expand All @@ -150,6 +152,7 @@ export const createTestUser = ({
password: finalPassword,
deleteAfterMinute,
isGuestUser,
doNotSetUsername,
} as IDAPITestUserOptions,
})
.then((res) => {
Expand Down
13 changes: 11 additions & 2 deletions cypress/tests/e2e/e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ describe('E2E with Okta', () => {
});

context('profile tab', () => {
it('should contain a username', () => {
it('should allow the user to set a username', () => {
const randomUsername = `testuser${Math.floor(
Math.random() * 100000,
)}`;
cy.visit('/public-settings');
cy.findByText('Username');
cy.get('input[name="username"]').type(randomUsername);
cy.findByText('Save changes').click();
cy.visit('/public-settings');
cy.get('span[data-cy="username-display"]').should(
'contain',
randomUsername,
);
});
});

Expand Down

0 comments on commit 68344c5

Please sign in to comment.