Skip to content

Commit

Permalink
Addressing review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
CDimonaco committed May 30, 2024
1 parent ee1bb60 commit 3219bf9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion assets/js/lib/test-utils/factories/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const profileFactory = Factory.define(() => ({
email: faker.internet.email(),
abilities: abilityFactory.buildList(2),
password_change_requested: false,
totp_enabled: faker.datatype.boolean(),
created_at: formatISO(faker.date.past()),
updated_at: formatISO(faker.date.past()),
totp_enabled: faker.datatype.boolean(),
}));

export const adminUser = userFactory.params({
Expand Down
6 changes: 3 additions & 3 deletions assets/js/pages/Profile/ProfileForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ProfileForm({
onSave = noop,
onResetTotp = noop,
onVerifyTotp = noop,
onTotpEnable = noop,
onEnableTotp = noop,
}) {
const [fullNameState, setFullName] = useState(fullName);
const [fullNameErrorState, setFullNameError] = useState(null);
Expand Down Expand Up @@ -67,7 +67,7 @@ function ProfileForm({

const toggleTotp = () => {
if (!totpEnabled) {
onTotpEnable();
onEnableTotp();
return;
}
setTotpDisableModalOpen(true);
Expand Down Expand Up @@ -139,7 +139,7 @@ function ProfileForm({
<>
<Label
className="col-start-1 col-span-1"
info="Use a second factor besides your password to increase security
info="Setup a multi factor TOTP authentication besides your password to increase security
for your account."
>
Authenticator App
Expand Down
8 changes: 4 additions & 4 deletions assets/js/pages/Profile/ProfileForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ describe('ProfileForm', () => {
).toBe('false');
});

it('should call onTotpEnable when totpEnabled is false and the switch is clicked', async () => {
it('should call onEnableTotp when totpEnabled is false and the switch is clicked', async () => {
const username = faker.internet.userName();
const fullName = faker.person.fullName();
const email = faker.internet.email();
const abilities = abilityFactory.buildList(2);

const onTotpEnable = jest.fn();
const onEnableTotp = jest.fn();
const user = userEvent.setup();

render(
Expand All @@ -171,7 +171,7 @@ describe('ProfileForm', () => {
username={username}
abilities={abilities}
totpEnabled={false}
onTotpEnable={onTotpEnable}
onEnableTotp={onEnableTotp}
/>
);

Expand All @@ -181,7 +181,7 @@ describe('ProfileForm', () => {
await user.click(screen.getByRole('switch'));
});

expect(onTotpEnable).toHaveBeenCalled();
expect(onEnableTotp).toHaveBeenCalled();
});

it('should call onResetTotp when totpEnabled is true, the switch is clicked and the user confirms with the modal', async () => {
Expand Down
8 changes: 4 additions & 4 deletions assets/js/pages/Profile/ProfilePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function ProfilePage() {
setErrors([]);
};

const verifyTotpEnrolling = async (enrollmentTotp) => {
const verifyTotpEnrollment = async (enrollmentTotp) => {
setSaving(true);
setErrors([]);

Expand Down Expand Up @@ -79,7 +79,7 @@ function ProfilePage() {
setSaving(false);
toast.success('TOTP Disabled');
} catch {
toast.error('Error disabling totp, please refresh profile.');
toast.error('Error disabling totp, please refresh your profile.');
}
await loadUserProfile();
setSaving(false);
Expand Down Expand Up @@ -161,8 +161,8 @@ function ProfilePage() {
loading={loading || saving}
disableForm={isDefaultAdmin}
onSave={updateProfile}
onTotpEnable={totpInitiateEnrolling}
onVerifyTotp={verifyTotpEnrolling}
onEnableTotp={totpInitiateEnrolling}
onVerifyTotp={verifyTotpEnrollment}
onResetTotp={disableTotp}
/>
</>
Expand Down
10 changes: 9 additions & 1 deletion assets/js/pages/Profile/ProfilePage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ describe('ProfilePage', () => {
await testUser.click(screen.getByRole('switch'));
});

await act(async () => {
await testUser.click(screen.getByText('Disable'));
});

expect(toast.success).toHaveBeenCalledWith('TOTP Disabled');
});

Expand All @@ -206,8 +210,12 @@ describe('ProfilePage', () => {
await testUser.click(screen.getByRole('switch'));
});

await act(async () => {
await testUser.click(screen.getByText('Disable'));
});

expect(toast.error).toHaveBeenCalledWith(
'Error disabling totp, please refresh profile.'
'Error disabling totp, please refresh your profile.'
);
});

Expand Down
14 changes: 7 additions & 7 deletions assets/js/pages/Profile/TotpEnrollmentBox.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ export default {
type: 'text',
},
},
verifyError: {
description: 'Totp error during the enrollment verify procedure',
errors: {
description: 'Totp errors during the enrollment verify procedure',
control: {
type: 'boolean',
},
},
loading: {
control: {
type: 'boolean',
},
Expand All @@ -27,11 +32,6 @@ export default {
action: 'Verify enrollment TOTP',
},
},
args: {
secret: faker.string.uuid(),
qrData:
'otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example',
},
};

export const Default = {
Expand Down

0 comments on commit 3219bf9

Please sign in to comment.