Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSEGOG-362 add a user #515

Draft
wants to merge 4 commits into
base: DSEGOG-361-view-all-users
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions cypress/e2e/users.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,127 @@ describe('Users', () => {

cy.findByRole('link', { name: 'home page' }).should('exist');
});

describe('add dialog', () => {
beforeEach(() => {
cy.visit('/admin/users');
cy.findByRole('button', { name: 'Add User' }).click();
});

afterEach(() => {
cy.clearMocks();
});

it('displays required error when username is empty', () => {
cy.findByRole('button', { name: 'Submit' }).click();
cy.findByText('Username is required.').should('exist');
});

it('displays password field only when auth_type is "local"', () => {
cy.findByLabelText('Username').type('new_user');
cy.findByLabelText('Password').should('exist');
});

it('dose not displays password field only when auth_type is "FedID"', () => {
cy.findAllByRole('combobox').first().click();
cy.findByRole('option', { name: 'FedID' }).click();

cy.findByLabelText('Username').type('new_user');
cy.findByLabelText('Password').should('not.exist');
});

it('adds user successfully (local)', () => {
cy.findByLabelText('Username').type('new_user');
cy.findByLabelText('Password').type('secure_password');

cy.findAllByRole('combobox').last().click();
cy.findByRole('option', { name: '/submit/hdf POST' }).click();
cy.findAllByRole('combobox').last().click();
cy.findByRole('option', { name: '/users PATCH' }).click();

cy.startSnoopingBrowserMockedRequest();

cy.findByRole('button', { name: 'Submit' }).click();

cy.findBrowserMockedRequests({ method: 'POST', url: '/users' }).should(
async (postRequests) => {
expect(postRequests.length).equal(1);
const request = postRequests[0];
expect(JSON.stringify(await request.json())).equal(
JSON.stringify({
_id: 'new_user',
sha256_password: 'secure_password',
auth_type: 'local',
authorised_routes: ['/submit/hdf POST', '/users PATCH'],
})
);
}
);
});

it('adds user successfully (fedId)', () => {
cy.findByLabelText('Username').type('new_user');

cy.findAllByRole('combobox').first().click();
cy.findByRole('option', { name: 'FedID' }).click();

cy.startSnoopingBrowserMockedRequest();

cy.findByRole('button', { name: 'Submit' }).click();

cy.findBrowserMockedRequests({ method: 'POST', url: '/users' }).should(
async (postRequests) => {
expect(postRequests.length).equal(1);
const request = postRequests[0];
expect(JSON.stringify(await request.json())).equal(
JSON.stringify({
_id: 'new_user',
auth_type: 'FedID',
})
);
}
);
});

it('displays error when adding a user without a password for "local" auth_type', () => {
cy.findByLabelText('Username').type('local_user');
cy.findByRole('button', { name: 'Submit' }).click();
cy.findByText(
'for the auth_type you put (local), a password is required. Please add this field'
).should('exist');
});

it('displays error for duplicate username', () => {
cy.findByLabelText('Username').type('test_dup');
cy.findByLabelText('Password').type('secure_password');
cy.findByRole('button', { name: 'Submit' }).click();
cy.findByText(
'username field must not be the same as a pre existing user. You put: test_dup'
).should('exist');
});

it('displays general error for unknown issues', () => {
cy.findByLabelText('Username').type('error');
cy.findByLabelText('Password').type('secure_password');
cy.findByRole('button', { name: 'Submit' }).click();
cy.findByText(
'An unexpected error occurred. Please try again later.'
).should('exist');
});

it('should show and hide password when clicking the visibility toggle', () => {
cy.findByLabelText('Username').type('testuser');
cy.findByLabelText('Password').type('secure_password');

cy.findByLabelText('Password').should('have.attr', 'type', 'password');

cy.findByLabelText('Show password').click();

cy.findByLabelText('Password').should('have.attr', 'type', 'text');

cy.findByLabelText('Hide password').click();

cy.findByLabelText('Password').should('have.attr', 'type', 'password');
});
});
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@emotion/react": "11.14.0",
"@emotion/styled": "11.14.0",
"@hello-pangea/dnd": "17.0.0",
"@hookform/resolvers": "^3.9.1",
"@mui/base": "5.0.0-beta.40",
"@mui/icons-material": "5.16.2",
"@mui/material": "5.16.2",
Expand Down Expand Up @@ -37,11 +38,13 @@
"react": "18.3.1",
"react-colorful": "5.6.1",
"react-dom": "18.3.1",
"react-hook-form": "^7.53.2",
"react-redux": "9.2.0",
"react-router-dom": "7.1.1",
"single-spa-react": "6.0.2",
"typescript": "5.6.2",
"vite": "5.4.11"
"vite": "5.4.11",
"zod": "^3.23.8"
},
"resolutions": {
"nwsapi": "2.2.13",
Expand Down
67 changes: 59 additions & 8 deletions src/admin/users/__snapshots__/usersTable.component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,60 @@ exports[`UsersTable Snapshot > matches snapshot 1`] = `
</p>
</div>
<div
class="MuiBox-root css-zrlv9q"
class="MuiBox-root css-wsew38"
>
<span />
<div
class="MuiBox-root css-0"
>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedPrimary MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorPrimary MuiButton-root MuiButton-outlined MuiButton-outlinedPrimary MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorPrimary css-1owl11-MuiButtonBase-root-MuiButton-root"
tabindex="0"
type="button"
>
<span
class="MuiButton-icon MuiButton-startIcon MuiButton-iconSizeMedium css-1d6wzja-MuiButton-startIcon"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="AddIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6z"
/>
</svg>
</span>
Add User
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedPrimary MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorPrimary Mui-disabled MuiButton-root MuiButton-outlined MuiButton-outlinedPrimary MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorPrimary css-1owl11-MuiButtonBase-root-MuiButton-root"
disabled=""
tabindex="-1"
type="button"
>
<span
class="MuiButton-icon MuiButton-startIcon MuiButton-iconSizeMedium css-1d6wzja-MuiButton-startIcon"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="ClearIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
/>
</svg>
</span>
Clear Filters
</button>
</div>
<div
class="MuiBox-root css-1p0wbhh"
>
Expand Down Expand Up @@ -217,15 +268,15 @@ exports[`UsersTable Snapshot > matches snapshot 1`] = `
<div
class="Mui-TableHeadCell-Content-Wrapper MuiBox-root css-lapokc"
>
User ID
Username
</div>
<span
aria-label="Sort by User ID descending"
aria-label="Sort by Username descending"
class="MuiBadge-root css-1c32n2y-MuiBadge-root"
data-mui-internal-clone-element="true"
>
<span
aria-label="Sort by User ID descending"
aria-label="Sort by Username descending"
class="MuiButtonBase-root MuiTableSortLabel-root Mui-active css-118d58w-MuiButtonBase-root-MuiTableSortLabel-root"
role="button"
tabindex="0"
Expand Down Expand Up @@ -316,12 +367,12 @@ exports[`UsersTable Snapshot > matches snapshot 1`] = `
>
<input
aria-invalid="false"
aria-label="Filter by User ID"
aria-label="Filter by Username"
autocomplete="new-password"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedEnd css-929hxt-MuiInputBase-input-MuiInput-input"
id=":r7:"
placeholder="Filter by User ID"
title="Filter by User ID"
placeholder="Filter by Username"
title="Filter by Username"
type="text"
value=""
/>
Expand Down
Loading
Loading