Skip to content

Commit

Permalink
Merge pull request #1226 from ral-facilities/feature/order-downloads-…
Browse files Browse the repository at this point in the history
…by-requested-date-#1176

Download tables sort by requested time descending by default #1176
  • Loading branch information
Sam Glendenning authored Apr 20, 2022
2 parents 255e8a0 + 68acecb commit 3cb1ca2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ describe('Admin Download Status', () => {

describe('should be able to sort download items by', () => {
it('ascending order', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.get('.react-draggable')
.eq(7)
.trigger('mousedown')
.trigger('mousemove', { clientX: 800 })
.trigger('mouseup');
cy.contains('[role="button"]', 'Requested Date').click();

cy.get('.react-draggable')
.eq(4)
.trigger('mousedown')
Expand All @@ -69,6 +77,14 @@ describe('Admin Download Status', () => {
});

it('descending order', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.get('.react-draggable')
.eq(7)
.trigger('mousedown')
.trigger('mousemove', { clientX: 800 })
.trigger('mouseup');
cy.contains('[role="button"]', 'Requested Date').click();

cy.get('.react-draggable')
.eq(4)
.trigger('mousedown')
Expand All @@ -90,6 +106,14 @@ describe('Admin Download Status', () => {
});

it('no order', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.get('.react-draggable')
.eq(7)
.trigger('mousedown')
.trigger('mousemove', { clientX: 800 })
.trigger('mouseup');
cy.contains('[role="button"]', 'Requested Date').click();

cy.get('.react-draggable')
.eq(3)
.trigger('mousedown')
Expand All @@ -116,6 +140,14 @@ describe('Admin Download Status', () => {
});

it('multiple columns', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.get('.react-draggable')
.eq(7)
.trigger('mousedown')
.trigger('mousemove', { clientX: 800 })
.trigger('mouseup');
cy.contains('[role="button"]', 'Requested Date').click();

cy.get('.react-draggable')
.eq(4)
.trigger('mousedown')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ describe('Download Status', () => {

describe('should be able to sort download items by', () => {
it('ascending order', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.contains('[role="button"]', 'Requested Date').click();

cy.contains('[role="button"]', 'Download Name').click();

cy.get('[aria-sort="ascending"]').should('exist');
Expand All @@ -58,6 +61,9 @@ describe('Download Status', () => {
});

it('descending order', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.contains('[role="button"]', 'Requested Date').click();

cy.contains('[role="button"]', 'Download Name').click();
cy.contains('[role="button"]', 'Download Name').click();

Expand All @@ -79,6 +85,9 @@ describe('Download Status', () => {
});

it('no order', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.contains('[role="button"]', 'Requested Date').click();

cy.contains('[role="button"]', 'Download Name').click();
cy.contains('[role="button"]', 'Download Name').click();
cy.contains('[role="button"]', 'Download Name').click();
Expand All @@ -102,6 +111,9 @@ describe('Download Status', () => {
});

it('multiple columns', () => {
// Table is sorted by Requested Date by default. To keep working test, we will remove all sorts on the table beforehand
cy.contains('[role="button"]', 'Requested Date').click();

cy.contains('[role="button"]', 'Access Method').click();
cy.contains('[role="button"]', 'Availability').click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ exports[`Admin Download Status Table renders correctly 1`] = `
loadMoreRows={[Function]}
loading={true}
onSort={[Function]}
sort={Object {}}
sort={
Object {
"createdAt": "desc",
}
}
totalRowCount={9007199254740991}
/>
</WithStyles(ForwardRef(Paper))>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ exports[`Download Status Table renders correctly 1`] = `
data={Array []}
loading={true}
onSort={[Function]}
sort={Object {}}
sort={
Object {
"createdAt": "desc",
}
}
/>
</WithStyles(ForwardRef(Paper))>
</WithStyles(ForwardRef(Grid))>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('Admin Download Status Table', () => {
expect(wrapper).toMatchSnapshot();
});

it('fetches the download items on load', async () => {
it('fetches the download items and sorts by download requested time desc on load ', async () => {
const wrapper = mount(
<div id="datagateway-download">
<AdminDownloadStatusTable />
Expand All @@ -164,7 +164,7 @@ describe('Admin Download Status Table', () => {
expect(fetchAdminDownloads).toHaveBeenNthCalledWith(
1,
{ downloadApiUrl: '', facilityName: '' },
"WHERE UPPER(download.facilityName) = '' ORDER BY UPPER(download.id) ASC LIMIT 0, 50"
"WHERE UPPER(download.facilityName) = '' ORDER BY UPPER(download.createdAt) desc, UPPER(download.id) ASC LIMIT 0, 50"
);
expect(wrapper.exists('[aria-rowcount=5]')).toBe(true);
});
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('Admin Download Status Table', () => {
expect(fetchAdminDownloads).toHaveBeenCalledTimes(3);
expect(fetchAdminDownloads).toHaveBeenLastCalledWith(
{ downloadApiUrl: '', facilityName: '' },
"WHERE UPPER(download.facilityName) = '' ORDER BY UPPER(download.id) ASC LIMIT 5, 5"
"WHERE UPPER(download.facilityName) = '' ORDER BY UPPER(download.createdAt) desc, UPPER(download.id) ASC LIMIT 5, 5"
);
expect(wrapper.exists('[aria-rowcount=5]')).toBe(true);
});
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('Admin Download Status Table', () => {
expect(fetchAdminDownloads).toHaveBeenNthCalledWith(
3,
{ downloadApiUrl: '', facilityName: '' },
"WHERE UPPER(download.facilityName) = '' ORDER BY UPPER(download.id) ASC LIMIT 0, 50"
"WHERE UPPER(download.facilityName) = '' ORDER BY UPPER(download.createdAt) desc, UPPER(download.id) ASC LIMIT 0, 50"
);
expect(wrapper.exists('[aria-rowcount=5]')).toBe(true);
});
Expand All @@ -271,6 +271,17 @@ describe('Admin Download Status Table', () => {
wrapper.update();
});

// Table is sorted by createdAt desc by default
// To keep working test, we will remove all sorts on the table beforehand
const createdAtSortLabel = wrapper
.find('[role="columnheader"] span[role="button"]')
.at(6);
await act(async () => {
createdAtSortLabel.simulate('click');
await flushPromises();
wrapper.update();
});

// Get the Username sort header
const usernameSortLabel = wrapper
.find('[role="columnheader"] span[role="button"]')
Expand Down Expand Up @@ -336,6 +347,17 @@ describe('Admin Download Status Table', () => {
wrapper.update();
});

// Table is sorted by createdAt desc by default
// To keep working test, we will remove all sorts on the table beforehand
const createdAtSortLabel = wrapper
.find('[role="columnheader"] span[role="button"]')
.at(6);
await act(async () => {
createdAtSortLabel.simulate('click');
await flushPromises();
wrapper.update();
});

// Get the Username filter input
const usernameFilterInput = wrapper
.find('[aria-label="Filter by downloadStatus.username"]')
Expand Down Expand Up @@ -410,6 +432,17 @@ describe('Admin Download Status Table', () => {
wrapper.update();
});

// Table is sorted by createdAt desc by default
// To keep working test, we will remove all sorts on the table beforehand
const createdAtSortLabel = wrapper
.find('[role="columnheader"] span[role="button"]')
.at(6);
await act(async () => {
createdAtSortLabel.simulate('click');
await flushPromises();
wrapper.update();
});

// Get the Requested Data From filter input
const dateFromFilterInput = wrapper.find(
'input[id="downloadStatus.createdAt filter from"]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const AdminDownloadStatusTable: React.FC = () => {
// Load the settings for use
const settings = React.useContext(DownloadSettingsContext);
// Sorting columns
const [sort, setSort] = React.useState<{ [column: string]: Order }>({});
const [sort, setSort] = React.useState<{ [column: string]: Order }>({
createdAt: 'desc',
});
const [filters, setFilters] = React.useState<{
[column: string]:
| { value?: string | number; type: string }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ describe('Download Status Table', () => {
wrapper.update();
});

// Table is sorted by createdAt desc by default
// To keep working test, we will remove all sorts on the table beforehand
const createdAtSortLabel = wrapper
.find('[role="columnheader"] span[role="button"]')
.at(3);
createdAtSortLabel.simulate('click');

const firstNameCell = wrapper.find('[aria-colindex=1]').find('p').first();

// Get the access method sort header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const DownloadStatusTable: React.FC<DownloadStatusTableProps> = (
const settings = React.useContext(DownloadSettingsContext);

// Sorting columns
const [sort, setSort] = React.useState<{ [column: string]: Order }>({});
const [sort, setSort] = React.useState<{ [column: string]: Order }>({
createdAt: 'desc',
});
const [filters, setFilters] = React.useState<{
[column: string]:
| { value?: string | number; type: string }
Expand Down

0 comments on commit 3cb1ca2

Please sign in to comment.