-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fca718
commit 58e1acd
Showing
7 changed files
with
253 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 50 additions & 50 deletions
100
src/Configuration/Customers/CustomerDetailView/EnterpriseCustomerUsersTable.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
import { useParams } from 'react-router-dom'; | ||
import { Container, DataTable, TextFilter } from '@openedx/paragon'; | ||
import { DataTable, TextFilter } from '@openedx/paragon'; | ||
import { EnterpriseCustomerUserDetail, LearnerCell, AdministratorCell } from './EnterpriseCustomerUserDetail'; | ||
import useEnterpriseUsersTableData from '../data/hooks/useCustomerUsersTableData'; | ||
import useCustomerUsersTableData from '../data/hooks/useCustomerUsersTableData'; | ||
|
||
const EnterpriseCustomerUsersTable = () => { | ||
const { id } = useParams(); | ||
const { | ||
isLoading, | ||
enterpriseUsersTableData, | ||
fetchEnterpriseUsersData, | ||
} = useEnterpriseUsersTableData(id); | ||
} = useCustomerUsersTableData(id); | ||
return ( | ||
<Container> | ||
<h2>Associated users ({ enterpriseUsersTableData.itemCount })</h2> | ||
<div> | ||
<h2>Associated users ({enterpriseUsersTableData.itemCount})</h2> | ||
<hr /> | ||
<DataTable | ||
isLoading={isLoading} | ||
isExpandable | ||
isSortable | ||
manualSortBy | ||
isPaginated | ||
manualPagination | ||
isFilterable | ||
manualFilters | ||
initialState={{ | ||
pageSize: 8, | ||
pageIndex: 0, | ||
sortBy: [], | ||
filters: [], | ||
}} | ||
defaultColumnValues={{ Filter: TextFilter }} | ||
fetchData={fetchEnterpriseUsersData} | ||
data={enterpriseUsersTableData.results} | ||
itemCount={enterpriseUsersTableData.itemCount} | ||
pageCount={enterpriseUsersTableData.pageCount} | ||
columns={[ | ||
{ | ||
id: 'userDetails', | ||
Header: 'User details', | ||
accessor: 'userDetails', | ||
Cell: EnterpriseCustomerUserDetail, | ||
}, | ||
{ | ||
id: 'administrator', | ||
Header: 'Administrator', | ||
accessor: 'administrator', | ||
disableFilters: true, | ||
Cell: AdministratorCell, | ||
}, | ||
{ | ||
id: 'learner', | ||
Header: 'Learner', | ||
accessor: 'learner', | ||
disableFilters: true, | ||
Cell: LearnerCell, | ||
}, | ||
]} | ||
/> | ||
</Container> | ||
<DataTable | ||
isLoading={isLoading} | ||
isExpandable | ||
isSortable | ||
manualSortBy | ||
isPaginated | ||
manualPagination | ||
isFilterable | ||
manualFilters | ||
initialState={{ | ||
pageSize: 8, | ||
pageIndex: 0, | ||
sortBy: [], | ||
filters: [], | ||
}} | ||
defaultColumnValues={{ Filter: TextFilter }} | ||
fetchData={fetchEnterpriseUsersData} | ||
data={enterpriseUsersTableData.results} | ||
itemCount={enterpriseUsersTableData.itemCount} | ||
pageCount={enterpriseUsersTableData.pageCount} | ||
columns={[ | ||
{ | ||
id: 'details', | ||
Header: 'User details', | ||
accessor: 'details', | ||
Cell: EnterpriseCustomerUserDetail, | ||
}, | ||
{ | ||
id: 'administrator', | ||
Header: 'Administrator', | ||
accessor: 'administrator', | ||
disableFilters: true, | ||
Cell: AdministratorCell, | ||
}, | ||
{ | ||
id: 'learner', | ||
Header: 'Learner', | ||
accessor: 'learner', | ||
disableFilters: true, | ||
Cell: LearnerCell, | ||
}, | ||
]} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EnterpriseCustomerUsersTable; | ||
export default EnterpriseCustomerUsersTable; |
80 changes: 80 additions & 0 deletions
80
src/Configuration/Customers/CustomerDetailView/tests/EnterpriseCustomerUserDetail.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-disable react/prop-types */ | ||
import { | ||
screen, | ||
render, | ||
} from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { | ||
EnterpriseCustomerUserDetail, | ||
AdministratorCell, | ||
LearnerCell, | ||
} from '../EnterpriseCustomerUserDetail'; | ||
|
||
describe('EnterpriseCustomerUserDetail', () => { | ||
it('renders enterprise customer detail', () => { | ||
const enterpriseCustomerUser = { | ||
original: { | ||
enterpriseCustomerUser: { | ||
username: 'ash ketchum', | ||
email: 'ash@ketchum.org', | ||
}, | ||
}, | ||
}; | ||
render(<EnterpriseCustomerUserDetail row={enterpriseCustomerUser} />); | ||
expect(screen.getByText('ash ketchum')).toBeInTheDocument(); | ||
expect(screen.getByText('ash@ketchum.org')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders pending enterprise customer detail', () => { | ||
const pendingEnterpriseCustomerUser = { | ||
original: { | ||
pendingEnterpriseCustomerUser: { | ||
userEmail: 'pending@customer.org', | ||
}, | ||
}, | ||
}; | ||
render(<EnterpriseCustomerUserDetail row={pendingEnterpriseCustomerUser} />); | ||
expect(screen.getByText('pending@customer.org')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders AdministratorCell there is a pending admin', () => { | ||
const pendingAdmin = { | ||
original: { | ||
pendingEnterpriseCustomerUser: { | ||
isPendingAdmin: true, | ||
}, | ||
roleAssignments: ['enterprise_learner'], | ||
}, | ||
}; | ||
render(<AdministratorCell row={pendingAdmin} />); | ||
expect(screen.getByText('Pending')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders AdministratorCell there is a registered admin', () => { | ||
const adminRow = { | ||
original: { | ||
pendingEnterpriseCustomerUser: { | ||
isPendingAdmin: false, | ||
}, | ||
roleAssignments: ['enterprise_admin'], | ||
}, | ||
}; | ||
render(<AdministratorCell row={adminRow} />); | ||
expect(screen.queryByText('Pending')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders LearnerCell there is a registered learner and not pendning', () => { | ||
const learnerRow = { | ||
original: { | ||
pendingEnterpriseCustomerUser: null, | ||
enterpriseCustomerUser: { | ||
username: 'ash ketchum', | ||
email: 'ash@ketchum.org', | ||
}, | ||
roleAssignments: ['enterprise_learner'], | ||
}, | ||
}; | ||
render(<LearnerCell row={learnerRow} />); | ||
expect(screen.queryByText('Pending')).not.toBeInTheDocument(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
src/Configuration/Customers/CustomerDetailView/tests/EnterpriseCustomerUsersTable.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable react/prop-types */ | ||
import { screen, render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import EnterpriseCustomerUsersTable from '../EnterpriseCustomerUsersTable'; | ||
import useCustomerUsersTableData from '../../data/hooks/useCustomerUsersTableData'; | ||
|
||
const mockData = { | ||
isLoading: false, | ||
enterpriseUsersTableData: { | ||
itemCount: 2, | ||
pageCount: 1, | ||
results: [ | ||
{ | ||
enterpriseCustomerUser: { | ||
username: 'ash ketchum', | ||
email: 'ash@ketchum.org', | ||
}, | ||
pendingEnterpriseCustomerUser: null, | ||
roleAssignments: ['enterprise_learner'], | ||
}, | ||
{ | ||
enterpriseCustomerUser: { | ||
username: 'misty', | ||
email: 'misty@pokemon.org', | ||
}, | ||
pendingEnterpriseCustomerUser: null, | ||
roleAssignments: ['enterprise_admin'], | ||
}, | ||
], | ||
fetchEnterpriseUsersData: jest.fn(), | ||
}, | ||
}; | ||
|
||
jest.mock('../../data/hooks/useCustomerUsersTableData'); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: () => ({ id: 'test-uuid' }), | ||
})); | ||
|
||
describe('EnterpriseCustomerUsersTable', () => { | ||
it('renders the datatable with data', () => { | ||
useCustomerUsersTableData.mockReturnValue(mockData); | ||
|
||
render( | ||
<IntlProvider locale="en"> | ||
<EnterpriseCustomerUsersTable /> | ||
</IntlProvider>, | ||
); | ||
expect(screen.getByText('Search user details')).toBeInTheDocument(); | ||
expect(screen.getByText('User details')).toBeInTheDocument(); | ||
expect(screen.getByText('Administrator')).toBeInTheDocument(); | ||
expect(screen.getByText('Learner')).toBeInTheDocument(); | ||
expect(screen.getByText('ash ketchum')).toBeInTheDocument(); | ||
expect(screen.getByText('ash@ketchum.org')).toBeInTheDocument(); | ||
expect(screen.getByTestId('learner check')); | ||
|
||
expect(screen.getByText('misty')).toBeInTheDocument(); | ||
expect(screen.getByText('misty@pokemon.org')).toBeInTheDocument(); | ||
expect(screen.getByTestId('admin check')).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.