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

Ws 119/admin listing page #6179

Merged
merged 44 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f1a1e6d
Create mocked search API endpoint
robmarch2 Mar 4, 2021
8676776
Add react router dependency
robmarch2 Mar 4, 2021
ad11160
Create middleware API caller with typed response
robmarch2 Mar 4, 2021
a6e2dd1
Create utils for building search URLs
robmarch2 Mar 4, 2021
7bdbd19
Create search components
robmarch2 Mar 4, 2021
9506630
Add search component to homepage
robmarch2 Mar 4, 2021
dcdbe74
Add stylesheets
robmarch2 Mar 4, 2021
bafdfaf
Expand pagination component
robmarch2 Mar 4, 2021
8f79bfc
Remove magic numbers from pagination
robmarch2 Mar 4, 2021
f0a096c
Remove intermediate state on search forms
robmarch2 Mar 4, 2021
2b3c3a2
Hide placeholder text on status dropdown
robmarch2 Mar 4, 2021
a0df4a4
Fix linting issue
robmarch2 Mar 4, 2021
35679e7
Remove unnecessary dependency
robmarch2 Mar 4, 2021
e7a82cd
Provide default value for page in mock API
robmarch2 Mar 4, 2021
b730b8b
Use query string to build search URLs
robmarch2 Mar 4, 2021
d7e892c
Make page number cast in mock API more explicit
robmarch2 Mar 4, 2021
48069ee
Merge branches 'master' and 'WS-119/admin-listing-page' of https://gi…
robmarch2 Mar 9, 2021
2d80d91
Remove app CSS
robmarch2 Mar 9, 2021
ab83f28
Use standardised pretty date module
robmarch2 Mar 9, 2021
36d0853
Remove unnecessary dependency
robmarch2 Mar 9, 2021
1a59d01
Use correct query string library to build URLs
robmarch2 Mar 9, 2021
aac2a27
Simplify last login date field
robmarch2 Mar 10, 2021
f6bfa4c
Remove redundant sort field check
robmarch2 Mar 10, 2021
115a802
Add pagination tests
robmarch2 Mar 10, 2021
a876b05
Add sorter tests
robmarch2 Mar 10, 2021
1683380
Add status dropdown tests
robmarch2 Mar 10, 2021
1eb0f09
UI and UX changes to make the user listing page
robmarch2 Mar 17, 2021
1e26551
Improve styling of status dropdown
robmarch2 Mar 23, 2021
26ceba6
Merge branch 'master' of https://github.com/wellcomecollection/wellco…
robmarch2 Mar 23, 2021
d2cc332
Ensure correct query param is used to build search URL
robmarch2 Mar 23, 2021
c5079d8
Style user list item to appear clickable
robmarch2 Mar 24, 2021
7053bbc
Integrate user listing page with real API
robmarch2 Mar 24, 2021
366645b
Remove unusable sort field
robmarch2 Mar 24, 2021
e0dcbc1
Improve pagingation tests
robmarch2 Mar 31, 2021
1a8859a
Improve sorter tests
robmarch2 Mar 31, 2021
c3167b8
Improve status dropdown tests
robmarch2 Mar 31, 2021
f34c2a0
Remove unnecessary logging from test
robmarch2 Mar 31, 2021
2506f92
Wrap user list entry in link
robmarch2 Mar 31, 2021
f208633
Update yarn.lock
robmarch2 Mar 31, 2021
c635a6f
Merge branches 'master' and 'WS-119/admin-listing-page' of https://gi…
robmarch2 Mar 31, 2021
bb5d259
Update yarn.lock
robmarch2 Mar 31, 2021
d5b81fc
Improve selctors for tests
robmarch2 Apr 1, 2021
f123a89
Improved semantics for table header
robmarch2 Apr 1, 2021
7c9156d
Increase contrast of disabled pagination links
robmarch2 Apr 1, 2021
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
49 changes: 17 additions & 32 deletions identity-admin/webapp/components/search/StatusDropdown.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import StatusDropdown from './StatusDropdown';
import { buildSearchUrl } from '../../utils/search-util';

jest.mock('next/router', () => ({
useRouter: () => {
Expand All @@ -17,34 +16,23 @@ jest.mock('next/router', () => ({
}));

const renderComponent = () => render(<StatusDropdown />);
const getOptions = (container: HTMLElement) =>
container.getElementsByClassName('status-dropdown__option');
const clickToggle = (container: HTMLElement) => {
const label = container.querySelector('.status-dropdown__label');
if (label) {
fireEvent.click(label);
} else {
fail('Unable to find label');
}
};
const getLabelArrow = (container: HTMLElement) =>
container.getElementsByClassName('status-dropdown__label-arrow');
const getOptions = () => screen.getAllByRole('link');
const clickToggle = () => fireEvent.click(screen.getByRole('dropdown'));
const getLabelArrow = () => screen.getAllByRole('label')[1];
const expectedUrl = (statusValue: string) =>
buildSearchUrl('1', statusValue, 'Bob', 'bob@email.com');
'/?email=bob%40email.com&name=Bob&page=1&status=' + statusValue;

describe('Status dropdown', () => {
it('is initially collapsed', () => {
const { container } = renderComponent();
const options = getOptions(container);
expect(options.length).toBe(0);
const labelArrow = getLabelArrow(container)[0];
expect(labelArrow).toHaveTextContent('▾');
renderComponent();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
expect(getLabelArrow()).toHaveTextContent('▾');
});

it('expands on initial click', () => {
const { container } = renderComponent();
clickToggle(container);
const options = getOptions(container);
renderComponent();
clickToggle();
const options = getOptions();
expect(options.length).toBe(4);
expect(options[0]).toHaveTextContent('Any');
expect(options[0]).toHaveAttribute('href', expectedUrl('any'));
Expand All @@ -54,17 +42,14 @@ describe('Status dropdown', () => {
expect(options[2]).toHaveAttribute('href', expectedUrl('locked'));
expect(options[3]).toHaveTextContent('Pending delete');
expect(options[3]).toHaveAttribute('href', expectedUrl('deletePending'));
const labelArrow = getLabelArrow(container)[0];
expect(labelArrow).toHaveTextContent('▴');
expect(getLabelArrow()).toHaveTextContent('▴');
});

it('collapses on second click', () => {
const { container } = renderComponent();
clickToggle(container);
clickToggle(container);
const options = getOptions(container);
expect(options.length).toBe(0);
const labelArrow = getLabelArrow(container)[0];
expect(labelArrow).toHaveTextContent('▾');
renderComponent();
clickToggle();
clickToggle();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
expect(getLabelArrow()).toHaveTextContent('▾');
});
});
16 changes: 10 additions & 6 deletions identity-admin/webapp/components/search/StatusDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,26 @@ const StatusDropdown = (): JSX.Element => {

return (
<div className="status-dropdown">
<div className="status-dropdown__label" onClick={toggleExpansion}>
<span>{statusLabel()}</span>
<span className="status-dropdown__label-arrow">
<div
role="dropdown"
ajrussellaudio marked this conversation as resolved.
Show resolved Hide resolved
className="status-dropdown__label"
onClick={toggleExpansion}
>
<span role="label">{statusLabel()}</span>
<span role="label" className="status-dropdown__label-arrow">
{isExpanded ? '▴' : '▾'}
</span>
</div>
{isExpanded && (
<div className="status-dropdown__options">
{statuses.map((s, i) => {
{statuses.map((statusEntry, i) => {
return (
<a
className="status-dropdown__option"
key={i}
href={buildSearchUrl('1', s.key, name, email)}
href={buildSearchUrl('1', statusEntry.key, name, email)}
>
{s.value}
{statusEntry.value}
</a>
);
})}
Expand Down