diff --git a/packages/datagateway-common/package.json b/packages/datagateway-common/package.json index bd17bab54..33969ab7f 100644 --- a/packages/datagateway-common/package.json +++ b/packages/datagateway-common/package.json @@ -43,6 +43,7 @@ "react-router-dom": ">= 5.2.0 < 6" }, "devDependencies": { + "@babel/eslint-parser": "7.22.5", "@mui/icons-material": "5.11.0", "@mui/material": "5.11.0", "@testing-library/jest-dom": "5.16.4", @@ -56,7 +57,6 @@ "@types/react-virtualized": "9.21.10", "@typescript-eslint/eslint-plugin": "5.61.0", "@typescript-eslint/parser": "5.61.0", - "@babel/eslint-parser": "7.22.5", "eslint": "8.44.0", "eslint-config-prettier": "8.8.0", "eslint-config-react-app": "7.0.0", diff --git a/packages/datagateway-common/src/api/dataPublications.test.tsx b/packages/datagateway-common/src/api/dataPublications.test.tsx index 43f83dcd0..660515e45 100644 --- a/packages/datagateway-common/src/api/dataPublications.test.tsx +++ b/packages/datagateway-common/src/api/dataPublications.test.tsx @@ -36,7 +36,7 @@ describe('data publications api functions', () => { ]; history = createMemoryHistory({ initialEntries: [ - '/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', + '/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', ], }); params = new URLSearchParams(); @@ -53,7 +53,7 @@ describe('data publications api functions', () => { data: mockData, }); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useDataPublicationsPaginated([ { @@ -74,6 +74,7 @@ describe('data publications api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -103,6 +104,16 @@ describe('data publications api functions', () => { params.toString() ); expect(result.current.data).toEqual(mockData); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2); }); it('sends axios request to fetch paginated data publications and calls handleICATError on failure', async () => { @@ -143,7 +154,7 @@ describe('data publications api functions', () => { : Promise.resolve({ data: mockData[1] }) ); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useDataPublicationsInfinite([ { @@ -164,6 +175,7 @@ describe('data publications api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -219,6 +231,16 @@ describe('data publications api functions', () => { mockData[0], mockData[1], ]); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3); }); it('sends axios request to fetch infinite data publications and calls handleICATError on failure', async () => { diff --git a/packages/datagateway-common/src/api/dataPublications.tsx b/packages/datagateway-common/src/api/dataPublications.tsx index c7ceb40bf..00cb55897 100644 --- a/packages/datagateway-common/src/api/dataPublications.tsx +++ b/packages/datagateway-common/src/api/dataPublications.tsx @@ -67,7 +67,7 @@ export const useDataPublicationsPaginated = ( [ string, { - sort: SortType; + sort: string; filters: FiltersType; page: number; results: number; @@ -77,11 +77,16 @@ export const useDataPublicationsPaginated = ( >( [ 'dataPublication', - { sort, filters, page: page ?? 1, results: results ?? 10 }, + { + sort: JSON.stringify(sort), // need to stringify sort as property order is important! + filters, + page: page ?? 1, + results: results ?? 10, + }, additionalFilters, ], (params) => { - const { sort, filters, page, results } = params.queryKey[1]; + const { page, results } = params.queryKey[1]; const startIndex = (page - 1) * results; const stopIndex = startIndex + results - 1; return fetchDataPublications( @@ -110,15 +115,13 @@ export const useDataPublicationsInfinite = ( const location = useLocation(); const { filters, sort } = parseSearchToQuery(location.search); - return useInfiniteQuery< - DataPublication[], - AxiosError, - DataPublication[], - [string, { sort: SortType; filters: FiltersType }, AdditionalFilters?] - >( - ['dataPublication', { sort, filters }, additionalFilters], + return useInfiniteQuery( + [ + 'dataPublication', + { sort: JSON.stringify(sort), filters }, // need to stringify sort as property order is important! + additionalFilters, + ], (params) => { - const { sort, filters } = params.queryKey[1]; const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 }; return fetchDataPublications( apiUrl, diff --git a/packages/datagateway-common/src/api/datafiles.test.tsx b/packages/datagateway-common/src/api/datafiles.test.tsx index 3e888fa7e..9354faea6 100644 --- a/packages/datagateway-common/src/api/datafiles.test.tsx +++ b/packages/datagateway-common/src/api/datafiles.test.tsx @@ -40,7 +40,7 @@ describe('datafile api functions', () => { ]; history = createMemoryHistory({ initialEntries: [ - '/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', + '/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', ], }); params = new URLSearchParams(); @@ -58,7 +58,7 @@ describe('datafile api functions', () => { data: mockData, }); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useDatafilesPaginated([ { @@ -76,6 +76,7 @@ describe('datafile api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -102,6 +103,16 @@ describe('datafile api functions', () => { params.toString() ); expect(result.current.data).toEqual(mockData); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2); }); it('sends axios request to fetch paginated datafiles and calls handleICATError on failure', async () => { @@ -139,7 +150,7 @@ describe('datafile api functions', () => { : Promise.resolve({ data: mockData[1] }) ); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useDatafilesInfinite([ { @@ -157,6 +168,7 @@ describe('datafile api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -209,6 +221,16 @@ describe('datafile api functions', () => { mockData[0], mockData[1], ]); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3); }); it('sends axios request to fetch infinite datafiles and calls handleICATError on failure', async () => { diff --git a/packages/datagateway-common/src/api/datafiles.tsx b/packages/datagateway-common/src/api/datafiles.tsx index 976bfd410..82cad3bf0 100644 --- a/packages/datagateway-common/src/api/datafiles.tsx +++ b/packages/datagateway-common/src/api/datafiles.tsx @@ -69,7 +69,7 @@ export const useDatafilesPaginated = ( [ string, { - sort: SortType; + sort: string; filters: FiltersType; page: number; results: number; @@ -79,11 +79,16 @@ export const useDatafilesPaginated = ( >( [ 'datafile', - { sort, filters, page: page ?? 1, results: results ?? 10 }, + { + sort: JSON.stringify(sort), // need to stringify sort as property order is important! + filters, + page: page ?? 1, + results: results ?? 10, + }, additionalFilters, ], (params) => { - const { sort, filters, page, results } = params.queryKey[1]; + const { page, results } = params.queryKey[1]; const startIndex = (page - 1) * results; const stopIndex = startIndex + results - 1; return fetchDatafiles(apiUrl, { sort, filters }, additionalFilters, { @@ -107,15 +112,9 @@ export const useDatafilesInfinite = ( const location = useLocation(); const { filters, sort } = parseSearchToQuery(location.search); - return useInfiniteQuery< - Datafile[], - AxiosError, - Datafile[], - [string, { sort: SortType; filters: FiltersType }, AdditionalFilters?] - >( - ['datafile', { sort, filters }, additionalFilters], + return useInfiniteQuery( + ['datafile', { sort: JSON.stringify(sort), filters }, additionalFilters], // need to stringify sort as property order is important! (params) => { - const { sort, filters } = params.queryKey[1]; const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 }; return fetchDatafiles( apiUrl, diff --git a/packages/datagateway-common/src/api/datasets.test.tsx b/packages/datagateway-common/src/api/datasets.test.tsx index d9d874fe6..1d1d0ccd5 100644 --- a/packages/datagateway-common/src/api/datasets.test.tsx +++ b/packages/datagateway-common/src/api/datasets.test.tsx @@ -45,7 +45,7 @@ describe('dataset api functions', () => { ]; history = createMemoryHistory({ initialEntries: [ - '/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', + '/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', ], }); params = new URLSearchParams(); @@ -126,7 +126,7 @@ describe('dataset api functions', () => { data: mockData, }); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useDatasetsPaginated([ { @@ -144,6 +144,7 @@ describe('dataset api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -170,6 +171,16 @@ describe('dataset api functions', () => { params.toString() ); expect(result.current.data).toEqual(mockData); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2); }); it('sends axios request to fetch paginated datasets and calls handleICATError on failure', async () => { @@ -207,7 +218,7 @@ describe('dataset api functions', () => { : Promise.resolve({ data: mockData[1] }) ); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useDatasetsInfinite([ { @@ -225,6 +236,7 @@ describe('dataset api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -277,6 +289,16 @@ describe('dataset api functions', () => { mockData[0], mockData[1], ]); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3); }); it('sends axios request to fetch infinite datasets and calls handleICATError on failure', async () => { diff --git a/packages/datagateway-common/src/api/datasets.tsx b/packages/datagateway-common/src/api/datasets.tsx index 08c274f01..092c629f6 100644 --- a/packages/datagateway-common/src/api/datasets.tsx +++ b/packages/datagateway-common/src/api/datasets.tsx @@ -108,7 +108,7 @@ export const useDatasetsPaginated = ( [ string, { - sort: SortType; + sort: string; filters: FiltersType; page: number; results: number; @@ -118,11 +118,16 @@ export const useDatasetsPaginated = ( >( [ 'dataset', - { sort, filters, page: page ?? 1, results: results ?? 10 }, + { + sort: JSON.stringify(sort), // need to stringify sort as property order is important! + filters, + page: page ?? 1, + results: results ?? 10, + }, additionalFilters, ], (params) => { - const { sort, filters, page, results } = params.queryKey[1]; + const { page, results } = params.queryKey[1]; const startIndex = (page - 1) * results; const stopIndex = startIndex + results - 1; return fetchDatasets(apiUrl, { sort, filters }, additionalFilters, { @@ -146,15 +151,9 @@ export const useDatasetsInfinite = ( const location = useLocation(); const { filters, sort } = parseSearchToQuery(location.search); - return useInfiniteQuery< - Dataset[], - AxiosError, - Dataset[], - [string, { sort: SortType; filters: FiltersType }, AdditionalFilters?] - >( - ['dataset', { sort, filters }, additionalFilters], + return useInfiniteQuery( + ['dataset', { sort: JSON.stringify(sort), filters }, additionalFilters], // need to stringify sort as property order is important! (params) => { - const { sort, filters } = params.queryKey[1]; const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 }; return fetchDatasets( apiUrl, diff --git a/packages/datagateway-common/src/api/facilityCycles.test.tsx b/packages/datagateway-common/src/api/facilityCycles.test.tsx index 1f8fcf116..7ee87672e 100644 --- a/packages/datagateway-common/src/api/facilityCycles.test.tsx +++ b/packages/datagateway-common/src/api/facilityCycles.test.tsx @@ -36,7 +36,7 @@ describe('facility cycle api functions', () => { ]; history = createMemoryHistory({ initialEntries: [ - '/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', + '/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', ], }); params = new URLSearchParams(); @@ -88,7 +88,7 @@ describe('facility cycle api functions', () => { data: mockData, }); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useFacilityCyclesPaginated(1), { wrapper: createReactQueryWrapper(history), @@ -98,6 +98,7 @@ describe('facility cycle api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -131,6 +132,16 @@ describe('facility cycle api functions', () => { params.toString() ); expect(result.current.data).toEqual(mockData); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2); }); it('sends axios request to fetch paginated facility cycles and calls handleICATError on failure', async () => { @@ -184,7 +195,7 @@ describe('facility cycle api functions', () => { : Promise.resolve({ data: mockData[1] }) ); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useFacilityCyclesInfinite(1), { wrapper: createReactQueryWrapper(history), @@ -194,6 +205,7 @@ describe('facility cycle api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -253,6 +265,16 @@ describe('facility cycle api functions', () => { mockData[0], mockData[1], ]); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3); }); it('sends axios request to fetch infinite facility cycles and calls handleICATError on failure', async () => { diff --git a/packages/datagateway-common/src/api/facilityCycles.tsx b/packages/datagateway-common/src/api/facilityCycles.tsx index 6187918c3..cb82a7afe 100644 --- a/packages/datagateway-common/src/api/facilityCycles.tsx +++ b/packages/datagateway-common/src/api/facilityCycles.tsx @@ -106,7 +106,7 @@ export const useFacilityCyclesPaginated = ( string, number, { - sort: SortType; + sort: string; filters: FiltersType; page: number; results: number; @@ -116,10 +116,15 @@ export const useFacilityCyclesPaginated = ( [ 'facilityCycle', instrumentId, - { sort, filters, page: page ?? 1, results: results ?? 10 }, + { + sort: JSON.stringify(sort), // need to stringify sort as property order is important! + filters, + page: page ?? 1, + results: results ?? 10, + }, ], (params) => { - const { sort, filters, page, results } = params.queryKey[2]; + const { page, results } = params.queryKey[2]; const startIndex = (page - 1) * results; const stopIndex = startIndex + results - 1; return fetchFacilityCycles( @@ -148,15 +153,9 @@ export const useFacilityCyclesInfinite = ( const location = useLocation(); const { filters, sort } = parseSearchToQuery(location.search); - return useInfiniteQuery< - FacilityCycle[], - AxiosError, - FacilityCycle[], - [string, number, { sort: SortType; filters: FiltersType }] - >( - ['facilityCycle', instrumentId, { sort, filters }], + return useInfiniteQuery( + ['facilityCycle', instrumentId, { sort: JSON.stringify(sort), filters }], (params) => { - const { sort, filters } = params.queryKey[2]; const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 }; return fetchFacilityCycles( apiUrl, diff --git a/packages/datagateway-common/src/api/instruments.test.tsx b/packages/datagateway-common/src/api/instruments.test.tsx index 214864251..1100b4065 100644 --- a/packages/datagateway-common/src/api/instruments.test.tsx +++ b/packages/datagateway-common/src/api/instruments.test.tsx @@ -30,7 +30,7 @@ describe('instrument api functions', () => { ]; history = createMemoryHistory({ initialEntries: [ - '/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', + '/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', ], }); params = new URLSearchParams(); @@ -47,13 +47,17 @@ describe('instrument api functions', () => { data: mockData, }); - const { result, waitFor } = renderHook(() => useInstrumentsPaginated(), { - wrapper: createReactQueryWrapper(history), - }); + const { result, waitFor, rerender } = renderHook( + () => useInstrumentsPaginated(), + { + wrapper: createReactQueryWrapper(history), + } + ); await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -74,6 +78,16 @@ describe('instrument api functions', () => { params.toString() ); expect(result.current.data).toEqual(mockData); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2); }); it('sends axios request to fetch paginated instruments and calls handleICATError on failure', async () => { @@ -121,13 +135,17 @@ describe('instrument api functions', () => { : Promise.resolve({ data: mockData[1] }) ); - const { result, waitFor } = renderHook(() => useInstrumentsInfinite(), { - wrapper: createReactQueryWrapper(history), - }); + const { result, waitFor, rerender } = renderHook( + () => useInstrumentsInfinite(), + { + wrapper: createReactQueryWrapper(history), + } + ); await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -174,6 +192,16 @@ describe('instrument api functions', () => { mockData[0], mockData[1], ]); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3); }); it('sends axios request to fetch infinite instruments and calls handleICATError on failure', async () => { diff --git a/packages/datagateway-common/src/api/instruments.tsx b/packages/datagateway-common/src/api/instruments.tsx index e2822d446..51d9c36a6 100644 --- a/packages/datagateway-common/src/api/instruments.tsx +++ b/packages/datagateway-common/src/api/instruments.tsx @@ -69,16 +69,24 @@ export const useInstrumentsPaginated = ( [ string, { - sort: SortType; + sort: string; filters: FiltersType; page: number; results: number; } ] >( - ['instrument', { sort, filters, page: page ?? 1, results: results ?? 10 }], + [ + 'instrument', + { + sort: JSON.stringify(sort), // need to stringify sort as property order is important! + filters, + page: page ?? 1, + results: results ?? 10, + }, + ], (params) => { - const { sort, filters, page, results } = params.queryKey[1]; + const { page, results } = params.queryKey[1]; const startIndex = (page - 1) * results; const stopIndex = startIndex + results - 1; return fetchInstruments(apiUrl, { sort, filters }, additionalFilters, { @@ -102,15 +110,9 @@ export const useInstrumentsInfinite = ( const location = useLocation(); const { filters, sort } = parseSearchToQuery(location.search); - return useInfiniteQuery< - Instrument[], - AxiosError, - Instrument[], - [string, { sort: SortType; filters: FiltersType }] - >( - ['instrument', { sort, filters }], + return useInfiniteQuery( + ['instrument', { sort: JSON.stringify(sort), filters }], // need to stringify sort as property order is important! (params) => { - const { sort, filters } = params.queryKey[1]; const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 }; return fetchInstruments( apiUrl, diff --git a/packages/datagateway-common/src/api/investigations.test.tsx b/packages/datagateway-common/src/api/investigations.test.tsx index 80cc2e2ae..8c6707b35 100644 --- a/packages/datagateway-common/src/api/investigations.test.tsx +++ b/packages/datagateway-common/src/api/investigations.test.tsx @@ -51,7 +51,7 @@ describe('investigation api functions', () => { ]; history = createMemoryHistory({ initialEntries: [ - '/?sort={"name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', + '/?sort={"name":"asc","title":"desc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20', ], }); params = new URLSearchParams(); @@ -132,7 +132,7 @@ describe('investigation api functions', () => { data: mockData, }); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useInvestigationsPaginated([ { @@ -150,6 +150,7 @@ describe('investigation api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -176,6 +177,16 @@ describe('investigation api functions', () => { params.toString() ); expect(result.current.data).toEqual(mockData); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}&page=2&results=20' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(2); }); it('sends axios request to fetch paginated investigations and returns successful response when ignoreIDSort is true', async () => { @@ -204,6 +215,7 @@ describe('investigation api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append( 'where', JSON.stringify({ @@ -269,7 +281,7 @@ describe('investigation api functions', () => { : Promise.resolve({ data: mockData[1] }) ); - const { result, waitFor } = renderHook( + const { result, waitFor, rerender } = renderHook( () => useInvestigationsInfinite([ { @@ -287,6 +299,7 @@ describe('investigation api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append('order', JSON.stringify('id asc')); params.append( 'where', @@ -339,6 +352,16 @@ describe('investigation api functions', () => { mockData[0], mockData[1], ]); + + // test that order of sort object triggers new query + history.push( + '/?sort={"title":"desc", "name":"asc"}&filters={"name":{"value":"test","type":"include"}}' + ); + rerender(); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(axios.get as jest.Mock).toHaveBeenCalledTimes(3); }); it('sends axios request to fetch infinite investigations and returns successful response when ignoreIDSort is true', async () => { @@ -369,6 +392,7 @@ describe('investigation api functions', () => { await waitFor(() => result.current.isSuccess); params.append('order', JSON.stringify('name asc')); + params.append('order', JSON.stringify('title desc')); params.append( 'where', JSON.stringify({ diff --git a/packages/datagateway-common/src/api/investigations.tsx b/packages/datagateway-common/src/api/investigations.tsx index 25f7a599c..3adbc7914 100644 --- a/packages/datagateway-common/src/api/investigations.tsx +++ b/packages/datagateway-common/src/api/investigations.tsx @@ -110,7 +110,7 @@ export const useInvestigationsPaginated = ( [ string, { - sort: SortType; + sort: string; filters: FiltersType; page: number; results: number; @@ -121,12 +121,17 @@ export const useInvestigationsPaginated = ( >( [ 'investigation', - { sort, filters, page: page ?? 1, results: results ?? 10 }, + { + sort: JSON.stringify(sort), // need to stringify sort as property order is important! + filters, + page: page ?? 1, + results: results ?? 10, + }, additionalFilters, ignoreIDSort, ], (params) => { - const { sort, filters, page, results } = params.queryKey[1]; + const { page, results } = params.queryKey[1]; const startIndex = (page - 1) * results; const stopIndex = startIndex + results - 1; return fetchInvestigations( @@ -157,20 +162,14 @@ export const useInvestigationsInfinite = ( const location = useLocation(); const { filters, sort } = parseSearchToQuery(location.search); - return useInfiniteQuery< - Investigation[], - AxiosError, - Investigation[], + return useInfiniteQuery( [ - string, - { sort: SortType; filters: FiltersType }, - AdditionalFilters?, - boolean? - ] - >( - ['investigation', { sort, filters }, additionalFilters, ignoreIDSort], + 'investigation', + { sort: JSON.stringify(sort), filters }, // need to stringify sort as property order is important! + additionalFilters, + ignoreIDSort, + ], (params) => { - const { sort, filters } = params.queryKey[1]; const offsetParams = params.pageParam ?? { startIndex: 0, stopIndex: 49 }; return fetchInvestigations( apiUrl, diff --git a/packages/datagateway-dataview/cypress.config.ts b/packages/datagateway-dataview/cypress.config.ts index d1d811276..4f087d831 100644 --- a/packages/datagateway-dataview/cypress.config.ts +++ b/packages/datagateway-dataview/cypress.config.ts @@ -29,4 +29,7 @@ export default defineConfig({ }, baseUrl: 'http://127.0.0.1:3000', }, + env: { + CI: process.env.CI ?? false, + }, }); diff --git a/packages/datagateway-dataview/cypress/e2e/breadcrumbs.cy.ts b/packages/datagateway-dataview/cypress/e2e/breadcrumbs.cy.ts index d0b271dff..bd88ba210 100644 --- a/packages/datagateway-dataview/cypress/e2e/breadcrumbs.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/breadcrumbs.cy.ts @@ -19,10 +19,8 @@ describe('Breadcrumbs Component', () => { it('should click on investigation and add breadcrumbs correctly', () => { // Click on the first investigation in the table. - cy.get('[role="gridcell"] a') - .first() - .click({ force: true }) - .wait('@getInvestigation'); + cy.get('[role="gridcell"] a').first().click({ force: true }); + cy.wait('@getInvestigation'); // Check to see if the breadcrumbs have been added correctly. // Get the first link on the page which is a link to @@ -77,7 +75,8 @@ describe('Breadcrumbs Component', () => { cy.visit('/browse/investigation/1/dataset').wait('@getInvestigation'); // Click on the first link with Dataset 1. - cy.contains('DATASET 1').click({ force: true }).wait('@getDataset'); + cy.contains('DATASET 1').click({ force: true }); + cy.wait('@getDataset'); // Check to ensure the location is the datafile. cy.location('pathname').should( @@ -122,7 +121,8 @@ describe('Breadcrumbs Component', () => { cy.visit('/browse/investigation/1/dataset').wait('@getInvestigation'); // Click on the first link with Dataset 1. - cy.contains('DATASET 1').click({ force: true }).wait('@getDataset'); + cy.contains('DATASET 1').click({ force: true }); + cy.wait('@getDataset'); // Check to ensure the location is the datafile. cy.location('pathname').should( @@ -131,20 +131,15 @@ describe('Breadcrumbs Component', () => { ); // The hover tool tip has an enter delay of 100ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.contains('span', 'DATASET 1') - .trigger('mouseover', { force: true }) - .wait(300) - .get('[role="tooltip"]') - .should('not.exist'); + cy.contains('span', 'DATASET 1').trigger('mouseover', { force: true }); + + cy.get('[role="tooltip"]').should('not.exist'); // The hover tool tip has an enter delay of 100ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.contains('span', 'Analysis reflect') - .trigger('mouseover', { force: true }) - .wait(300) - .get('[role="tooltip"]') - .contains('Analysis reflect'); + cy.contains('span', 'Analysis reflect').trigger('mouseover', { + force: true, + }); + cy.get('[role="tooltip"]').contains('Analysis reflect'); }); it('breadcrumbs should be sticky', () => { @@ -156,9 +151,10 @@ describe('Breadcrumbs Component', () => { 'Investigations' ); - cy.get('[data-testid="card"]').eq(5).scrollIntoView().should('be.visible'); + cy.get('[data-testid="card"]').eq(5).scrollIntoView(); + cy.get('[data-testid="card"]').eq(5).should('be.visible'); // Check the breadcrumbs are still visible - cy.get('[data-testid="Breadcrumb-base"]').isScrolledTo(); + cy.get('[data-testid="Breadcrumb-base"]').should('be.visible'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/datasets.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/datasets.cy.ts index 13bd12d23..c67b35719 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/datasets.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/datasets.cy.ts @@ -3,15 +3,10 @@ describe('Datasets Cards', () => { cy.intercept('**/datasets/count*').as('getDatasetsCount'); cy.intercept('**/datasets?order*').as('getDatasetsOrder'); cy.login(); - cy.visit('/browse/investigation/1/dataset').wait( - ['@getDatasetsCount', '@getDatasetsOrder', '@getDatasetsOrder'], + cy.visit('/browse/investigation/1/dataset?view=card').wait( + ['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 } ); - cy.get('[aria-label="page view Display as cards"]') - .click() - .wait(['@getDatasetsOrder'], { - timeout: 10000, - }); }); it('should load correctly', () => { @@ -30,67 +25,70 @@ describe('Datasets Cards', () => { ); }); - it('should be able to sort by one field', () => { - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { + it('should be able to sort by one field or multiple', () => { + // ascending + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@getDatasetsOrder', { timeout: 10000, }); cy.contains('[role="button"]', 'asc').should('exist'); cy.contains('[role="button"]', 'desc').should('not.exist'); cy.get('[data-testid="card"]').first().contains('DATASET 1'); - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { + // descending + cy.get('@nameSortButton').click(); + cy.wait('@getDatasetsOrder', { timeout: 10000, }); cy.contains('[role="button"]', 'asc').should('not.exist'); cy.contains('[role="button"]', 'desc').should('exist'); cy.get('[data-testid="card"]').first().contains('DATASET 61'); - cy.contains('[role="button"]', 'Name').click(); + // no order + cy.get('@nameSortButton').click(); cy.contains('[role="button"]', 'asc').should('not.exist'); cy.contains('[role="button"]', 'desc').should('not.exist'); cy.get('[data-testid="card"]').first().contains('DATASET 1'); - }); - it('should be able to sort by multiple fields', () => { - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 1'); + // multiple fields + cy.contains('[role="button"]', 'Create Time').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, + }); - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { + cy.get('@nameSortButton').click(); + cy.wait('@getDatasetsOrder', { timeout: 10000, }); - cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by NAME"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by CREATE TIME"]', 'asc').should('exist'); cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 1'); }); it('should be able to filter by multiple fields', () => { cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Name"]') - .first() - .type('61') - .wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); + cy.get('[aria-label="Filter by Name"]').first().type('61'); + cy.wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); + cy.get('[data-testid="card"]').first().contains('DATASET 61'); + + cy.get('input[id="Create Time filter from"]').type('2019-01-01'); + cy.wait(['@getDatasetsCount'], { timeout: 10000 }); cy.get('[data-testid="card"]').first().contains('DATASET 61'); - cy.get('input[id="Create Time filter from"]') - .click() - .type('2019-01-01') - .wait(['@getDatasetsCount'], { timeout: 10000 }); cy.get('input[aria-label="Create Time filter to"]') .parent() .find('button') .click(); - cy.get('.MuiPickersDay-root[type="button"]') - .first() - .click() - .wait(['@getDatasetsCount'], { timeout: 10000 }); + cy.get('.MuiPickersCalendarHeader-label').click(); + cy.contains('2020').click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.wait(['@getDatasetsCount'], { timeout: 10000 }); + const date = new Date(); date.setDate(1); + date.setFullYear(2020); cy.get('input[id="Create Time filter to"]').should( 'have.value', date.toISOString().slice(0, 10) diff --git a/packages/datagateway-dataview/cypress/e2e/card/dls/datasets.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/dls/datasets.cy.ts index 83d3a8701..38f99e7ab 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/dls/datasets.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/dls/datasets.cy.ts @@ -3,17 +3,11 @@ describe('DLS - Datasets Cards', () => { cy.intercept('**/datasets/count*').as('getDatasetsCount'); cy.intercept('**/datasets?order*').as('getDatasetsOrder'); cy.login(); - cy.visit('/browse/proposal/INVESTIGATION%201/investigation/1/dataset').wait( - ['@getDatasetsCount', '@getDatasetsOrder', '@getDatasetsOrder'], - { - timeout: 10000, - } - ); - cy.get('[aria-label="page view Display as cards"]') - .click() - .wait(['@getDatasetsOrder'], { - timeout: 10000, - }); + cy.visit( + '/browse/proposal/INVESTIGATION%201/investigation/1/dataset?view=card' + ).wait(['@getDatasetsCount', '@getDatasetsOrder'], { + timeout: 10000, + }); }); it('should load correctly', () => { @@ -25,7 +19,7 @@ describe('DLS - Datasets Cards', () => { cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); }); - it('should be able to click an investigation to see its datasets', () => { + it('should be able to click a dataset to see its datafiles', () => { cy.get('[data-testid="card"]') .first() .contains('DATASET 61') @@ -58,111 +52,81 @@ describe('DLS - Datasets Cards', () => { .contains('DATASETTYPE 3'); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { timeout: 10000 }); - }); + it('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Create Time').as('timeSortButton').click(); + cy.wait('@getDatasetsOrder', { timeout: 10000 }); - it('one field', () => { - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 1'); - - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 61'); - - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 1'); + // ascending + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); - - it('multiple fields', () => { - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 1'); - - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 1'); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 1'); + + // descending + cy.get('@nameSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); - }); - - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 61'); + + // no order + cy.get('@nameSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 1'); + + // multiple fields + cy.get('@timeSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Name"]') - .first() - .type('61') - .wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); - cy.get('[data-testid="card"]').first().contains('DATASET 61'); - - cy.get('input[id="Create Time filter from"]') - .click() - .type('2019-01-01') - .wait(['@getDatasetsCount'], { timeout: 10000 }); - cy.get('input[aria-label="Create Time filter to"]') - .parent() - .find('button') - .click(); - cy.get('.MuiPickersDay-root[type="button"]') - .first() - .click() - .wait(['@getDatasetsCount'], { timeout: 10000 }); - const date = new Date(); - date.setDate(1); - cy.get('input[id="Create Time filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); - cy.get('[data-testid="card"]').should('not.exist'); + cy.get('@nameSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); - }); + cy.contains('[aria-label="Sort by NAME"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by CREATE TIME"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); - it('should display correct datafile count after filtering', () => { - cy.visit('/browse/proposal/INVESTIGATION%202/investigation/2/dataset').wait( - ['@getDatasetsCount', '@getDatasetsOrder'], - { - timeout: 10000, - } - ); - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { timeout: 10000 }); + cy.get('[data-testid="card"]').first().contains('DATASET 1'); + }); + it('should be able to filter by multiple fields', () => { cy.get('[data-testid="advanced-filters-link"]').click(); - - cy.get('[aria-label="Filter by Name"]') - .first() - .type('DATASET 62') - .wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); - - cy.get('[data-testid="card"]').first().contains('62'); + cy.get('[aria-label="Filter by Name"]').first().type('61'); + cy.wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); + + cy.get('[data-testid="card"]').first().contains('DATASET 61'); + // check that count is correct after filtering + cy.get('[data-testid="card"]').first().contains('15'); + + cy.get('input[id="Create Time filter from"]').type('2019-01-01'); + cy.wait(['@getDatasetsCount'], { timeout: 10000 }); + cy.get('[data-testid="card"]').first().contains('DATASET 61'); + + cy.get('input[aria-label="Create Time filter to"]') + .parent() + .find('button') + .click(); + cy.get('.MuiPickersCalendarHeader-label').click(); + cy.contains('2020').click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.wait(['@getDatasetsCount'], { timeout: 10000 }); + + const date = new Date(); + date.setDate(1); + date.setFullYear(2020); + cy.get('input[id="Create Time filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); + cy.get('[data-testid="card"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/dls/proposals.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/dls/proposals.cy.ts index 9d75c236c..b8d66a00d 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/dls/proposals.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/dls/proposals.cy.ts @@ -3,15 +3,10 @@ describe('DLS - Proposals Cards', () => { cy.intercept('**/investigations/count*').as('getInvestigationsCount'); cy.intercept('**/investigations?order*').as('getInvestigationsOrder'); cy.login(); - cy.visit('/browse/proposal/').wait( + cy.visit('/browse/proposal?view=card').wait( ['@getInvestigationsCount', '@getInvestigationsOrder'], { timeout: 10000 } ); - cy.get('[aria-label="page view Display as cards"]') - .click() - .wait(['@getInvestigationsOrder'], { - timeout: 10000, - }); }); it('should load correctly', () => { @@ -19,7 +14,7 @@ describe('DLS - Proposals Cards', () => { cy.get('#datagateway-dataview').should('be.visible'); }); - it('should be able to click an investigation to see its datasets', () => { + it('should be able to click a proposal to see its visits', () => { cy.get('[data-testid="card"]') .first() .contains('A air avoid beautiful.') @@ -30,48 +25,23 @@ describe('DLS - Proposals Cards', () => { ); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="dls-proposal-card-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + it('should be able to filter by multiple fields', () => { + cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('body').type('{esc}'); + cy.get('[aria-label="Filter by Name"]').first().type('2'); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, + }); + cy.get('[data-testid="card"]').first().contains('INVESTIGATION 21'); + cy.contains('[aria-label="view-count"]', '15').should('be.visible'); - // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.get('[aria-label="Filter by Title"]').first().type('Dog'); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, + }); cy.get('[data-testid="card"]') - .get('[data-testid="dls-proposal-card-title"]') - .wait(700) .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - - describe('should be able to filter by', () => { - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Title"]') - .first() - .type('Dog') - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]') - .first() - .contains('Majority about dog idea bag summer.'); - - cy.get('[aria-label="Filter by Name"]') - .first() - .type('2') - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]').first().contains('INVESTIGATION 52'); - }); + .contains('Majority about dog idea bag summer.'); + cy.get('[data-testid="card"]').should('have.length', 1); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/dls/visits.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/dls/visits.cy.ts index 0e9923f8e..64f2e68f9 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/dls/visits.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/dls/visits.cy.ts @@ -3,15 +3,10 @@ describe('DLS - Visits Cards', () => { cy.intercept('**/investigations/count*').as('getInvestigationsCount'); cy.intercept('**/investigations?order*').as('getInvestigationsOrder'); cy.login(); - cy.visit('/browse/proposal/INVESTIGATION%201/investigation/').wait( + cy.visit('/browse/proposal/INVESTIGATION%201/investigation?view=card').wait( ['@getInvestigationsCount', '@getInvestigationsOrder'], { timeout: 10000 } ); - cy.get('[aria-label="page view Display as cards"]') - .click() - .wait(['@getInvestigationsOrder'], { - timeout: 10000, - }); }); it('should load correctly', () => { @@ -65,89 +60,65 @@ describe('DLS - Visits Cards', () => { .contains('Simple notice since view check over through there.'); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - }); + // only 1 visit, so no point in testing sorting + it.skip('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').as('dateSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); - it('one field', () => { - cy.contains('[role="button"]', 'Visit ID') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('70'); + // ascending + cy.contains('[role="button"]', 'Visit ID').as('visitIdSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('70'); - cy.contains('[role="button"]', 'Visit ID') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]').first().contains('70'); + // descending + cy.get('@visitIdSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]').first().contains('70'); - cy.contains('[role="button"]', 'Visit ID').click(); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('70'); - }); + // no order + cy.get('@visitIdSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('70'); - it('multiple fields', () => { - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('70'); + // multiple fields + cy.get('@dateSortButton').click(); + cy.get('@visitIdSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Visit ID') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').contains('70'); - }); + cy.contains('[aria-label="Sort by VISIT ID"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by START DATE"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('70'); }); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); + it('should be able to filter by multiple fields', () => { + cy.get('[data-testid="advanced-filters-link"]').click(); + cy.get('[aria-label="Filter by Visit ID"]').first().type('7'); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, }); + cy.get('[data-testid="card"]').first().contains('70'); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Visit ID"]') - .first() - .type('7') - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]').first().contains('70'); - - cy.get('input[id="Start Date filter from"]') - .click() - .type('2000-05-01') - .wait(['@getInvestigationsCount'], { timeout: 10000 }); - cy.get('input[aria-label="Start Date filter to"]') - .parent() - .find('button') - .click(); - cy.get('.MuiPickersDay-root[type="button"]') - .first() - .click() - .wait(['@getInvestigationsCount'], { timeout: 10000 }); - const date = new Date(); - date.setDate(1); - cy.get('input[id="Start Date filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); - cy.get('[data-testid="card"]').should('not.exist'); - }); + cy.get('input[id="Start Date filter from"]').type('2000-05-01'); + cy.wait(['@getInvestigationsCount'], { timeout: 10000 }); + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.wait(['@getInvestigationsCount'], { timeout: 10000 }); + const date = new Date(); + date.setDate(1); + cy.get('input[id="Start Date filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); + cy.get('[data-testid="card"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/investigations.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/investigations.cy.ts index 014c20369..59aa31f72 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/investigations.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/investigations.cy.ts @@ -3,27 +3,16 @@ describe('Investigations Cards', () => { cy.intercept('**/investigations/count*').as('getInvestigationsCount'); cy.intercept('**/investigations?order*').as('getInvestigationsOrder'); cy.login(); - cy.visit('/browse/investigation').wait( + cy.visit('/browse/investigation?view=card').wait( ['@getInvestigationsCount', '@getInvestigationsOrder'], { timeout: 15000 } ); - cy.get('[aria-label="page view Display as cards"]').click(); }); it('should load correctly', () => { cy.title().should('equal', 'DataGateway DataView'); cy.get('#datagateway-dataview').should('be.visible'); - }); - - it('should be able to click an investigation to see its datasets', () => { - cy.get('[data-testid="card"]') - .first() - .contains('Analysis reflect work or hour color maybe.') - .click({ force: true }); - cy.location('pathname').should('eq', '/browse/investigation/1/dataset'); - }); - it('should have the correct url for the DOI link', () => { cy.get('[data-testid="card"]') .first() .get('[data-testid="investigation-card-doi-link"]') @@ -41,69 +30,46 @@ describe('Investigations Cards', () => { }); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="investigation-card-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting + it('should be able to click an investigation to see its datasets', () => { cy.get('[data-testid="card"]') - .get('[data-testid="investigation-card-title"]') - .wait(700) .first() - .get('[role="tooltip"]') - .should('not.exist'); + .contains('Analysis reflect work or hour color maybe.') + .click({ force: true }); + cy.location('pathname').should('eq', '/browse/investigation/1/dataset'); }); - it('should be able to sort by one field', () => { - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); + it('should be able to sort by one field or multiple', () => { + // ascending + cy.contains('[role="button"]', 'Title').as('titleSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); cy.contains('[role="button"]', 'asc').should('exist'); cy.contains('[role="button"]', 'desc').should('not.exist'); cy.get('[data-testid="card"]').first().contains('A air avoid beautiful.'); - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); + // descending + cy.get('@titleSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); cy.contains('[role="button"]', 'asc').should('not.exist'); cy.contains('[role="button"]', 'desc').should('exist'); cy.get('[data-testid="card"]') .first() .contains('Why news west bar sing tax.'); - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); + // no order + cy.get('@titleSortButton').click(); cy.contains('[role="button"]', 'asc').should('not.exist'); cy.contains('[role="button"]', 'desc').should('not.exist'); cy.get('[data-testid="card"]') .first() .contains('Analysis reflect work or hour color maybe.'); - }); - it('should be able to sort by multiple fields', () => { - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]') - .first() - .contains('Analysis reflect work or hour color maybe.'); + // multiple fields + cy.contains('[role="button"]', 'Start Date').click(); + cy.get('@titleSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by TITLE"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by START DATE"]', 'asc').should('exist'); cy.contains('[role="button"]', 'desc').should('not.exist'); cy.get('[data-testid="card"]') .first() @@ -115,10 +81,10 @@ describe('Investigations Cards', () => { cy.contains('[role="button"]', 'Type ID') .parent() .contains('[role="button"]', '1') - .click() - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 30000, - }); + .click(); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 30000, + }); cy.contains('[role="button"]', 'Type ID - 1').should('exist'); cy.get('[data-testid="card"]') .first() @@ -126,12 +92,10 @@ describe('Investigations Cards', () => { cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Title"]') - .first() - .type('off', { delay: 20 }) - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); + cy.get('[aria-label="Filter by Title"]').first().type('off', { delay: 20 }); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, + }); cy.get('[data-testid="advanced-filters-link"]').click(); @@ -141,25 +105,21 @@ describe('Investigations Cards', () => { cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('input[id="Start Date filter from"]') - .click() - .type('2014-01-01') - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); + cy.get('input[aria-label="Start Date filter from"]').type('2014-01-01'); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, + }); cy.get('input[aria-label="Start Date filter to"]') .parent() .find('button') .click(); - cy.get('.MuiPickersDay-root[type="button"]') - .first() - .click() - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, + }); const date = new Date(); date.setDate(1); - cy.get('input[id="Start Date filter to"]').should( + cy.get('input[aria-label="Start Date filter to"]').should( 'have.value', date.toISOString().slice(0, 10) ); diff --git a/packages/datagateway-dataview/cypress/e2e/card/isis/dataPublications.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/isis/dataPublications.cy.ts index 3be657163..e38c1b435 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/isis/dataPublications.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/isis/dataPublications.cy.ts @@ -3,56 +3,17 @@ describe('ISIS - Data Publication Cards', () => { cy.intercept('**/datapublications/count*').as('getDataPublicationsCount'); cy.intercept('**/datapublications?order*').as('getDataPublicationsOrder'); cy.login(); - cy.visit('/browseDataPublications/instrument/8/dataPublication').wait( - ['@getDataPublicationsCount', '@getDataPublicationsOrder'], - { timeout: 10000 } - ); - cy.get('[aria-label="page view Display as cards"]').click(); + cy.visit( + '/browseDataPublications/instrument/8/dataPublication?view=card' + ).wait(['@getDataPublicationsCount', '@getDataPublicationsOrder'], { + timeout: 10000, + }); }); it('should load correctly', () => { cy.title().should('equal', 'DataGateway DataView'); cy.get('#datagateway-dataview').should('be.visible'); - //Default sort - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); - }); - - it('should be able to click a datapublication to see its landing page', () => { - cy.get('[data-testid="card"]') - .first() - .contains('Church') - .click({ force: true }); - cy.location('pathname').should( - 'eq', - '/browseDataPublications/instrument/8/dataPublication/51' - ); - }); - - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="landing-datapublication-card-pid-link"]') - .first() - .trigger('mouseover') - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="landing-datapublication-card-pid-link"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - - it('should have the correct url for the PID link', () => { cy.get('[data-testid="card"]') .first() .get('[data-testid="landing-datapublication-card-pid-link"]') @@ -68,72 +29,75 @@ describe('ISIS - Data Publication Cards', () => { .first() .should('have.attr', 'href', url); }); - }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Publication Date') - .click() - .wait('@getDataPublicationsOrder', { timeout: 10000 }); - }); - - it('one field', () => { - cy.contains('[role="button"]', 'Publication Date') - .click() - .wait('@getDataPublicationsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('Article'); - - cy.contains('[role="button"]', 'Publication Date') - .click() - .wait('@getDataPublicationsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]').first().contains('Church'); + //Default sort + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); + }); - cy.contains('[role="button"]', 'Publication Date') - .click() - .wait('@getDataPublicationsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('Article'); - }); + it('should be able to click a datapublication to see its landing page', () => { + cy.get('[data-testid="card"]') + .first() + .contains('Church') + .click({ force: true }); + cy.location('pathname').should( + 'eq', + '/browseDataPublications/instrument/8/dataPublication/51' + ); }); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Publication Date') - .click() - .wait('@getDataPublicationsOrder', { timeout: 10000 }); - }); + it('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Publication Date') + .as('dateSortButton') + .click(); + cy.wait('@getDataPublicationsOrder', { timeout: 10000 }); + + // ascending + cy.get('@dateSortButton').click(); + cy.wait('@getDataPublicationsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('Article'); + + // descending + cy.get('@dateSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]').first().contains('Church'); + + // no order + cy.get('@dateSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('Article'); + + // multiple fields + cy.contains('[role="button"]', 'Title').click(); + cy.get('@dateSortButton').click(); + cy.wait('@getDataPublicationsOrder', { timeout: 10000 }); + + cy.contains('[aria-label="Sort by TITLE"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by PUBLICATION DATE"]', 'asc').should( + 'exist' + ); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('Article'); + }); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); + it('should be able to filter by multiple fields', () => { + cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by DOI"]') - .first() - .type('0') - .wait(['@getDataPublicationsCount', '@getDataPublicationsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]').first().contains('Article'); + cy.get('[aria-label="Filter by DOI"]').first().type('0'); + cy.wait(['@getDataPublicationsCount', '@getDataPublicationsOrder'], { + timeout: 10000, + }); + cy.get('[data-testid="card"]').first().contains('Consider'); - cy.get('[aria-label="Filter by Title"]') - .first() - .type('wat') - .wait(['@getDataPublicationsCount', '@getDataPublicationsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]').first().contains('Consider'); + cy.get('[aria-label="Filter by Title"]').first().type('sub'); + cy.wait(['@getDataPublicationsCount', '@getDataPublicationsOrder'], { + timeout: 10000, }); + cy.get('[data-testid="card"]').first().contains('Article'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/isis/datasets.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/isis/datasets.cy.ts index b28d75bb9..e3c0dc560 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/isis/datasets.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/isis/datasets.cy.ts @@ -4,15 +4,10 @@ describe('ISIS - Datasets Cards', () => { cy.intercept('**/datasets?order*').as('getDatasetsOrder'); cy.login(); cy.visit( - '/browse/instrument/1/facilityCycle/19/investigation/19/dataset' - ).wait(['@getDatasetsCount', '@getDatasetsOrder', '@getDatasetsOrder'], { + '/browse/instrument/1/facilityCycle/19/investigation/19/dataset?view=card' + ).wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000, }); - cy.get('[aria-label="page view Display as cards"]') - .click() - .wait(['@getDatasetsOrder'], { - timeout: 10000, - }); }); it('should load correctly', () => { @@ -24,7 +19,7 @@ describe('ISIS - Datasets Cards', () => { cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); }); - it('should be able to click an investigation to see its datasets', () => { + it('should be able to click a dataset to see its datafiles', () => { cy.get('[data-testid="card"]') .first() .contains('DATASET 79') @@ -37,9 +32,8 @@ describe('ISIS - Datasets Cards', () => { it('should be able to expand "More Information"', () => { //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'Create Time').click(); + cy.wait('@getDatasetsOrder', { timeout: 10000 }); cy.get('[data-testid="card"]') .first() @@ -61,91 +55,81 @@ describe('ISIS - Datasets Cards', () => { ); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { timeout: 10000 }); - }); + it('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Create Time').as('timeSortButton').click(); + cy.wait('@getDatasetsOrder', { timeout: 10000 }); - it('one field', () => { - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 19'); - - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 79'); - - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 19'); + // ascending + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 19'); - it('multiple fields', () => { - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 19'); - - cy.contains('[role="button"]', 'Name').click().wait('@getDatasetsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('DATASET 19'); + // descending + cy.get('@nameSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); - }); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 79'); + + // no order + cy.get('@nameSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('DATASET 19'); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@getDatasetsOrder', { timeout: 10000 }); + // multiple fields + cy.get('@timeSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Name"]') - .first() - .type('19') - .wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); - cy.get('[data-testid="card"]').first().contains('DATASET 19'); - // check that size is correct after filtering - cy.get('[data-testid="card"]').first().contains('1.47 GB'); - - cy.get('input[id="Create Time filter from"]') - .click() - .type('2019-01-01') - .wait(['@getDatasetsCount'], { timeout: 10000 }); - cy.get('input[aria-label="Create Time filter to"]') - .parent() - .find('button') - .click(); - cy.get('.MuiPickersDay-root[type="button"]') - .first() - .click() - .wait(['@getDatasetsCount'], { timeout: 10000 }); - const date = new Date(); - date.setDate(1); - cy.get('input[id="Create Time filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); - cy.get('[data-testid="card"]').should('not.exist'); + cy.get('@nameSortButton').click(); + cy.wait('@getDatasetsOrder', { + timeout: 10000, }); + cy.contains('[aria-label="Sort by NAME"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by CREATE TIME"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + + cy.get('[data-testid="card"]').first().contains('DATASET 19'); + }); + + it('should be able to filter by multiple fields', () => { + cy.get('[data-testid="advanced-filters-link"]').click(); + cy.get('[aria-label="Filter by Name"]').first().type('19'); + cy.wait(['@getDatasetsCount', '@getDatasetsOrder'], { timeout: 10000 }); + + cy.get('[data-testid="card"]').first().contains('DATASET 19'); + // check that size is correct after filtering + cy.get('[data-testid="card"]').first().contains('1.47 GB'); + + cy.get('input[id="Create Time filter from"]').type('2019-01-01'); + cy.wait(['@getDatasetsCount'], { timeout: 10000 }); + cy.get('[data-testid="card"]').first().contains('DATASET 19'); + + cy.get('input[aria-label="Create Time filter to"]') + .parent() + .find('button') + .click(); + cy.get('.MuiPickersCalendarHeader-label').click(); + cy.contains('2020').click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.wait(['@getDatasetsCount'], { timeout: 10000 }); + + const date = new Date(); + date.setDate(1); + date.setFullYear(2020); + cy.get('input[id="Create Time filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); + cy.get('[data-testid="card"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/isis/facilityCycles.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/isis/facilityCycles.cy.ts index 8f7003101..88695d603 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/isis/facilityCycles.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/isis/facilityCycles.cy.ts @@ -18,7 +18,7 @@ describe('ISIS - FacilityCycles Cards', () => { cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); }); - it('should be able to click an investigation to see its datasets', () => { + it('should be able to click a facility cycle to see its investigations', () => { cy.get('[data-testid="card"]') .first() .contains('2004 cycle 3') @@ -29,87 +29,67 @@ describe('ISIS - FacilityCycles Cards', () => { ); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getFacilityCyclesOrder', { timeout: 10000 }); - }); - // Note that Name and Description currently fail to sort - it('one field', () => { - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getFacilityCyclesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); + it('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').as('dateSortButton').click(); + cy.wait('@getFacilityCyclesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Start Date').click(); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]').first().contains('2004 cycle 3'); + // ascending + cy.get('@dateSortButton').click(); + cy.wait('@getFacilityCyclesOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); - cy.contains('[role="button"]', 'Start Date').click(); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); - }); + // descending + cy.get('@dateSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]').first().contains('2004 cycle 3'); - it('multiple fields', () => { - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getFacilityCyclesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); + // no order + cy.get('@dateSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); - cy.contains('[role="button"]', 'End Date') - .click() - .wait('@getFacilityCyclesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); - }); - }); + // multiple fields + cy.get('@dateSortButton').click(); + cy.contains('[role="button"]', 'End Date').click(); + cy.wait('@getFacilityCyclesOrder', { timeout: 10000 }); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getFacilityCyclesOrder', { timeout: 10000 }); - }); + cy.contains('[aria-label="Sort by START DATE"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by END DATE"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('2001 cycle 2'); + }); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Name"]') - .first() - .type('3') - .wait(['@getFacilityCyclesCount', '@getFacilityCyclesOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]').first().contains('2002 cycle 3'); + it('should be able to filter by multiple fields', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').as('dateSortButton').click(); + cy.wait('@getFacilityCyclesOrder', { timeout: 10000 }); - cy.get('input[id="Start Date filter from"]') - .click() - .type('2004-06-01') - .wait(['@getFacilityCyclesCount'], { timeout: 10000 }); - cy.get('input[aria-label="Start Date filter to"]') - .parent() - .find('button') - .click(); - cy.get('.MuiPickersDay-root[type="button"]') - .first() - .click() - .wait(['@getFacilityCyclesCount'], { timeout: 10000 }); - const date = new Date(); - date.setDate(1); - cy.get('input[id="Start Date filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); - cy.get('[data-testid="card"]').first().contains('2004 cycle 3'); + cy.get('[data-testid="advanced-filters-link"]').click(); + cy.get('[aria-label="Filter by Name"]').first().type('3'); + cy.wait(['@getFacilityCyclesCount', '@getFacilityCyclesOrder'], { + timeout: 10000, }); + cy.get('[data-testid="card"]').first().contains('2002 cycle 3'); + + cy.get('input[id="Start Date filter from"]').type('2004-06-01'); + cy.wait(['@getFacilityCyclesCount'], { timeout: 10000 }); + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.wait(['@getFacilityCyclesCount'], { timeout: 10000 }); + const date = new Date(); + date.setDate(1); + cy.get('input[id="Start Date filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); + cy.get('[data-testid="card"]').first().contains('2004 cycle 3'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/isis/instruments.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/isis/instruments.cy.ts index 1a4214876..2937c76f0 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/isis/instruments.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/isis/instruments.cy.ts @@ -19,7 +19,7 @@ describe('ISIS - Instruments Cards', () => { cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); }); - it('should be able to click an investigation to see its datasets', () => { + it('should be able to click an instrument to see its facility cycles', () => { cy.get('[data-testid="card"]') .first() .contains('Eight imagine picture tough.') @@ -27,28 +27,6 @@ describe('ISIS - Instruments Cards', () => { cy.location('pathname').should('eq', '/browse/instrument/11/facilityCycle'); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="isis-instrument-card-name"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="isis-instrument-card-name"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - it('should be able to expand "More Information"', () => { cy.get('[data-testid="card"]') .first() @@ -65,92 +43,73 @@ describe('ISIS - Instruments Cards', () => { .contains('Kim Ramirez'); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Name') - .click() - .click() - .wait('@getInstrumentsOrder', { timeout: 10000 }); - }); + it('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.get('@nameSortButton').click(); + cy.wait('@getInstrumentsOrder', { timeout: 10000 }); - it('one field', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@getInstrumentsOrder', { - timeout: 10000, - }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]') - .first() - .contains('Eight imagine picture tough.'); + // ascending + cy.get('@nameSortButton').click(); + cy.wait('@getInstrumentsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@getInstrumentsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]') - .first() - .contains('Whether number computer economy design now serious appear.'); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]') + .first() + .contains('Eight imagine picture tough.'); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@getInstrumentsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]') - .first() - .contains('Stop prove field onto think suffer measure.'); - }); + // descending + cy.get('@nameSortButton').click(); + cy.wait('@getInstrumentsOrder', { timeout: 10000 }); - it('multiple fields', () => { - cy.contains('[role="button"]', 'Description') - .click() - .wait('@getInstrumentsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]') - .first() - .contains('Sound low certain challenge yet sport happy.'); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]') + .first() + .contains('Whether number computer economy design now serious appear.'); - cy.contains('[role="button"]', 'Type') - .click() - .wait('@getInstrumentsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('10'); - }); + // no order + cy.get('@nameSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]') + .first() + .contains('Stop prove field onto think suffer measure.'); + + cy.contains('[role="button"]', 'Description').click(); + cy.wait('@getInstrumentsOrder', { timeout: 10000 }); + cy.get('[data-testid="card"]') + .first() + .contains('Sound low certain challenge yet sport happy.'); + + cy.contains('[role="button"]', 'Type').click(); + cy.wait('@getInstrumentsOrder', { timeout: 10000 }); + cy.contains('[aria-label="Sort by DESCRIPTION"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by TYPE"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('10'); }); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Name') - .click() - .click() - .wait('@getInstrumentsOrder', { timeout: 10000 }); + it('should be able to filter by multiple fields', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.get('@nameSortButton').click(); + cy.wait('@getInstrumentsOrder', { timeout: 10000 }); + + cy.get('[data-testid="advanced-filters-link"]').click(); + cy.get('[aria-label="Filter by Name"]').first().type('oil'); + cy.wait(['@getInstrumentsCount', '@getInstrumentsOrder'], { + timeout: 10000, }); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Name"]') - .first() - .type('oil') - .wait(['@getInstrumentsCount', '@getInstrumentsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]') - .first() - .contains('Eight imagine picture tough.'); + cy.get('[data-testid="card"]') + .first() + .contains('Eight imagine picture tough.'); - cy.get('[aria-label="Filter by Type"]') - .first() - .type('11') - .wait(['@getInstrumentsCount', '@getInstrumentsOrder'], { - timeout: 10000, - }); - cy.get('[data-testid="card"]').first().contains('11'); + cy.get('[aria-label="Filter by Type"]').first().type('11'); + cy.wait(['@getInstrumentsCount', '@getInstrumentsOrder'], { + timeout: 10000, }); + cy.get('[data-testid="card"]').first().contains('11'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/isis/investigations.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/isis/investigations.cy.ts index f1b097201..408b68aa1 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/isis/investigations.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/isis/investigations.cy.ts @@ -3,56 +3,17 @@ describe('ISIS - Investigations Cards', () => { cy.intercept('**/investigations/count*').as('getInvestigationsCount'); cy.intercept('**/investigations?order*').as('getInvestigationsOrder'); cy.login(); - cy.visit('/browse/instrument/13/facilityCycle/12/investigation').wait( - ['@getInvestigationsCount', '@getInvestigationsOrder'], - { timeout: 10000 } - ); - cy.get('[aria-label="page view Display as cards"]').click(); + cy.visit( + '/browse/instrument/13/facilityCycle/12/investigation?view=card' + ).wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, + }); }); it('should load correctly', () => { cy.title().should('equal', 'DataGateway DataView'); cy.get('#datagateway-dataview').should('be.visible'); - //Default sort - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); - }); - - it('should be able to click an investigation to see its datasets', () => { - cy.get('[data-testid="card"]') - .first() - .contains('Stop system investment') - .click({ force: true }); - cy.location('pathname').should( - 'eq', - '/browse/instrument/13/facilityCycle/12/investigation/31' - ); - }); - - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="isis-investigations-card-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="card"]') - .get('[data-testid="isis-investigations-card-title"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - - it('should have the correct url for the DOI link', () => { cy.get('[data-testid="card"]') .first() .get('[data-testid="isis-investigations-card-doi-link"]') @@ -68,6 +29,21 @@ describe('ISIS - Investigations Cards', () => { .first() .should('have.attr', 'href', url); }); + + //Default sort + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); + }); + + it('should be able to click an investigation to see its datasets', () => { + cy.get('[data-testid="card"]') + .first() + .contains('Stop system investment') + .click({ force: true }); + cy.location('pathname').should( + 'eq', + '/browse/instrument/13/facilityCycle/12/investigation/31' + ); }); it('should be able to expand "More Information"', () => { @@ -145,84 +121,58 @@ describe('ISIS - Investigations Cards', () => { ); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - }); - - it('one field', () => { - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('exist'); - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('not.exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - }); - - it('multiple fields', () => { - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - - cy.contains('[role="button"]', 'Title') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'asc').should('exist'); - cy.contains('[role="button"]', 'desc').should('not.exist'); - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - }); + it('should be able to sort by one field or multiple', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').as('dateSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); + + // ascending + cy.contains('[role="button"]', 'Title').as('titleSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('Stop system investment'); + + // descending + cy.get('@titleSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('exist'); + cy.get('[data-testid="card"]').first().contains('Stop system investment'); + + // no order + cy.get('@titleSortButton').click(); + cy.contains('[role="button"]', 'asc').should('not.exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('Stop system investment'); + + // multiple fields + cy.get('@dateSortButton').click(); + cy.get('@titleSortButton').click(); + cy.wait('@getInvestigationsOrder', { timeout: 10000 }); + + cy.contains('[aria-label="Sort by TITLE"]', 'asc').should('exist'); + cy.contains('[aria-label="Sort by START DATE"]', 'asc').should('exist'); + cy.contains('[role="button"]', 'desc').should('not.exist'); + cy.get('[data-testid="card"]').first().contains('Stop system investment'); }); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date') - .click() - .wait('@getInvestigationsOrder', { timeout: 10000 }); + it('should be able to filter by multiple fields', () => { + cy.get('[data-testid="advanced-filters-link"]').click(); + cy.get('[aria-label="Filter by Title"]').first().type('stop'); + cy.wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { + timeout: 10000, }); - it('multiple fields', () => { - cy.get('[data-testid="advanced-filters-link"]').click(); - cy.get('[aria-label="Filter by Title"]') - .first() - .type('stop') - .wait(['@getInvestigationsCount', '@getInvestigationsOrder'], { - timeout: 10000, - }); - - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - // check that size is correct after filtering - cy.get('[data-testid="card"]').first().contains('3.31 GB'); - - cy.get('input[id="Start Date filter from"]') - .click() - .type('2007-08-01') - .wait(['@getInvestigationsCount'], { timeout: 10000 }); - cy.get('[data-testid="card"]').first().contains('Stop system investment'); - cy.get('input[id="Start Date filter to"]') - .type('2007-08-02') - .wait(['@getInvestigationsCount'], { timeout: 10000 }); - cy.get('[data-testid="card"]').should('not.exist'); - }); + cy.get('[data-testid="card"]').first().contains('Stop system investment'); + // check that size is correct after filtering + cy.get('[data-testid="card"]').first().contains('3.31 GB'); + + cy.get('input[id="Start Date filter from"]').type('2007-08-01'); + cy.wait(['@getInvestigationsCount'], { timeout: 10000 }); + cy.get('[data-testid="card"]').first().contains('Stop system investment'); + cy.get('input[id="Start Date filter to"]').type('2007-08-02'); + cy.wait(['@getInvestigationsCount'], { timeout: 10000 }); + cy.get('[data-testid="card"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/card/pageContainer.cy.ts b/packages/datagateway-dataview/cypress/e2e/card/pageContainer.cy.ts index 1549d4f61..1e3c9934f 100644 --- a/packages/datagateway-dataview/cypress/e2e/card/pageContainer.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/card/pageContainer.cy.ts @@ -29,9 +29,7 @@ describe('PageContainer Component', () => { cy.get('[aria-label="Go to selections"]').should('exist'); cy.get('[aria-label="page view Display as table"]').should('exist'); - }); - it('should display correct entity count', () => { // Check that the entity count has displayed correctly. cy.get('[aria-label="view-count"]') .should('be.visible') @@ -212,29 +210,20 @@ describe('PageContainer Component', () => { it('should display tooltips correctly', () => { // The hover tool tip has an enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="card"]') .get('[data-testid="investigation-card-title"]') .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + .trigger('mouseover', { force: true }); + cy.get('[role="tooltip"]').should('exist'); }); it('should not display tooltips after making the window bigger', () => { cy.viewport(3500, 750); - // The hover tool tip has an enter delay of 500ms and also need to - // wait after the viewport change as it takes a moment to resize - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(200) - .get('[data-testid="card"]') + cy.get('[data-testid="card"]') .get('[data-testid="investigation-card-title"]') .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('not.exist'); + .trigger('mouseover', { force: true }); + cy.get('[role="tooltip"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/cartSelection.cy.ts b/packages/datagateway-dataview/cypress/e2e/cartSelection.cy.ts index 17b30fa3f..b5556f351 100644 --- a/packages/datagateway-dataview/cypress/e2e/cartSelection.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/cartSelection.cy.ts @@ -37,12 +37,8 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('1 item has been added to selection.'); }); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') @@ -55,6 +51,10 @@ describe('Add/remove from cart functionality', () => { '1 item has been removed from selection.' ); }); + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -85,13 +85,45 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('15 items have been added to selection.'); }); + + // and uncheck + + cy.get('[aria-label="grid"]').scrollTo('top', { + ensureScrollable: false, + }); + + cy.get('[aria-label="select all rows"]').uncheck(); + cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( + 'not.be.checked' + ); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + cy.get( + `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` + ).should('not.be.checked'); + + cy.get('[aria-label="grid"]').scrollTo('bottom', { + ensureScrollable: false, + }); + cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); + cy.get('[aria-label="select all rows"]').should('not.be.checked'); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + + cy.get('[aria-label="selection-alert-text"]') + .invoke('text') + .then((text) => { + expect(text.trim()).equal( + '15 items have been removed from selection.' + ); + }); }); it('by all items in a filtered table', () => { - cy.get('[aria-label="Filter by Location"]') - .first() - .type('s') - .wait(['@getDatafiles', '@getDatafiles', '@getDatafileCount']); + cy.get('[aria-label="Filter by Location"]').first().type('s'); + cy.wait(['@getDatafiles', '@getDatafiles', '@getDatafileCount']); cy.get('[aria-label="select all rows"]').check(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( @@ -116,7 +148,6 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 0"]').should('be.checked'); cy.get('[aria-label="select row 1"]').should('not.be.checked'); - //cy.get('[aria-label="grid"]').scrollTo(0, 350); cy.get('[aria-label="select row 9"]').should('not.be.checked'); cy.get('[aria-label="grid"]').scrollTo('bottom', { @@ -125,75 +156,17 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); + cy.get('[aria-label="select row 12"]').should('be.checked'); cy.get('[aria-label="select row 14"]').should('be.checked'); }); - it('and unselect all items', () => { - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - - cy.reload().wait([ - '@getDatafiles', - '@getDatafiles', - '@getDatafileCount', - '@getDataset', - '@getDataset', - '@getInvestigation', - ]); - - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - cy.get('[aria-label="select all rows"]').uncheck(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'not.be.checked' - ); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - cy.get( - `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` - ).should('not.be.checked'); - - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); - cy.get('[aria-label="select all rows"]').should('not.be.checked'); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - - cy.get('[aria-label="selection-alert-text"]') - .invoke('text') - .then((text) => { - expect(text.trim()).equal( - '15 items have been removed from selection.' - ); - }); - }); - it('by shift clicking', () => { cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); + cy.get('body').type('{shift}', { release: false }); + cy.get('[aria-label="select row 5"]').click(); cy.get('[aria-label="select row 5"]').should('be.checked'); cy.get('[aria-label="grid"]').scrollTo('top'); @@ -207,19 +180,9 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('5 items have been added to selection.'); }); - }); - - it('and unselect by shift clicking', () => { - cy.get('[aria-label="select row 0"]').click(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); - cy.get('[aria-label="select row 5"]').should('be.checked'); + // and uncheck - cy.get('[aria-label="grid"]').scrollTo('top'); cy.get('[aria-label="select row 2"]').click(); cy.get('[aria-label="select row 2"]').should('not.be.checked'); @@ -240,15 +203,6 @@ describe('Add/remove from cart functionality', () => { ); }); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); describe('in DLS table', () => { @@ -264,17 +218,18 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'true'); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -300,39 +255,23 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]', { timeout: 10000 }) .should('have.attr', 'data-indeterminate') .and('eq', 'false'); - }); - - it('by all items in a filtered table', () => { - cy.get('[aria-label="Filter by Location"]') - .first() - .type('s') - .wait(['@getDatafiles', '@getDatafiles', '@getDatafileCount']); - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - cy.get( - `[aria-label="select row ${Math.floor(Math.random() * 6)}"]` - ).should('be.checked'); + // and uncheck - cy.get('[aria-label="Filter by Location"]').first().clear(); + cy.get('[aria-label="grid"]').scrollTo('top', { + ensureScrollable: false, + }); + cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' ); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') - .and('eq', 'true'); - - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="select row 1"]').should('not.be.checked'); - - //cy.get('[aria-label="grid"]').scrollTo(0, 350); - //cy.get('[aria-label="select row 14"]').should('not.be.checked'); + .and('eq', 'false'); + cy.get( + `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` + ).should('not.be.checked'); cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, @@ -340,38 +279,39 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); - cy.get('[aria-label="select row 13"]').should('not.be.checked'); - cy.get('[aria-label="select row 14"]').should('be.checked'); + cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); + cy.get('[aria-label="select all rows"]').should('not.be.checked'); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); }); - it('and unselect all items', () => { - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); //.wait('@getDatafiles'); - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); + it('by all items in a filtered table', () => { + cy.get('[aria-label="Filter by Location"]').first().type('s'); + cy.wait(['@getDatafiles', '@getDatafiles', '@getDatafileCount']); cy.get('[aria-label="select all rows"]').check(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'be.checked' ); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + cy.get( + `[aria-label="select row ${Math.floor(Math.random() * 6)}"]` + ).should('be.checked'); - cy.reload().wait(['@getDatafiles', '@getDatafiles']); + cy.get('[aria-label="Filter by Location"]').first().clear(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' ); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - cy.get( - `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` - ).should('not.be.checked'); + .and('eq', 'true'); + + cy.get('[aria-label="select row 0"]').should('be.checked'); + cy.get('[aria-label="select row 1"]').should('not.be.checked'); cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, @@ -379,21 +319,16 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); - cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); - cy.get('[aria-label="select all rows"]').should('not.be.checked'); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); + cy.get('[aria-label="select row 13"]').should('not.be.checked'); + cy.get('[aria-label="select row 14"]').should('be.checked'); }); it('by shift clicking', () => { cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); + cy.get('body').type('{shift}', { release: false }); + cy.get('[aria-label="select row 5"]').click(); cy.get('[aria-label="select row 5"]').should('be.checked'); cy.get('[aria-label="grid"]').scrollTo('top'); @@ -401,19 +336,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 3"]').should('be.checked'); cy.get('[aria-label="select row 2"]').should('be.checked'); cy.get('[aria-label="select row 1"]').should('be.checked'); - }); - - it('and unselect by shift clicking', () => { - cy.get('[aria-label="select row 0"]').click(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); - cy.get('[aria-label="select row 5"]').should('be.checked'); - - cy.get('[aria-label="grid"]').scrollTo('top'); + // and uncheck cy.get('[aria-label="select row 2"]').click(); cy.get('[aria-label="select row 2"]').should('not.be.checked'); @@ -426,15 +350,6 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 1"]').should('be.checked'); cy.get('[aria-label="select row 0"]').should('be.checked'); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); describe('in ISIS table', () => { @@ -450,17 +365,19 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'true'); - }); - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -486,102 +403,80 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]', { timeout: 10000 }) .should('have.attr', 'data-indeterminate') .and('eq', 'false'); - }); - it('by all items in a filtered table', () => { - cy.get('[aria-label="Filter by Location"]') - .first() - .type('g') - .wait(['@getDatafiles', '@getDatafiles']); - - cy.get('[aria-label="select all rows"]').check(); + // and uncheck + cy.get('[aria-label="grid"]').scrollTo('top', { + ensureScrollable: false, + }); + cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' + 'not.be.checked' ); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get( - `[aria-label="select row ${Math.floor(Math.random() * 6)}"]` - ).should('be.checked'); - - cy.get('[aria-label="Filter by Location"]').first().clear(); - - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'not.be.checked' - ); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'true'); - - cy.get('[aria-label="select row 4"]').should('be.checked'); - cy.get('[aria-label="select row 10"]').should('not.be.checked'); - cy.get('[aria-label="select row 0"]').should('be.checked'); - - cy.get('[aria-label="grid"]') - .scrollTo('bottom', { ensureScrollable: false }) - .wait('@getDatafiles'); - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get('[aria-label="select row 13"]').should('be.checked'); - cy.get('[aria-label="select row 14"]').should('be.checked'); - }); + `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` + ).should('not.be.checked'); - it('and unselect all items', () => { cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); + cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); + cy.get('[aria-label="select all rows"]').should('not.be.checked'); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + }); + + it('by all items in a filtered table', () => { + cy.get('[aria-label="Filter by Location"]').first().type('g'); + cy.wait(['@getDatafiles', '@getDatafiles']); cy.get('[aria-label="select all rows"]').check(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'be.checked' ); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + cy.get( + `[aria-label="select row ${Math.floor(Math.random() * 6)}"]` + ).should('be.checked'); - cy.reload().wait([ - '@getDatafiles', - '@getDatafiles', - '@getDatafileCount', - ]); + cy.get('[aria-label="Filter by Location"]').first().clear(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' ); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - cy.get( - `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` - ).should('not.be.checked'); + .and('eq', 'true'); + + cy.get('[aria-label="select row 4"]').should('be.checked'); + cy.get('[aria-label="select row 10"]').should('not.be.checked'); + cy.get('[aria-label="select row 0"]').should('be.checked'); cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); + cy.wait('@getDatafiles'); cy.get('[aria-label="grid"]').scrollTo('bottom', { ensureScrollable: false, }); - cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); - cy.get('[aria-label="select all rows"]').should('not.be.checked'); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); + cy.get('[aria-label="select row 13"]').should('be.checked'); + cy.get('[aria-label="select row 14"]').should('be.checked'); }); it('by shift clicking', () => { cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); + cy.get('body').type('{shift}', { release: false }); + cy.get('[aria-label="select row 5"]').click(); cy.get('[aria-label="select row 5"]').should('be.checked'); cy.get('[aria-label="grid"]').scrollTo('top'); @@ -589,19 +484,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 3"]').should('be.checked'); cy.get('[aria-label="select row 2"]').should('be.checked'); cy.get('[aria-label="select row 1"]').should('be.checked'); - }); - - it('and unselect by shift clicking', () => { - cy.get('[aria-label="select row 0"]').click(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); - cy.get('[aria-label="select row 5"]').should('be.checked'); - cy.get('[aria-label="grid"]').scrollTo('top'); + // and uncheck cy.get('[aria-label="select row 2"]').click(); cy.get('[aria-label="select row 2"]').should('not.be.checked'); @@ -614,15 +498,6 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 1"]').should('be.checked'); cy.get('[aria-label="select row 0"]').should('be.checked'); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); }); @@ -653,12 +528,8 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('1 item has been added to selection.'); }); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') @@ -672,6 +543,11 @@ describe('Add/remove from cart functionality', () => { '1 item has been removed from selection.' ); }); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -690,16 +566,8 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('2 items have been added to selection.'); }); - }); - - it('and unselect all items', () => { - cy.get(`[aria-label="select row 0"]`).should('exist'); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); + // and uncheck cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' @@ -716,15 +584,6 @@ describe('Add/remove from cart functionality', () => { ); }); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); describe('in DLS table', () => { @@ -741,18 +600,19 @@ describe('Add/remove from cart functionality', () => { .should('have.attr', 'data-indeterminate') .and('eq', 'true'); cy.get('[aria-label="select all rows"]').should('not.be.checked'); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get('[aria-label="select all rows"]').should('not.be.checked'); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -766,16 +626,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); - }); - - it('and unselect all items', () => { - cy.get(`[aria-label="select row 0"]`).should('exist'); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); + // and uncheck cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' @@ -785,15 +637,6 @@ describe('Add/remove from cart functionality', () => { .and('eq', 'false'); cy.get(`[aria-label="select row 0"]`).should('not.be.checked'); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); describe('in ISIS table', () => { @@ -810,18 +653,19 @@ describe('Add/remove from cart functionality', () => { .should('have.attr', 'data-indeterminate') .and('eq', 'true'); cy.get('[aria-label="select all rows"]').should('not.be.checked'); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get('[aria-label="select all rows"]').should('not.be.checked'); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -835,16 +679,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); - }); - - it('and unselect all items', () => { - cy.get(`[aria-label="select row 0"]`).should('exist'); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); + // and uncheck cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' @@ -854,15 +690,6 @@ describe('Add/remove from cart functionality', () => { .and('eq', 'false'); cy.get(`[aria-label="select row 0"]`).should('not.be.checked'); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); }); @@ -892,12 +719,8 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('1 item has been added to selection.'); }); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').uncheck(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') @@ -910,6 +733,11 @@ describe('Add/remove from cart functionality', () => { '1 item has been removed from selection.' ); }); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -940,13 +768,42 @@ describe('Add/remove from cart functionality', () => { .then((text) => { expect(text.trim()).equal('59 items have been added to selection.'); }); + + // and uncheck + cy.get('[aria-label="grid"]').scrollTo('top', { + ensureScrollable: false, + }); + cy.get('[aria-label="select all rows"]').uncheck(); + cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( + 'not.be.checked' + ); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + cy.get( + `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` + ).should('not.be.checked'); + + cy.get('[aria-label="grid"]').scrollTo('bottom', { + ensureScrollable: false, + }); + cy.get(`[aria-label="select row 50"]`).should('not.be.checked'); + cy.get('[aria-label="select all rows"]') + .should('have.attr', 'data-indeterminate') + .and('eq', 'false'); + + cy.get('[aria-label="selection-alert-text"]') + .invoke('text') + .then((text) => { + expect(text.trim()).equal( + '59 items have been removed from selection.' + ); + }); }); it('by all items in a filtered table', () => { - cy.get('[aria-label="Filter by Visit ID"]') - .first() - .type('7') - .wait(['@getInvestigations', '@getInvestigations']); + cy.get('[aria-label="Filter by Visit ID"]').first().type('7'); + cy.wait(['@getInvestigations', '@getInvestigations']); cy.get('[aria-label="select all rows"]').check(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( @@ -983,63 +840,12 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 58"]').should('not.be.checked'); }); - it('and unselect all items', () => { - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - - cy.reload().wait(['@getInvestigations', '@getInvestigations']); - - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); - cy.get('[aria-label="select all rows"]').uncheck(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'not.be.checked' - ); - cy.get( - `[aria-label="select row ${Math.floor(Math.random() * 10)}"]` - ).should('not.be.checked'); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get('[aria-label="grid"]').scrollTo('bottom', { - ensureScrollable: false, - }); - cy.get(`[aria-label="select row 14"]`).should('not.be.checked'); - cy.get('[aria-label="select all rows"]') - .should('have.attr', 'data-indeterminate') - .and('eq', 'false'); - - cy.get('[aria-label="selection-alert-text"]') - .invoke('text') - .then((text) => { - expect(text.trim()).equal( - '59 items have been removed from selection.' - ); - }); - }); - it('by shift clicking', () => { cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); + cy.get('body').type('{shift}', { release: false }); + cy.get('[aria-label="select row 5"]').click(); cy.get('[aria-label="select row 5"]').should('be.checked'); cy.get('[aria-label="grid"]').scrollTo('top'); @@ -1048,24 +854,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select row 2"]').should('be.checked'); cy.get('[aria-label="select row 1"]').should('be.checked'); - cy.get('[aria-label="selection-alert-text"]') - .invoke('text') - .then((text) => { - expect(text.trim()).equal('5 items have been added to selection.'); - }); - }); - - it('and unselect by shift clicking', () => { - cy.get('[aria-label="select row 0"]').click(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - - cy.get('body') - .type('{shift}', { release: false }) - .get('[aria-label="select row 5"]') - .click(); - cy.get('[aria-label="select row 5"]').should('be.checked'); + // and uncheck - cy.get('[aria-label="grid"]').scrollTo('top'); cy.get('[aria-label="select row 2"]').click(); cy.get('[aria-label="select row 2"]').should('not.be.checked'); @@ -1086,15 +876,6 @@ describe('Add/remove from cart functionality', () => { ); }); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); describe('in ISIS browse table', () => { @@ -1113,18 +894,19 @@ describe('Add/remove from cart functionality', () => { .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get('[aria-label="select all rows"]').should('be.checked'); - }); - - it('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').click(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get('[aria-label="select all rows"]').should('not.be.checked'); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); it('by all items', () => { @@ -1138,16 +920,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); - }); - - it('and unselect all items', () => { - cy.get(`[aria-label="select row 0"]`).should('exist'); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); + // and uncheck cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' @@ -1157,19 +931,19 @@ describe('Add/remove from cart functionality', () => { .and('eq', 'false'); cy.get(`[aria-label="select row 0"]`).should('not.be.checked'); }); - - it('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); describe('in ISIS my data table', () => { beforeEach(() => { + cy.login( + { + username: 'root', + password: 'pw', + mechanism: 'simple', + }, + 'Richard459' + ); + cy.visit('/my-data/ISIS').wait([ '@getInvestigations', '@getInvestigations', @@ -1177,18 +951,15 @@ describe('Add/remove from cart functionality', () => { ]); }); - it.skip('individually', () => { + it('individually', () => { cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('be.checked'); cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get('[aria-label="select all rows"]').should('be.checked'); - }); - it.skip('and unselect them individually', () => { - cy.get('[aria-label="select row 0"]').click(); - cy.get('[aria-label="select row 0"]').should('be.checked'); + // and uncheck cy.get('[aria-label="select row 0"]').click(); cy.get('[aria-label="select row 0"]').should('not.be.checked'); @@ -1196,9 +967,14 @@ describe('Add/remove from cart functionality', () => { .should('have.attr', 'data-indeterminate') .and('eq', 'false'); cy.get('[aria-label="select all rows"]').should('not.be.checked'); + + cy.get('[aria-label="selection-alert-link"]').click(); + cy.location().should((loc) => { + expect(loc.pathname).to.equal('/download'); + }); }); - it.skip('by all items', () => { + it('by all items', () => { cy.get(`[aria-label="select row 0"]`).should('exist'); cy.get('[aria-label="select all rows"]').check(); @@ -1209,16 +985,8 @@ describe('Add/remove from cart functionality', () => { cy.get('[aria-label="select all rows"]') .should('have.attr', 'data-indeterminate') .and('eq', 'false'); - }); - - it.skip('and unselect all items', () => { - cy.get(`[aria-label="select row 0"]`).should('exist'); - - cy.get('[aria-label="select all rows"]').check(); - cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( - 'be.checked' - ); + // and uncheck cy.get('[aria-label="select all rows"]').uncheck(); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'not.be.checked' @@ -1228,15 +996,6 @@ describe('Add/remove from cart functionality', () => { .and('eq', 'false'); cy.get(`[aria-label="select row 0"]`).should('not.be.checked'); }); - - it.skip('and navigate to selection using banner', () => { - cy.get('[aria-label="select row 0"]').check(); - cy.get('[aria-label="select row 0"]').should('be.checked'); - cy.get('[aria-label="selection-alert-link"]').click(); - cy.location().should((loc) => { - expect(loc.pathname).to.equal('/download'); - }); - }); }); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/landing/isis/dataPublication.cy.ts b/packages/datagateway-dataview/cypress/e2e/landing/isis/dataPublication.cy.ts index 338ae95bc..9e58009c4 100644 --- a/packages/datagateway-dataview/cypress/e2e/landing/isis/dataPublication.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/landing/isis/dataPublication.cy.ts @@ -8,6 +8,22 @@ describe('ISIS - Data Publication Landing', () => { cy.title().should('equal', 'DataGateway DataView'); cy.get('#datagateway-dataview').should('be.visible'); cy.contains('Yourself good together red across.').should('be.visible'); + cy.contains('a', '0-7602-7584-X').should( + 'have.attr', + 'href', + 'https://doi.org/0-7602-7584-X' + ); + cy.get('[data-testid="landing-dataPublication-pid-link"]') + .first() + .then(($pid) => { + const pid = $pid.text(); + + const url = `https://doi.org/${pid}`; + + cy.get('[data-testid="landing-dataPublication-pid-link"]') + .first() + .should('have.attr', 'href', url); + }); }); it('should be able to click tab to see investigations', () => { @@ -31,28 +47,6 @@ describe('ISIS - Data Publication Landing', () => { ); }); - it('should be able to click a DOI render the correct webpage ', () => { - cy.contains('a', '0-7602-7584-X').should( - 'have.attr', - 'href', - 'https://doi.org/0-7602-7584-X' - ); - }); - - it('should have the correct urls for the DOI link and Data Publication PID', () => { - cy.get('[data-testid="landing-dataPublication-pid-link"]') - .first() - .then(($pid) => { - const pid = $pid.text(); - - const url = `https://doi.org/${pid}`; - - cy.get('[data-testid="landing-dataPublication-pid-link"]') - .first() - .should('have.attr', 'href', url); - }); - }); - it('should load correctly when investigation missing', () => { cy.intercept('**/datapublications?*', [ { @@ -72,20 +66,14 @@ describe('ISIS - Data Publication Landing', () => { pid: '10.5286/ISIS.E.RB1810842', }, ]); - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="landing-dataPublication-pid-link"]') .first() - .trigger('mouseover') - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + .trigger('mouseover'); + cy.get('[role="tooltip"]').should('exist'); cy.get('body').type('{esc}'); - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="landing-dataPublication-pid-link"]') - .wait(700) .first() .get('[role="tooltip"]') .should('not.exist'); diff --git a/packages/datagateway-dataview/cypress/e2e/landing/isis/dataset.cy.ts b/packages/datagateway-dataview/cypress/e2e/landing/isis/dataset.cy.ts index 1c540373d..54d475507 100644 --- a/packages/datagateway-dataview/cypress/e2e/landing/isis/dataset.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/landing/isis/dataset.cy.ts @@ -10,6 +10,20 @@ describe('ISIS - Dataset Landing', () => { cy.title().should('equal', 'DataGateway DataView'); cy.get('#datagateway-dataview').should('be.visible'); cy.contains('DATASET 79').should('be.visible'); + + // DOI + + cy.get('[data-testid="isis-dataset-landing-doi-link"]') + .first() + .then(($doi) => { + const doi = $doi.text(); + + const url = `https://doi.org/${doi}`; + + cy.get('[data-testid="isis-dataset-landing-doi-link"]') + .first() + .should('have.attr', 'href', url); + }); }); it('should be able to click a dataset to see its datafiles', () => { @@ -22,7 +36,7 @@ describe('ISIS - Dataset Landing', () => { it('should disable the hover tool tip by pressing escape', () => { cy.intercept( - '/datasets?where=%7B%22id%22%3A%7B%22eq%22%3A79%7D%7D&include=%22type%22', + '**/datasets?where=%7B%22id%22%3A%7B%22eq%22%3A79%7D%7D&include=%22type%22', [ { id: 79, @@ -38,38 +52,16 @@ describe('ISIS - Dataset Landing', () => { ] ); - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="isis-dataset-landing-doi-link"]') .first() - .trigger('mouseover') - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + .trigger('mouseover'); + cy.get('[role="tooltip"]').should('exist'); cy.get('body').type('{esc}'); - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="isis-dataset-landing-doi-link"]') - .wait(700) .first() .get('[role="tooltip"]') .should('not.exist'); }); - - it('should have the correct url for the DOI link', () => { - // DOI - - cy.get('[data-testid="isis-dataset-landing-doi-link"]') - .first() - .then(($doi) => { - const doi = $doi.text(); - - const url = `https://doi.org/${doi}`; - - cy.get('[data-testid="isis-dataset-landing-doi-link"]') - .first() - .should('have.attr', 'href', url); - }); - }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/landing/isis/investigation.cy.ts b/packages/datagateway-dataview/cypress/e2e/landing/isis/investigation.cy.ts index 978c96c60..6ac5c88ca 100644 --- a/packages/datagateway-dataview/cypress/e2e/landing/isis/investigation.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/landing/isis/investigation.cy.ts @@ -8,17 +8,7 @@ describe('ISIS - Investigation Landing', () => { cy.title().should('equal', 'DataGateway DataView'); cy.get('#datagateway-dataview').should('be.visible'); cy.contains('Stop system investment').should('be.visible'); - }); - - it('should be able to click an investigation to see its datasets', () => { - cy.get('#investigation-datasets-tab').first().click({ force: true }); - cy.location('pathname').should( - 'eq', - '/browse/instrument/13/facilityCycle/12/investigation/31/dataset' - ); - }); - it('should have the correct urls for the DOI link and parent DOI link', () => { // DOI cy.get('[data-testid="isis-investigation-landing-doi-link"]') @@ -48,6 +38,14 @@ describe('ISIS - Investigation Landing', () => { }); }); + it('should be able to click an investigation to see its datasets', () => { + cy.get('#investigation-datasets-tab').first().click({ force: true }); + cy.location('pathname').should( + 'eq', + '/browse/instrument/13/facilityCycle/12/investigation/31/dataset' + ); + }); + it('should be able to click a specific dataset', () => { cy.get('[aria-label="landing-investigation-part-label"') .children() @@ -96,37 +94,26 @@ describe('ISIS - Investigation Landing', () => { }, ]); - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="isis-investigations-landing-parent-doi-link"]') .first() - .trigger('mouseover') - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + .trigger('mouseover'); + cy.get('[role="tooltip"]').should('exist'); cy.get('body').type('{esc}'); - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="isis-investigations-landing-parent-doi-link"]') - .wait(700) .first() .get('[role="tooltip"]') .should('not.exist'); - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="isis-investigation-landing-doi-link"]') .first() - .trigger('mouseover') - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + .trigger('mouseover'); + cy.get('[role="tooltip"]').should('exist'); cy.get('body').type('{esc}'); - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="isis-investigation-landing-doi-link"]') - .wait(700) .first() .get('[role="tooltip"]') .should('not.exist'); diff --git a/packages/datagateway-dataview/cypress/e2e/table/datafiles.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/datafiles.cy.ts index f673571c2..f22a37247 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/datafiles.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/datafiles.cy.ts @@ -20,66 +20,6 @@ describe('Datafiles Table', () => { cy.get('[role="grid"]').should('not.exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select, details and actions column widths - columnWidth = (windowWidth - 40 - 40 - 70) / 4; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('nameColumn'); - cy.get('[role="columnheader"]').eq(3).as('locationColumn'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - // Unable to test lazy loading as there are only 15 datafiles in it.skip('should be able to scroll down and load more rows', () => { cy.get('[aria-rowcount="50"]').should('exist'); @@ -87,175 +27,128 @@ describe('Datafiles Table', () => { cy.get('[aria-rowcount="55"]').should('exist'); }); - describe('should be able to sort by', () => { - beforeEach(() => { - cy.wait( - [ - '@investigations', - '@datafilesCount', - '@datasets', - '@datafilesOrder', - '@datafilesOrder', - ], - { - timeout: 10000, - } - ); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/able/leg/policy.gif' - ); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/writer/family/pull.bmp' - ); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/five/with/question.bmp' - ); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Modified Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 119' - ); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + cy.wait( + [ + '@investigations', + '@datafilesCount', + '@datasets', + '@datafilesOrder', + '@datafilesOrder', + ], + { + timeout: 10000, + } + ); + + // ascending + cy.contains('[role="button"]', 'Location').as('locationSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/able/leg/policy.gif' + ); + + // descending + cy.get('@locationSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/writer/family/pull.bmp' + ); + + // no order + cy.get('@locationSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/five/with/question.bmp' + ); + + // multiple columns + cy.contains('[role="button"]', 'Name').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'Modified Time').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1071'); }); - describe('should be able to filter by', () => { - beforeEach(() => { - cy.wait( - [ - '@investigations', - '@datafilesCount', - '@datasets', - '@datafilesOrder', - '@datafilesOrder', - ], - { - timeout: 10000, - } - ); - }); - - it('text', () => { - cy.get('[aria-label="Filter by Location"]').first().type('candidate'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 1071' - ); - }); - - it('date between', () => { - cy.get('input[id="Modified Time filter from"]').type('2019-01-01'); - const date = new Date(); - cy.get('input[aria-label="Modified Time filter to"]').type( - date.toISOString().slice(0, 10) - ); - - cy.get('[aria-rowcount="15"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 119' - ); - cy.get('[aria-rowindex="2"] [aria-colindex="3"]').contains( - 'Datafile 238' - ); - }); - - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]') - .first() - .type('4') - .wait('@datafilesCount', { timeout: 10000 }); - cy.get('[aria-label="Filter by Location"]') - .first() - .type('.gif') - .wait('@datafilesCount', { timeout: 10000 }); - - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 476' - ); - }); + it('should be able to filter with both text & date filters on multiple columns', () => { + cy.wait( + [ + '@investigations', + '@datafilesCount', + '@datasets', + '@datafilesOrder', + '@datafilesOrder', + ], + { + timeout: 10000, + } + ); + // test text filter + cy.get('[aria-label="Filter by Location"]').first().type('candidate'); + + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1071'); + + // test date filter + cy.get('input[id="Modified Time filter from"]').type('2019-01-01'); + + cy.get('[aria-rowcount="1"]').should('exist'); + + cy.get('input[aria-label="Modified Time filter to"]') + .parent() + .find('button') + .click(); + const date = new Date(); + date.setDate(1); + date.setFullYear(2020); + + cy.get('.MuiPickersCalendarHeader-label').click(); + cy.contains('2020').click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + + cy.get('input[id="Modified Time filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); + + cy.get('[aria-rowcount="0"]').should('exist'); }); - describe('should be able to view details', () => { - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').should('be.visible'); + cy.get('#details-panel').contains('Datafile 238').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); - cy.get('#details-panel').contains('Datafile 119').should('be.visible'); - cy.get('#details-panel').contains('Datafile 238').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); + cy.get('[aria-label="Show details"]').first().click(); - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').contains('Datafile 119').should('be.visible'); + cy.get('#details-panel').contains('Datafile 238').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('[aria-label="Hide details"]').first().click(); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/datasets.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/datasets.cy.ts index 6d396e3db..2b0dd0fd6 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/datasets.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/datasets.cy.ts @@ -24,66 +24,6 @@ describe('Datasets Table', () => { ); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select and details column widths - columnWidth = (windowWidth - 40 - 40) / 4; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('nameColumn'); - cy.get('[role="columnheader"]').eq(3).as('sizeColumn'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@sizeColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@sizeColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@sizeColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - // current example data only has 2 datasets per investigation, so can't test lazy loading it.skip('should be able to scroll down and load more rows', () => { cy.get('[aria-rowcount="50"]').should('exist'); @@ -91,124 +31,96 @@ describe('Datasets Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - describe('should be able to sort by', () => { - it('ascending order', () => { - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Create Time').click(); - cy.contains('[role="button"]', 'Create Time').click(); - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - }); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + // ascending order + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); + + // descending order + cy.get('@nameSortButton').click(); - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Name"]').first().type('DATASET 1'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); - - it.skip('date between', () => { - // Unable to test as cypress doesn't want to type into date fields. - cy.get('input[id="Create Time filter from"]').type('2006-01-01', { - force: true, - }); - - cy.get('input[aria-label="Create Time filter to"]') - .parent() - .find('button') - .click(); - - cy.get('.MuiPickersDay-root[type="button"]').first().click(); - - const date = new Date(); - date.setDate(1); - - cy.get('input[id="Create Time filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 241'); - }); - - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]').first().type('6'); - const date = new Date(); - cy.get('input[id="Create Time filter to"]').type( - date.toISOString().slice(0, 10) - ); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); + + // no order + cy.get('@nameSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); + + cy.contains('[role="button"]', 'Create Time').as('timeSortButton').click(); + cy.get('@timeSortButton').click(); + cy.get('@nameSortButton').click(); + cy.get('@nameSortButton').click(); + + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); }); - describe('should be able to view details', () => { - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('[aria-label="Filter by Name"]').first().type('6'); + + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); + // test date filter + cy.get('input[id="Create Time filter from"]').type('2006-01-01'); + + cy.get('[aria-rowcount="1"]').should('exist'); + + cy.get('input[aria-label="Create Time filter to"]') + .parent() + .find('button') + .click(); + + const date = new Date(); + date.setDate(1); + date.setFullYear(2020); + + cy.get('.MuiPickersCalendarHeader-label').click(); + cy.contains('2020').click(); + + cy.get('.MuiPickersDay-root[type="button"]').first().click(); + + cy.get('input[id="Create Time filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); + + cy.get('[aria-rowcount="0"]').should('exist'); + }); - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').should('be.visible'); + cy.get('#details-panel').contains('DATASET 61').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); - cy.get('#details-panel').contains('DATASET 1').should('be.visible'); - cy.get('#details-panel').contains('DATASET 61').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); + cy.get('[aria-label="Show details"]').first().click(); - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').contains('DATASET 1').should('be.visible'); + cy.get('#details-panel').contains('DATASET 61').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('[aria-label="Hide details"]').first().click(); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/dls/datafiles.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/dls/datafiles.cy.ts index 750f55349..f8e316209 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/dls/datafiles.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/dls/datafiles.cy.ts @@ -37,231 +37,90 @@ describe('DLS - Datafiles Table', () => { cy.get('[aria-rowcount="55"]').should('exist'); }); - it('should be able to resize a column', () => { - // Filtering results so vertical scrollbar won't appear as this can impact on the - // column width causing these types of tests to intermittently fail - cy.get('[aria-label="Filter by Location"]').first().type('rise'); - - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select and details column widths - columnWidth = (windowWidth - 40 - 40) / 4; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('nameColumn'); - cy.get('[role="columnheader"]').eq(3).as('locationColumn'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/analysis/unit/bank.tiff' - ); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Create Time').as('timeSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + // ascending order + cy.contains('[role="button"]', 'Location').as('locationSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/analysis/unit/bank.tiff' + ); - it('descending order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); + // descending order + cy.get('@locationSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/to/total/according.tiff' - ); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/to/total/according.tiff' + ); - it('no order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); + // no order + cy.get('@locationSortButton').click(); - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/time/run/drug.jpeg' - ); - }); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/time/run/drug.jpeg' + ); - it('multiple columns', () => { - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); + // multiple columns + cy.get('@timeSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + cy.get('@nameSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 60'); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 60'); }); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - }); - - it('text', () => { - cy.get('[aria-label="Filter by Location"]').first().type('unit'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 1369' - ); - }); - - it('date between', () => { - cy.get('input[id="Create Time filter from"]').type('2019-01-01'); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('input[aria-label="Filter by Location"]').type('unit'); - const date = new Date(); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1369'); - cy.get('input[aria-label="Create Time filter to"]').type( - date.toISOString().slice(0, 10) - ); + // test date filter + cy.get('input[aria-label="Create Time filter to"]').type('2019-01-01'); - cy.get('[aria-rowcount="15"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 60'); - cy.get('[aria-rowindex="2"] [aria-colindex="3"]').contains( - 'Datafile 179' - ); - }); - - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]') - .first() - .type('5') - .wait('@datafilesCount', { timeout: 10000 }); - - cy.get('[aria-label="Filter by Location"]') - .first() - .type('.gif') - .wait('@datafilesCount', { timeout: 10000 }); - - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 536' - ); - }); + cy.get('[aria-rowcount="0"]').should('exist'); }); - describe('should be able to view details', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - }); - - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); + cy.get('#details-panel').contains('Datafile 1607').should('be.visible'); - cy.get('#details-panel').contains('Datafile 60').should('be.visible'); - cy.get('#details-panel').contains('Datafile 179').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); + cy.get('[aria-label="Show details"]').first().click(); - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').contains('Datafile 1726').should('be.visible'); + cy.get('#details-panel').contains('Datafile 1607').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('[aria-label="Hide details"]').first().click(); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/dls/datasets.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/dls/datasets.cy.ts index 3d92b9a50..a5f9ce928 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/dls/datasets.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/dls/datasets.cy.ts @@ -50,222 +50,104 @@ describe('DLS - Datasets Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select and details column widths - columnWidth = (windowWidth - 40 - 40) / 4; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('nameColumn'); - cy.get('[role="columnheader"]').eq(3).as('datafileCountColumn'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@datafileCountColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Create Time').as('timeSortButton').click(); - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@datafileCountColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); + // ascending order + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@datasets', { timeout: 10000 }); - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - cy.get('@datafileCountColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time').click(); - }); + // descending order + cy.get('@nameSortButton').click(); + cy.wait('@datasets', { timeout: 10000 }); - it('ascending order', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datasets', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasets', { timeout: 10000 }); - - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); + + // no order + cy.get('@nameSortButton').click(); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); + + // multiple columns + cy.get('@timeSortButton').click(); + cy.wait('@datasets', { timeout: 10000 }); + cy.get('@nameSortButton').click(); + cy.wait('@datasets', { timeout: 10000 }); + cy.get('@nameSortButton').click(); + cy.wait('@datasets', { timeout: 10000 }); + + cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); }); - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Name"]').first().type('DATASET 1'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 1'); - }); - - it('date between', () => { - const date = new Date(); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('[aria-label="Filter by Name"]').first().type('61'); - cy.get('input[id="Create Time filter from"]').type('2002-01-01'); - cy.get('input[id="Create Time filter to"]').type( - date.toISOString().slice(0, 10) - ); - - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]') - .first() - .type('1') - .wait(['@datasetsCount', '@datasets'], { timeout: 10000 }); - - cy.get('input[id="Create Time filter from"]') - .type('2006-11-21') - .wait(['@datasetsCount', '@datasets'], { timeout: 10000 }); - - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 61'); - }); + // test date filter + cy.get('input[aria-label="Create Time filter to"]').type('2002-01-01'); + cy.get('[aria-rowcount="0"]').should('exist'); }); describe('should be able to view details', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time').click(); - }); + it('and can calculate size, all the details are correct & also able to hide the panel', () => { + // need to wait for counts to finish, otherwise cypress might interact with the details panel + // too quickly and it rerenders during the test + cy.contains('[aria-rowindex="1"] [aria-colindex="4"]', '15').should( + 'exist' + ); + cy.contains('[aria-rowindex="2"] [aria-colindex="4"]', '15').should( + 'exist' + ); - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('[aria-label="Show details"]').eq(1).click(); cy.get('#details-panel').should('be.visible'); cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); + cy.get('#details-panel').contains('DATASET 1').should('be.visible'); cy.get('[aria-label="Show details"]').first().click(); - cy.get('#details-panel').contains('DATASET 1').should('be.visible'); - cy.get('#details-panel').contains('DATASET 241').should('not.exist'); + cy.get('#details-panel').contains('DATASET 61').should('be.visible'); + cy.get('#details-panel').contains('DATASET 1').should('not.exist'); cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); - - it('and view dataset details', () => { - cy.get('[aria-label="Show details"]').first().click(); cy.get('#details-panel') - .contains( - 'Suggest shake effort many last prepare small. Maintain throw hope parent. ' + - 'Entire soon option bill fish against power. Rather why rise month shake voice.' - ) + .contains('Home down your nice amount successful') .should('be.visible'); - }); - it('and then calculate file size', () => { - // need to wait for counts to finish, otherwise cypress might interact with the details panel - // too quickly and it rerenders during the test - cy.contains('[aria-rowindex="1"] [aria-colindex="4"]', '15').should( - 'exist' - ); - cy.contains('[aria-rowindex="2"] [aria-colindex="4"]', '15').should( - 'exist' - ); + cy.contains('#calculate-size-btn', 'Calculate').should('exist').click(); + cy.contains('1.73 GB', { timeout: 10000 }).should('be.visible'); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('[aria-controls="dataset-type-panel"]').click(); + cy.get('#dataset-type-panel').should('not.have.attr', 'hidden'); + cy.get('#details-panel').contains('DATASETTYPE 3'); - cy.contains('#calculate-size-btn', 'Calculate') - .should('exist') - .click({ force: true }); - cy.contains('1.39 GB', { timeout: 10000 }) - .scrollIntoView() - .should('be.visible'); + cy.get('[aria-label="Hide details"]').first().click(); + + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); it('and then calculate file size when the value is 0 ', () => { @@ -282,57 +164,9 @@ describe('DLS - Datasets Table', () => { cy.get('[aria-label="Show details"]').first().click(); - cy.contains('#calculate-size-btn', 'Calculate') - .should('exist') - .click({ force: true }); - cy.contains('0 B', { timeout: 10000 }) - .scrollIntoView() - .should('be.visible'); - }); - - it('and view the dataset type panel', () => { - // need to wait for counts to finish, otherwise cypress might interact with the details panel - // too quickly and it rerenders during the test - cy.contains('[aria-rowindex="1"] [aria-colindex="4"]', '15').should( - 'exist' - ); - cy.contains('[aria-rowindex="2"] [aria-colindex="4"]', '15').should( - 'exist' - ); - - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-controls="dataset-type-panel"]').click(); + cy.contains('#calculate-size-btn', 'Calculate').should('exist').click(); - cy.get('#dataset-type-panel').should('not.have.attr', 'hidden'); - cy.get('#details-panel').contains('DATASETTYPE 2').should('be.visible'); + cy.contains('0 B', { timeout: 10000 }).should('be.visible'); }); - - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-label="Hide details"]').first().click(); - - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); - }); - - it('should display correct datafile count after filtering', () => { - cy.visit('/browse/proposal/INVESTIGATION%202/investigation/2/dataset').wait( - ['@investigationsFindOne', '@datasetsCount', '@datasets'], - { - timeout: 10000, - } - ); - - cy.get('[aria-label="Filter by Name"]') - .first() - .type('DATASET 62') - .wait(['@datasetsCount', '@datasets'], { - timeout: 10000, - }); - - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('1'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/dls/myData.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/dls/myData.cy.ts index f42ea79c7..803ddc0fa 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/dls/myData.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/dls/myData.cy.ts @@ -29,23 +29,6 @@ describe('DLS - MyData Table', () => { cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); }); - it('should be able to click clear filters button to clear filters', () => { - cy.url().should('include', 'filters'); - - cy.url().then((url) => { - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('input[id="Title-filter"]').type('star'); - - cy.wait('@getInvestigations'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('72'); - - cy.get('[data-testid="clear-filters-button"]').click(); - cy.url().should('eq', url); - }); - }); - it('should be able to click an investigation to see its datasets', () => { cy.get('[role="gridcell"] a').first().click({ force: true }); @@ -55,249 +38,122 @@ describe('DLS - MyData Table', () => { ); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="dls-mydata-table-name"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="dls-mydata-table-name"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - columnWidth = (windowWidth - 40) / 6; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(1).as('titleColumn'); - cy.get('[role="columnheader"]').eq(2).as('visitIdColumn'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@visitIdColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@visitIdColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@visitIdColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').click(); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date').click(); - }); + // ascending order + cy.contains('[role="button"]', 'Title').as('titleSortButton').click(); - it('ascending order', () => { - cy.contains('[role="button"]', 'Title').click(); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Across prepare why go.' + ); - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Across prepare why go.' - ); - }); + // descending order + cy.get('@titleSortButton').click(); - it('descending order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Star enter wide nearly off.' - ); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Star enter wide nearly off.' + ); - it('no order', () => { - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Star enter wide nearly off.' - ); - }); + // no order + cy.get('@titleSortButton').click(); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Star enter wide nearly off.' + ); - it('multiple columns', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Instrument').click(); + // multiple columns + cy.get('@titleSortButton').click(); + cy.contains('[role="button"]', 'Instrument').click(); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Across prepare why go.' - ); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Across prepare why go.' + ); }); - describe('should be able to filter by', () => { - it('role', () => { - cy.get('[aria-rowcount="2"]').should('exist'); - - cy.get('#role-selector').click(); - cy.get('[role="listbox"]') - .find('[role="option"]') - .should('have.length', 3); - cy.get('[role="option"][data-value="PI"]').click(); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('72'); - - cy.get('#role-selector').click(); - cy.get('[role="option"]').first().click(); - cy.get('[aria-rowcount="2"]').should('exist'); - }); - - it('text', () => { - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('input[id="Title-filter"]').type('star'); + it('should be able to filter with role, text & date filters on multiple columns', () => { + // role + cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('72'); - }); + cy.get('#role-selector').click(); + cy.get('[role="listbox"]') + .find('[role="option"]') + .should('have.length', 3); + cy.get('[role="option"][data-value="PI"]').click(); - it('date between', () => { - cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('72'); - const date = new Date(); + cy.get('#role-selector').click(); + cy.get('[role="option"]').first().click(); + cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('input[aria-label="Start Date filter to"]').type( - date.toISOString().slice(0, 10) - ); + // test text filter + cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('input[id="Title-filter"]').type('star'); - cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('72'); - cy.get('input[id="Start Date filter from"]').type('2004-01-01'); + // test date filter + cy.get('input[id="Start Date filter from"]').type('2004-01-01'); - cy.get('[aria-rowcount="1"]').should('exist'); - }); - - it('multiple columns', () => { - cy.get('input[id="Start Date filter from"]').first().type('2004-01-01'); - - cy.get('[aria-rowcount="1"]').should('exist'); - - cy.get('[aria-label="Filter by Title"]').first().type('or'); - - cy.get('[aria-rowcount="1"]').should('exist'); - }); + cy.get('[aria-rowcount="0"]').should('exist'); }); - describe('should be able to view details', () => { - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); - it('and view visit users, samples and publications', () => { - cy.contains('[aria-rowindex="1"] [aria-colindex="4"]', '2').should( - 'exist' - ); + cy.get('#details-panel').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); + cy.get('#details-panel') + .contains('Star enter wide nearly off.') + .should('be.visible'); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('[aria-label="Show details"]').first().click(); - cy.get('[aria-controls="visit-samples-panel"]').click(); - cy.get('#visit-samples-panel').should('not.have.attr', 'hidden'); - cy.get('#details-panel').contains('SAMPLE 21').should('be.visible'); - - cy.get('[aria-controls="visit-users-panel"]').click(); - cy.get('#visit-users-panel').should('not.have.attr', 'hidden'); - cy.get('#details-panel') - .contains('Thomas Chambers') - .should('be.visible'); - - cy.get('[aria-controls="visit-publications-panel"]').click(); - cy.get('#visit-publications-panel').should('not.have.attr', 'hidden'); - cy.get('#details-panel').contains( - 'From central effort glass evidence life.' - ); - }); - - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); - cy.get('#details-panel') - .contains('Star enter wide nearly off.') - .should('be.visible'); + cy.get('#details-panel') + .contains('Across prepare why go.') + .should('be.visible'); + cy.get('#details-panel') + .contains('Star enter wide nearly off.') + .should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('[aria-controls="visit-samples-panel"]').click(); + cy.get('#visit-samples-panel').should('not.have.attr', 'hidden'); + cy.get('#details-panel').contains('SAMPLE 21').should('be.visible'); - cy.get('#details-panel') - .contains('Across prepare why go.') - .should('be.visible'); - cy.get('#details-panel') - .contains('Star enter wide nearly off.') - .should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); + cy.get('[aria-controls="visit-users-panel"]').click(); + cy.get('#visit-users-panel').should('not.have.attr', 'hidden'); + cy.get('#details-panel').contains('Thomas Chambers').should('be.visible'); - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('[aria-controls="visit-publications-panel"]').click(); + cy.get('#visit-publications-panel').should('not.have.attr', 'hidden'); + cy.get('#details-panel').contains( + 'From central effort glass evidence life.' + ); - cy.get('[aria-label="Hide details"]').first().click(); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/dls/proposals.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/dls/proposals.cy.ts index 69d7bf223..463bd24e0 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/dls/proposals.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/dls/proposals.cy.ts @@ -23,111 +23,24 @@ describe('DLS - Proposals Table', () => { it('should be able to scroll down and load more rows', () => { cy.get('[aria-rowcount="50"]').should('exist'); cy.get('[aria-label="grid"]').scrollTo('bottom'); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(3000); - cy.get('[aria-label="grid"]').scrollTo('bottom'); cy.get('[aria-rowcount="59"]').should('exist'); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="dls-proposals-table-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="dls-proposals-table-title"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - columnWidth = windowWidth / 2; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(0).as('titleColumn'); - cy.get('[role="columnheader"]').eq(1).as('nameColumn'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 500 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 1000 }) - .trigger('mouseup'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - - describe('should be able to filter by', () => { - beforeEach(() => { - cy.wait(['@investigations', '@investigationsCount'], { timeout: 10000 }); - }); - - it('text', () => { - cy.get('[aria-label="Filter by Title"]').first().type('dog'); + it('should be able to filter', () => { + cy.wait(['@investigations', '@investigationsCount'], { timeout: 10000 }); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'INVESTIGATION 52' - ); - }); + cy.get('[aria-label="Filter by Name"]').first().type('2'); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Title"]').first().type('dog'); + cy.get('[aria-rowcount="15"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'INVESTIGATION 21' + ); - cy.get('[aria-label="Filter by Name"]').first().type('INVESTIGATION 36'); + cy.get('[aria-label="Filter by Title"]').first().type('dog'); - cy.get('[aria-rowcount="0"]').should('exist'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'INVESTIGATION 52' + ); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/dls/visits.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/dls/visits.cy.ts index 632bfde30..2fd9b2b78 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/dls/visits.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/dls/visits.cy.ts @@ -41,164 +41,83 @@ describe('DLS - Visits Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - columnWidth = (windowWidth - 40) / 5; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(1).as('nameColumn'); - cy.get('[role="columnheader"]').eq(2).as('datasetCountColumn'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@datasetCountColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); + // only 1 visit so no point testing sort + it.skip('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').as('dateSortButton').click(); - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); + // ascending order + cy.contains('[role="button"]', 'Visit ID').as('visitIdSortButton').click(); - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@datasetCountColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@datasetCountColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); + // descending order + cy.get('@visitIdSortButton').click(); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date').click(); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Visit ID').click(); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Visit ID').click(); - cy.contains('[role="button"]', 'Visit ID').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Visit ID').click(); - cy.contains('[role="button"]', 'Visit ID').click(); - cy.contains('[role="button"]', 'Visit ID').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); + + // no order + cy.get('@visitIdSortButton').click(); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - it('multiple columns', () => { - cy.contains('[role="button"]', 'Start Date').click(); - cy.contains('[role="button"]', 'Visit ID').click(); + // multiple columns + cy.get('@dateSortButton').click(); + cy.get('@visitIdSortButton').click(); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); }); - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Visit ID"]').first().type('70'); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('[aria-label="Filter by Visit ID"]').first().type('70'); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - }); + cy.wait('@investigations'); - it('date between', () => { - cy.get('input[id="Start Date filter from"]').type('2000-04-03'); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - cy.get('input[aria-label="Start Date filter to"]') - .parent() - .find('button') - .click(); + // test date filter + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); - cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); - const date = new Date(); - date.setDate(1); + cy.wait('@investigations'); + cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('input[id="Start Date filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains('70'); - }); + const date = new Date(); + date.setDate(1); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Visit ID"]').first().type('70'); + cy.get('input[id="Start Date filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); - cy.get('[aria-label="Filter by Instrument').first().type('INSTRUMENT 3'); + cy.get('input[id="Start Date filter from"]').type('2001-01-01'); - cy.get('[aria-rowcount="1"').should('exist'); - }); + cy.get('[aria-rowcount="0"]').should('exist'); }); describe('should be able to view details', () => { - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('and then calculate file size', () => { + it('and can calculate size, all the details are correct & also able to hide the panel', () => { // We need to wait for counts to finish, otherwise cypress // might interact with the details panel too quickly and // it re-renders during the test. @@ -207,46 +126,14 @@ describe('DLS - Visits Table', () => { ); cy.get('[aria-label="Show details"]').first().click(); - cy.contains('#calculate-size-btn', 'Calculate') - .should('exist') - .click({ force: true }); - cy.contains('3.12 GB', { timeout: 10000 }) - .scrollIntoView() - .should('be.visible'); - }); - - it('and then calculate file size when the value is 0', () => { - cy.intercept('**/getSize?*', '0'); - - // We need to wait for counts to finish, otherwise cypress - // might interact with the details panel too quickly and - // it re-renders during the test. - - cy.contains('[aria-rowindex="1"] [aria-colindex="3"]', '2').should( - 'exist' - ); - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); cy.contains('#calculate-size-btn', 'Calculate') .should('exist') - .click({ force: true }); - cy.contains('0 B', { timeout: 10000 }) - .scrollIntoView() - .should('be.visible'); - }); - - // TODO: Since we only have one investigation, we cannot test - // showing details when another row is showing details at the moment. - - it('and view visit users, samples and publications', () => { - // We need to wait for counts to finish, otherwise cypress - // might interact with the details panel too quickly and - // it re-renders during the test. - cy.contains('[aria-rowindex="1"] [aria-colindex="3"]', '2').should( - 'exist' - ); - - cy.get('[aria-label="Show details"]').first().click(); + .scrollIntoView(); + cy.contains('#calculate-size-btn', 'Calculate').click(); + cy.contains('3.12 GB', { timeout: 10000 }).should('be.visible'); cy.get('[aria-controls="visit-users-panel"]').click(); cy.get('#visit-users-panel').should('not.have.attr', 'hidden'); @@ -261,15 +148,27 @@ describe('DLS - Visits Table', () => { cy.get('#details-panel').contains( 'Simple notice since view check over through there. Hotel provide available a air avoid beautiful technology.' ); - }); - - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); cy.get('[aria-label="Hide details"]').first().click(); cy.get('#details-panel').should('not.exist'); cy.get('[aria-label="Hide details"]').should('not.exist'); }); + + it('and then calculate file size when the value is 0', () => { + cy.intercept('**/getSize?*', '0'); + + // We need to wait for counts to finish, otherwise cypress + // might interact with the details panel too quickly and + // it re-renders during the test. + + cy.contains('[aria-rowindex="1"] [aria-colindex="3"]', '2').should( + 'exist' + ); + cy.get('[aria-label="Show details"]').first().click(); + + cy.contains('#calculate-size-btn', 'Calculate').should('exist').click(); + cy.contains('0 B', { timeout: 10000 }).should('be.visible'); + }); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/investigations.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/investigations.cy.ts index 40e31bcfb..4a046e913 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/investigations.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/investigations.cy.ts @@ -20,26 +20,6 @@ describe('Investigations Table', () => { cy.get('[aria-rowcount="59"]').should('exist'); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting, cypress/unsafe-to-chain-command - cy.get('[data-testid="investigation-table-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="investigation-table-title"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - it('should have the correct url for the DOI link', () => { cy.get('[data-testid="investigation-table-doi-link"]') .first() @@ -54,243 +34,140 @@ describe('Investigations Table', () => { }); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select and details column widths - columnWidth = (windowWidth - 40 - 40) / 8; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('titleColumn'); - cy.get('[role="columnheader"]').eq(3).as('visitColumn'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@visitColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - // eslint-disable-next-line cypress/unsafe-to-chain-command - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 200 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@visitColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - // eslint-disable-next-line cypress/unsafe-to-chain-command - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@visitColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - - describe('should be able to sort by', () => { - it('ascending order', () => { - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'A air avoid beautiful. Nature article your issue. Customer rather ' + - 'citizen bag boy late. Maybe big act produce challenge short.' - ); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Why news west bar sing tax. Drive up more near member article. Only ' + - 'remember free thousand interest. Ability ok upon condition ' + - 'ability. Hand statement despite probably song.' - ); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Analysis reflect work or hour color maybe. Much team discussion message weight.' - ); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Start Date').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Analysis reflect work or hour color maybe. Much team discussion message weight.' - ); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + // ascending order + cy.contains('[role="button"]', 'Title').as('titleSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'A air avoid beautiful. Nature article your issue. Customer rather ' + + 'citizen bag boy late. Maybe big act produce challenge short.' + ); + + // descending order + cy.get('@titleSortButton').click(); + + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Why news west bar sing tax. Drive up more near member article. Only ' + + 'remember free thousand interest. Ability ok upon condition ' + + 'ability. Hand statement despite probably song.' + ); + + // no order + cy.get('@titleSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Analysis reflect work or hour color maybe. Much team discussion message weight.' + ); + + // multiple columns + cy.contains('[role="button"]', 'Start Date').click(); + cy.get('@titleSortButton').click(); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Analysis reflect work or hour color maybe. Much team discussion message weight.' + ); }); - describe('should be able to filter by', () => { - it('exclude', () => { - cy.get('input[aria-label="Filter by Name"]') - .parent() - .find('[aria-label="include, exclude or exact"]') - .click(); - - cy.get('#select-filter-type-exclude').click(); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test exclude text filter + cy.get('input[aria-label="Filter by Name"]') + .as('nameFilter') + .parent() + .find('[aria-label="include, exclude or exact"]') + .as('nameFilterOptionsButton') + .click(); - cy.get('[aria-label="Filter by Name"]').first().type('INVESTIGATION 1'); + cy.get('#select-filter-type-exclude').click(); - cy.get('[aria-rowcount="48"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('87'); + cy.get('@nameFilter').type('INVESTIGATION 1'); - // check that size is correct after filtering - cy.get('[aria-rowindex="1"] [aria-colindex="7"]').contains('3.38 GB'); - }); + cy.get('[aria-rowcount="48"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('87'); - it('include', () => { - cy.get('input[aria-label="Filter by Name"]') - .parent() - .find('[aria-label="include, exclude or exact"]') - .click(); + // check that size is correct after filtering + cy.get('[aria-rowindex="1"] [aria-colindex="7"]').contains('3.38 GB'); - cy.get('#select-filter-type-include').click(); + // test exact text filter - cy.get('[aria-label="Filter by Name"]').first().type('INVESTIGATION 1'); + cy.get('@nameFilterOptionsButton').click(); - cy.get('[aria-rowcount="11"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('70'); + cy.get('#select-filter-type-exact').click(); - // check that size is correct after filtering - cy.get('[aria-rowindex="1"] [aria-colindex="7"]').contains('3.12 GB'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('70'); - it('exact', () => { - cy.get('input[aria-label="Filter by Name"]') - .parent() - .find('[aria-label="include, exclude or exact"]') - .click(); + // check that size is correct after filtering + cy.get('[aria-rowindex="1"] [aria-colindex="7"]').contains('3.12 GB'); - cy.get('#select-filter-type-exact').click(); + // test include text filter + cy.get('@nameFilterOptionsButton').click(); - cy.get('[aria-label="Filter by Name"]').first().type('INVESTIGATION 1'); + cy.get('#select-filter-type-include').click(); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('70'); + cy.get('[aria-rowcount="11"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('70'); - // check that size is correct after filtering - cy.get('[aria-rowindex="1"] [aria-colindex="7"]').contains('3.12 GB'); - }); + // check that size is correct after filtering + cy.get('[aria-rowindex="1"] [aria-colindex="7"]').contains('3.12 GB'); - it('date between', () => { - cy.get('input[id="Start Date filter from"]').type('2012-01-01'); + // test date filter + cy.get('input[id="Start Date filter from"]').type('2004-01-01'); - cy.get('input[aria-label="Start Date filter to"]') - .parent() - .find('button') - .click(); + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); - cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); - const date = new Date(); - date.setDate(1); + const date = new Date(); + date.setDate(1); - cy.get('input[id="Start Date filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); + cy.get('input[id="Start Date filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); - cy.get('[aria-rowcount="12"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Why news west bar sing tax. Drive up more near member article.' - ); - }); - - it('multiple columns', () => { - cy.get('[aria-label="Filter by Title"]').first().type('wide'); - - cy.get('[aria-label="Filter by Visit ID"]').first().type('7'); - - cy.get('[aria-rowcount="3"]').should('exist'); - }); + cy.get('[aria-rowcount="4"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('96'); }); - describe('should be able to view details', () => { - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(2).click(); - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); + cy.get('#details-panel').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); + const firstDetailsPanelText = + 'Prove begin boy those always dream write inside.'; - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(2).click(); + cy.get('[aria-label="Show details"]').first().click(); - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel') - .contains( - 'Strategy with piece reason late model air. Sound process international scene call deep answer. Teach financial vote season.' - ) - .should('be.visible'); - cy.get('#details-panel') - .contains( - 'Prove begin boy those always dream write inside. Cold drop season bill treat her wife. Nearly represent fire debate fish. Skin understand risk.' - ) - .should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); - - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel') + .contains('Strategy with piece reason late model air.') + .should('be.visible'); + cy.get('#details-panel') + .contains(firstDetailsPanelText) + .should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('[aria-label="Hide details"]').first().click(); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/dataPublications.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/dataPublications.cy.ts index f36e711b1..89b934715 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/dataPublications.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/dataPublications.cy.ts @@ -47,159 +47,105 @@ describe('ISIS - Data Publication Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - // Using Math.round to solve rounding errors when calculating 1000 / 3 - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - columnWidth = Math.round(windowWidth / 3); - columnWidth = Math.round((columnWidth * 100) / 100); - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(0).as('titleColumn'); - cy.get('[role="columnheader"]').eq(1).as('doiColumn'); - - cy.get('@titleColumn').should(($column) => { - let { width } = $column[0].getBoundingClientRect(); - width = Math.round((width * 100) / 100); - expect(width).to.equal(columnWidth); - }); - - cy.get('@doiColumn').should(($column) => { - let { width } = $column[0].getBoundingClientRect(); - width = Math.round((width * 100) / 100); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@doiColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 900 }) - .trigger('mouseup'); - - cy.get('@doiColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Publication Date') + .as('dateSortButton') + .click(); + + // ascending order + cy.contains('[role="button"]', 'Title').as('titleSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( + 'Article subject amount' + ); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Publication Date').click(); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( - 'Article subject amount' - ); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( - 'Daughter experience discussion' - ); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.be.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( - 'Article subject amount' - ); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Publication Date').click(); - cy.contains('[role="button"]', 'Publication Date').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( - 'Church child time Congress' - ); - }); - }); + // descending order + cy.get('@titleSortButton').click(); + + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( + 'Daughter experience discussion' + ); - describe('should be able to filter by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Publication Date').click(); - }); + // no order + cy.get('@titleSortButton').click(); - it('text', () => { - cy.get('[aria-label="Filter by Title"]').first().type('wat'); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.be.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( + 'Article subject amount' + ); - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( - 'Consider author watch' - ); - }); + // multiple columns + cy.get('@dateSortButton').click(); + cy.get('@dateSortButton').click(); + cy.get('@titleSortButton').click(); - it('date between', () => { - cy.get('input[id="Publication Date filter from"]').type('2014-04-02'); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( + 'Church child time Congress' + ); + }); - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="2"] [aria-colindex="1"]').contains( - 'Church child time Congress' - ); - }); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('[aria-label="Filter by Title"]').first().type('ne'); - it('multiple columns', () => { - cy.get('[aria-label="Filter by DOI"]').first().type('0'); + cy.get('[aria-rowcount="3"]').should('exist'); + + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( + 'Church child time Congress' + ); + + let toDate = '2016-01-01'; + let fromDate = '2014-01-01'; + // TODO: make this less scuffed when https://github.com/ral-facilities/datagateway-api/issues/444 is fixed + if (Cypress.env('CI')) { + // can get the below date by looking at the createTime of any datafiles on SG preprod + const sgPreprodGenerationDate = new Date('2023-03-28'); + // get rid of any timezone offset + sgPreprodGenerationDate.setHours(0); + const today = new Date(); + today.setHours(0); + today.setMinutes(0); + today.setSeconds(0); + today.setMilliseconds(0); + const diff = today.getTime() - sgPreprodGenerationDate.getTime(); + + const toDateDate = new Date(toDate); + toDateDate.setHours(0); + toDateDate.setTime(toDateDate.getTime() + diff); + toDate = toDateDate.toLocaleDateString('sv').split(' ')[0]; + + const fromDateDate = new Date(fromDate); + fromDateDate.setHours(0); + fromDateDate.setTime(fromDateDate.getTime() + diff); + fromDate = fromDateDate.toLocaleDateString('sv').split(' ')[0]; + } + + // test date filter + cy.get('input[id="Publication Date filter to"]').type(toDate); + + cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').contains( + 'Consider author watch' + ); - cy.get('[aria-label="Filter by Title"]').first().type('wat'); + cy.get('input[id="Publication Date filter from"]').type(fromDate); - cy.get('[aria-rowcount="1"]').should('exist'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/datafiles.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/datafiles.cy.ts index 79889479c..9a36b164d 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/datafiles.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/datafiles.cy.ts @@ -8,270 +8,152 @@ describe('ISIS - Datafiles Table', () => { cy.intercept('**/datafiles/count?*').as('datafilesCount'); cy.intercept('**/datafiles?order=*').as('datafilesOrder'); cy.login(); - }); - - describe('Wait for initial requests', () => { - beforeEach(() => { - cy.visit( - '/browse/instrument/1/facilityCycle/19/investigation/19/dataset/79/datafile' - ).wait( - [ - '@idCheck', - '@instrument', - '@facilityCycle', - '@investigation', - '@dataset', - '@datafilesCount', - '@datafilesOrder', - ], - { - timeout: 10000, - } - ); - }); - - it('should load correctly', () => { - cy.title().should('equal', 'DataGateway DataView'); - cy.get('#datagateway-dataview').should('be.visible'); - - //Default sort - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); - }); - - it('should not load incorrect URL', () => { - cy.visit( - '/browse/instrument/2/facilityCycle/14/investigation/88/dataset/118/datafile' - ); - - cy.contains('Oops!').should('be.visible'); - cy.get('[role="grid"]').should('not.exist'); - }); - - // Unable to test lazy loading as there are only 15 files per dataset - it.skip('should be able to scroll down and load more rows', () => { - cy.get('[aria-rowcount="50"]').should('exist'); - cy.get('[aria-label="grid"]').scrollTo('bottom'); - cy.get('[aria-rowcount="55"]').should('exist'); - }); - - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Modified Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/add/go/interview.png' - ); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Location') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - '/writer/me/expert.gif' - ); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Modified Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 78' - ); - }); - }); - - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Location"]').first().type('action'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 1268' - ); - }); - it('date between', () => { - cy.get('input[id="Modified Time filter from"]').type('2018-08-12'); - const date = new Date(); - cy.get('input[aria-label="Modified Time filter to"]').type( - date.toISOString().slice(0, 10) - ); - - cy.get('[aria-rowcount="15"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 1744' - ); - }); - - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]') - .first() - .type('5') - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-label="Filter by Location"]') - .first() - .type('.png') - .wait('@datafilesOrder', { timeout: 10000 }); - - cy.get('[aria-rowcount="3"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Datafile 1625' - ); - }); - }); - - describe('should be able to view details', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Modified Time') - .click() - .wait('@datafilesOrder', { timeout: 10000 }); - }); - - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('when another other row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); + cy.visit( + '/browse/instrument/1/facilityCycle/19/investigation/19/dataset/79/datafile' + ).wait( + [ + '@idCheck', + '@instrument', + '@facilityCycle', + '@investigation', + '@dataset', + '@datafilesCount', + '@datafilesOrder', + ], + { + timeout: 10000, + } + ); + }); - cy.get('[aria-label="Show details"]').first().click(); + it('should load correctly', () => { + cy.title().should('equal', 'DataGateway DataView'); + cy.get('#datagateway-dataview').should('be.visible'); - cy.get('#details-panel').contains('Datafile 78').should('be.visible'); - cy.get('#details-panel').contains('Datafile 197').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); + //Default sort + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('be.visible'); + }); - it('and view datafile details and parameters', () => { - cy.get('[aria-label="Show details"]').first().click(); + it('should not load incorrect URL', () => { + cy.visit( + '/browse/instrument/2/facilityCycle/14/investigation/88/dataset/118/datafile' + ); - cy.get('[aria-controls="datafile-details-panel"]').should('be.visible'); + cy.contains('Oops!').should('be.visible'); + cy.get('[role="grid"]').should('not.exist'); + }); - cy.get('#details-panel') - .contains( - 'Skill certain create left. Get onto back do door room mission. Business story growth economic.' - ) - .should('be.visible'); + // Unable to test lazy loading as there are only 15 files per dataset + it.skip('should be able to scroll down and load more rows', () => { + cy.get('[aria-rowcount="50"]').should('exist'); + cy.get('[aria-label="grid"]').scrollTo('bottom'); + cy.get('[aria-rowcount="55"]').should('exist'); + }); - cy.get('[aria-controls="datafile-parameters-panel"]').should( - 'be.visible' - ); - cy.get('[aria-controls="datafile-parameters-panel"]').click(); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Modified Time') + .as('timeSortButton') + .click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + // ascending order + cy.contains('[role="button"]', 'Location').as('locationSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/add/go/interview.png' + ); + + // descending order + cy.get('@locationSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/writer/me/expert.gif' + ); + + // no order + cy.get('@locationSortButton').click(); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + '/debate/form/growth.gif' + ); + + // multiple columns + cy.get('@timeSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + cy.get('@nameSortButton').click(); + cy.wait('@datafilesOrder', { timeout: 10000 }); + + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 78'); + }); - cy.get('#parameter-grid').should('be.visible'); - }); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test date filter + cy.get('input[aria-label="Modified Time filter from"]').type('2018-08-12'); + const date = new Date(); + cy.get('input[aria-label="Modified Time filter to"]').type( + date.toISOString().slice(0, 10) + ); - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('[aria-rowcount="15"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1744'); - cy.get('[aria-label="Hide details"]').first().click(); + // test text filter + cy.get('[aria-label="Filter by Location"]').first().type('action'); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1268'); }); - describe('Do not wait for initial requests', () => { - beforeEach(() => { - cy.visit( - '/browse/instrument/1/facilityCycle/19/investigation/19/dataset/79/datafile' - ); - }); - - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select, details and actions column widths - columnWidth = (windowWidth - 40 - 40 - 96) / 4; - }) - .then(() => expect(columnWidth).to.not.equal(0)); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); - cy.get('[role="columnheader"]').eq(2).as('nameColumn'); - cy.get('[role="columnheader"]').eq(3).as('locationColumn'); + cy.get('#details-panel').should('be.visible'); + cy.get('#details-panel').contains('Datafile 1625').should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); + cy.get('[aria-label="Show details"]').first().click(); - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); + cy.get('#details-panel').contains('Datafile 1744').should('be.visible'); + cy.get('#details-panel').contains('Datafile 1625').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); + cy.get('[aria-controls="datafile-details-panel"]').should('be.visible'); - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); + cy.get('#details-panel') + .contains('Doctor involve recently treat') + .should('be.visible'); - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); + cy.get('[aria-controls="datafile-parameters-panel"]').should('be.visible'); + cy.get('[aria-controls="datafile-parameters-panel"]').click(); - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); + cy.get('#parameter-grid').should('be.visible'); + cy.get('#details-panel').contains('PARAMETERTYPE 11').should('be.visible'); - cy.get('@locationColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/datasets.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/datasets.cy.ts index d2eeb8c3e..bdd38ce5f 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/datasets.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/datasets.cy.ts @@ -48,199 +48,97 @@ describe('ISIS - Datasets Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select, details and actions column widths - columnWidth = (windowWidth - 40 - 40 - 70) / 4; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('nameColumn'); - cy.get('[role="columnheader"]').eq(3).as('sizeColumn'); - - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Create Time').as('timeSortButton').click(); + cy.wait('@datasetsOrder', { timeout: 10000 }); - cy.get('@sizeColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); + // ascending order + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.wait('@datasetsOrder', { timeout: 10000 }); - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 19'); - cy.get('@nameColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); + // descending order + cy.get('@nameSortButton').click(); + cy.wait('@datasetsOrder', { timeout: 10000 }); - cy.get('@sizeColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 79'); + + // no order + cy.get('@nameSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 19'); - cy.get('@sizeColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); + // multiple columns + cy.get('@timeSortButton').click(); + cy.wait('@datasetsOrder', { timeout: 10000 }); + cy.get('@nameSortButton').click(); + cy.wait('@datasetsOrder', { timeout: 10000 }); - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 19'); }); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - }); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('[aria-label="Filter by Name"]').first().type('79'); - it('ascending order', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 79'); + // check that size is correct after filtering + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('1.36 GB'); - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 19'); - }); + // test date filter + cy.get('input[id="Create Time filter from"]').type('2005-06-12'); - it('descending order', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 79'); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 19'); - }); - - it('multiple columns', () => { - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Create Time') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - cy.contains('[role="button"]', 'Name') - .click() - .wait('@datasetsOrder', { timeout: 10000 }); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 79'); - }); - }); - - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Name"]').first().type('DATASET 79'); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 79'); - // check that size is correct after filtering - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('1.36 GB'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); - it('date between', () => { - cy.get('input[id="Create Time filter from"]').type('2005-06-12'); + cy.get('input[aria-label="Create Time filter to"]') + .parent() + .find('button') + .click(); - const date = new Date(); - cy.get('input[aria-label="Create Time filter to"]').type( - date.toISOString().slice(0, 10) - ); + const date = new Date(); + date.setDate(1); + date.setFullYear(2020); - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 79'); - }); + cy.get('.MuiPickersCalendarHeader-label').click(); + cy.contains('2020').click(); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]') - .first() - .type('19') - .wait(['@datasetsCount', '@datasetsOrder'], { timeout: 10000 }); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); - const date = new Date(); - cy.get('input[id="Create Time filter to"]') - .type(date.toISOString().slice(0, 10)) - .wait(['@datasetsCount', '@datasetsOrder'], { timeout: 10000 }); - - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('DATASET 19'); - }); + cy.get('[aria-rowcount="0"]').should('exist'); }); describe('should be able to view details', () => { - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); + it('and all the details are correct & also able to hide the panel', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); cy.get('#details-panel').should('be.visible'); cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('when another other row is showing details', () => { - cy.get('[aria-label="Show details"]').eq(1).click(); + cy.get('#details-panel').contains('DATASET 19').should('be.visible'); cy.get('[aria-label="Show details"]').first().click(); cy.get('#details-panel').contains('DATASET 79').should('be.visible'); cy.get('#details-panel').contains('DATASET 19').should('not.exist'); cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); - - it('and view dataset details and type', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-controls="dataset-details-panel"]').should('be.visible'); cy.get('#details-panel') .contains( @@ -256,6 +154,11 @@ describe('ISIS - Datasets Table', () => { 'Stop prove field onto think suffer measure. Table lose season identify professor happen third simply.' ) .should('be.visible'); + + cy.get('[aria-label="Hide details"]').first().click(); + + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); it('and view datafiles', () => { @@ -267,14 +170,5 @@ describe('ISIS - Datasets Table', () => { '/browse/instrument/1/facilityCycle/19/investigation/19/dataset/79/datafile' ); }); - - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-label="Hide details"]').first().click(); - - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/facilityCycles.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/facilityCycles.cy.ts index 2e25e24f8..9ec657116 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/facilityCycles.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/facilityCycles.cy.ts @@ -28,162 +28,76 @@ describe('ISIS - FacilityCycles Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - // Using Math.round to solve rounding errors when calculating 1000 / 3 - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - columnWidth = Math.round(windowWidth / 3); - columnWidth = Math.round((columnWidth * 100) / 100); - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(0).as('titleColumn'); - cy.get('[role="columnheader"]').eq(1).as('startDateColumn'); - - // Filtering results to remove vertical scroll bar affecting width calculations - cy.get('[aria-label="Filter by Name"]').first().type('2004'); - - cy.get('@titleColumn').should(($column) => { - let { width } = $column[0].getBoundingClientRect(); - width = Math.round((width * 100) / 100); - expect(width).to.equal(columnWidth); - }); - - cy.get('@startDateColumn').should(($column) => { - let { width } = $column[0].getBoundingClientRect(); - width = Math.round((width * 100) / 100); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@startDateColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // Table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 1000 }) - .trigger('mouseup'); - - cy.get('@startDateColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); - - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Start Date').click(); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date').click(); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - '2001-04-02 00:00:00' - ); - }); - - it('descending order', () => { - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - '2004-06-03 00:00:00' - ); - }); - - it('no order', () => { - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - '2001-04-02 00:00:00' - ); - }); - }); + // ascending order + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + '2001-04-02 00:00:00' + ); - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Name"]').first().type('4'); + // descending order + cy.get('@nameSortButton').click(); + + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + '2004-06-03 00:00:00' + ); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - '2004-06-03 00:00:00' - ); - }); + // no order + cy.get('@nameSortButton').click(); - it('date between', () => { - cy.get('input[id="Start Date filter from"]').type('2002-06-01'); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + '2001-04-02 00:00:00' + ); + }); - cy.get('input[aria-label="Start Date filter to"]') - .parent() - .find('button') - .click(); + it('should be able to filter with both text & date filters on multiple columns', () => { + cy.get('[aria-label="Filter by Name"]').first().type('3'); - cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + '2004-06-03 00:00:00' + ); - const date = new Date(); - date.setDate(1); + cy.get('input[id="Start Date filter from"]').type('2004-06-01'); - cy.get('input[id="Start Date filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - '2004-06-03 00:00:00' - ); - }); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Name"]').first().type('3'); + const date = new Date(); + date.setDate(1); - cy.get('input[id="Start Date filter from"]').type('2004-06-01'); + cy.get('input[id="Start Date filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); - cy.get('[aria-rowcount="1"]').should('exist'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + '2004-06-03 00:00:00' + ); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/instruments.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/instruments.cy.ts index c23274f01..7ea36932d 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/instruments.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/instruments.cy.ts @@ -30,157 +30,103 @@ describe('ISIS - Instruments Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="isis-instrument-table-name"]') - .eq(2) - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="isis-instrument-table-name"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + //Revert the default sort + cy.contains('[role="button"]', 'Name').as('nameSortButton').click(); + cy.get('@nameSortButton').click(); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Name').click().click(); - }); + // ascending order + cy.get('@nameSortButton').click(); - it('ascending order', () => { - cy.contains('[role="button"]', 'Name').click(); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Eight imagine picture tough.' + ); - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Eight imagine picture tough. Mouth participant chance including. Receive environment Democrat happy like full paper. School oil later change.' - ); - }); + // descending order + cy.get('@nameSortButton').click(); - it('descending order', () => { - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Whether number computer economy design now serious appear. Response girl middle close role American.' - ); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Whether number computer economy design now serious appear.' + ); - it('no order', () => { - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - cy.contains('[role="button"]', 'Name').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Stop prove field onto think suffer measure. Table lose season identify professor happen third simply.' - ); - }); + // no order + cy.get('@nameSortButton').click(); + + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Stop prove field onto think suffer measure.' + ); }); - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Name"]').first().type('space'); + it('should be able to filter with text filter on multiple columns', () => { + cy.get('[aria-label="Filter by Type"]').first().type('4'); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Space I environmental. Role again act seek. Light teacher big sing foreign meeting professor. Simply world start floor.' - ); - }); + cy.get('[aria-rowcount="2"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Space I environmental.' + ); + cy.get('[aria-rowindex="2"] [aria-colindex="2"]').contains( + 'Up election edge his not add.' + ); - it('type', () => { - cy.get('[aria-label="Filter by Type"]').first().type('4'); + cy.get('[aria-label="Filter by Name"]').first().type('space'); - cy.get('[aria-rowcount="2"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( - 'Space I environmental. Role again act seek. Light teacher big sing foreign meeting professor. Simply world start floor.' - ); - cy.get('[aria-rowindex="2"] [aria-colindex="2"]').contains( - 'Up election edge his not add. Where difficult audience often. Cup investment the officer network hospital cultural personal.' - ); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="2"]').contains( + 'Space I environmental.' + ); }); - describe('should be able to view details', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Name').click().click(); - }); + it('should be able to view details', () => { + cy.get('[aria-label="Show details"]').eq(1).click(); - it('when no other row is showing details', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel').should('be.visible'); + const firstDetailsPanelText = 'General attorney city month.'; + cy.get('#details-panel') + .contains(firstDetailsPanelText) + .should('be.visible'); + cy.get('[aria-label="Hide details"]').should('exist'); - cy.get('#details-panel').should('be.visible'); - cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('when another row is showing details', () => { - cy.get('[aria-label="Show details"]') - .eq(2) - .click({ scrollBehavior: 'center' }); - - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('#details-panel') - .contains( - 'Suggest shake effort many last prepare small. Maintain throw hope parent.' - ) - .should('be.visible'); - cy.get('#details-panel') - .contains( - 'Financial vote season indicate. Candidate night sure opportunity design. Commercial test wind region meeting her get.' - ) - .should('not.exist'); - cy.get('[aria-label="Hide details"]').should('have.length', 1); - }); + cy.get('[aria-label="Show details"]').first().click(); - it('and view instrument details and scientists', () => { - cy.get('[aria-label="Show details"]').first().click(); + cy.get('#details-panel') + .contains('Eight imagine picture tough') + .should('be.visible'); + cy.get('#details-panel') + .contains(firstDetailsPanelText) + .should('not.exist'); + cy.get('[aria-label="Hide details"]').should('have.length', 1); - cy.get('[aria-controls="instrument-details-panel').should('be.visible'); + cy.get('[aria-controls="instrument-details-panel').should('be.visible'); - cy.get('#details-panel') - .contains( - 'Stop prove field onto think suffer measure. Table lose season identify professor happen third simply. Beat professional blue clear style have. Analysis reflect work or hour color maybe.' - ) - .should('be.visible'); + cy.get('#details-panel') + .contains('Skill quality beautiful.') + .should('be.visible'); - cy.get('[aria-controls="instrument-users-panel"]').should('be.visible'); - cy.get('[aria-controls="instrument-users-panel"]').click({ - scrollBehavior: 'center', - }); - cy.get('#details-panel').contains('Kathryn Fox').should('be.visible'); + cy.get('[aria-controls="instrument-users-panel"]').should('be.visible'); + cy.get('[aria-controls="instrument-users-panel"]').click({ + scrollBehavior: 'center', }); + cy.get('#details-panel').contains('Kim Ramirez').should('be.visible'); - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-label="Hide details"]').first().click(); + cy.get('[aria-label="Hide details"]').first().click(); - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/investigations.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/investigations.cy.ts index 7d96ed8c6..1ba9ec19c 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/investigations.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/investigations.cy.ts @@ -45,26 +45,6 @@ describe('ISIS - Investigations Table', () => { }); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="isis-investigations-table-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="isis-investigations-table-title"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - // Not enough investigations to test scrolling. it.skip('should be able to scroll down and load more rows', () => { cy.get('[aria-rowcount="50"]').should('exist'); @@ -72,180 +52,96 @@ describe('ISIS - Investigations Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - // Using Math.floor to solve rounding errors when calculating (1000 - 40 - 40) / 7 - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select and details column widths - columnWidth = (windowWidth - 40 - 40 - 70) / 7; - columnWidth = Math.floor(columnWidth * 10) / 10; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('titleColumn'); - cy.get('[role="columnheader"]').eq(3).as('visitColumn'); - - cy.get('@titleColumn').should(($column) => { - let { width } = $column[0].getBoundingClientRect(); - width = Math.floor(width * 10) / 10; - expect(width).to.equal(columnWidth); - }); - - cy.get('@visitColumn').should(($column) => { - let { width } = $column[0].getBoundingClientRect(); - width = Math.floor(width * 10) / 10; - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 200 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@visitColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); - - // table width should grow if a column grows too large - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@visitColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); + // only 1 investigation, so sort test kind of pointless + it.skip('should be able to sort by all sort directions on single and multiple columns', () => { + // Revert the default sort + cy.contains('[role="button"]', 'Start Date').as('dateSortButton').click(); - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); + // ascending order + cy.contains('[role="button"]', 'Title').as('titleSortButton').click(); - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date').click(); - }); - - it('ascending order', () => { - cy.contains('[role="button"]', 'Title').click(); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + // descending order + cy.get('@titleSortButton').click(); - it('descending order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + // no order + cy.get('@titleSortButton').click(); - it('no order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); - it('multiple columns', () => { - cy.contains('[role="button"]', 'Start Date').click(); - cy.contains('[role="button"]', 'Title').click(); + cy.get('@dateSortButton').click(); + cy.get('@titleSortButton').click(); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); }); - describe('should be able to filter by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Title"]').first().type('stop'); + it('should be able to filter with both text & date filters on multiple columns', () => { + // test text filter + cy.get('[aria-label="Filter by Title"]').first().type('stop'); - cy.get('[role="progressbar"]').should('be.visible'); - cy.get('[role="progressbar"]').should('not.exist'); + cy.wait('@getInvestigationsOrder'); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( - 'INVESTIGATION 31' - ); - // check that size is correct after filtering - cy.get('[aria-rowindex="1"] [aria-colindex="6"]').contains('3.31 GB'); - }); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains( + 'INVESTIGATION 31' + ); + // check that size is correct after filtering + cy.get('[aria-rowindex="1"] [aria-colindex="6"]').contains('3.31 GB'); - it('date between', () => { - cy.get('input[id="Start Date filter from"]').type('2007-09-01'); + cy.get('input[id="Start Date filter from"]').type('2007-01-01'); - cy.get('input[aria-label="Start Date filter to"]') - .parent() - .find('button') - .click(); + cy.wait('@getInvestigationsOrder'); - cy.get('.MuiPickersDay-root[type="button"]').first().click(); + cy.get('[aria-rowcount="1"]').should('exist'); - const date = new Date(); - date.setDate(1); + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); - cy.get('input[id="Start Date filter to"]').should( - 'have.value', - date.toISOString().slice(0, 10) - ); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); - cy.get('[aria-rowcount="1"]').should('not.exist'); - cy.contains('Stop system investment').should('not.exist'); - }); + const date = new Date(); + date.setDate(1); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Title"]').first().type('fill'); + cy.get('input[id="Start Date filter to"]').should( + 'have.value', + date.toISOString().slice(0, 10) + ); - cy.get('[aria-rowcount="1"]').should('exist'); - }); + cy.get('[aria-rowcount="0"]').should('exist'); + cy.contains('Stop system investment').should('not.exist'); }); describe('should be able to view details', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date').click(); - }); - - it('when not other row is showing details', () => { + it('and all the details are correct & also able to hide the panel', () => { cy.get('[aria-label="Show details"]').first().click(); // DataPublication PID @@ -278,37 +174,22 @@ describe('ISIS - Investigations Table', () => { cy.get('#details-panel').should('be.visible'); cy.get('[aria-label="Hide details"]').should('exist'); - }); - - // Cannot test showing details when another row is showing details - // as well since we are currently limited to 1 investigation to test. - - it('and view investigation details, users, samples and publications', () => { - cy.get('[aria-label="Show details"]').first().click(); cy.get('[aria-controls="investigation-details-panel"]').should( 'be.visible' ); - // Waits needed due to suspected race condition on fetching the panels - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('#details-panel') .contains('Stop system investment') - .should('be.visible') - .wait(200); + .should('be.visible'); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[aria-controls="investigation-users-panel"]') - .should('be.visible') - .wait(200); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[aria-controls="investigation-users-panel"]').wait(200).click(); + cy.get('[aria-controls="investigation-users-panel"]').should( + 'be.visible' + ); - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('#details-panel') - .contains('Dustin Hall') - .should('be.visible') - .wait(200); + cy.get('[aria-controls="investigation-users-panel"]').click(); + + cy.get('#details-panel').contains('Dustin Hall').should('be.visible'); cy.get('[aria-controls="investigation-samples-panel"]').should( 'be.visible' @@ -325,6 +206,11 @@ describe('ISIS - Investigations Table', () => { cy.get('#details-panel') .contains('Pressure meeting would year but energy.') .should('be.visible'); + + cy.get('[aria-label="Hide details"]').first().click(); + + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); it('and view datasets', () => { @@ -336,14 +222,5 @@ describe('ISIS - Investigations Table', () => { '/browse/instrument/13/facilityCycle/12/investigation/31/dataset' ); }); - - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-label="Hide details"]').first().click(); - - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/isis/myData.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/isis/myData.cy.ts index 82534dc4c..e4b2e6923 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/isis/myData.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/isis/myData.cy.ts @@ -35,26 +35,6 @@ describe('ISIS - MyData Table', () => { cy.get('.MuiTableSortLabel-iconDirectionDesc').should('exist'); }); - it('should disable the hover tool tip by pressing escape', () => { - // The hover tool tip has a enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="isis-mydata-table-title"]') - .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); - - cy.get('body').type('{esc}'); - - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.get('[data-testid="isis-mydata-table-title"]') - .wait(700) - .first() - .get('[role="tooltip"]') - .should('not.exist'); - }); - it('should be able to click an investigation to see its landing page', () => { cy.get('[role="gridcell"] a').first().click({ force: true }); cy.location('pathname').should( @@ -84,176 +64,112 @@ describe('ISIS - MyData Table', () => { cy.get('[aria-rowcount="75"]').should('exist'); }); - it('should be able to resize a column', () => { - let columnWidth = 0; - - cy.window() - .then((window) => { - const windowWidth = window.innerWidth; - // Account for select and details column widths - columnWidth = (windowWidth - 40 - 40) / 8; - }) - .then(() => expect(columnWidth).to.not.equal(0)); - - cy.get('[role="columnheader"]').eq(2).as('titleColumn'); - cy.get('[role="columnheader"]').eq(3).as('doiColumn'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('@doiColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.equal(columnWidth); - }); - - cy.get('.react-draggable') - .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 200 }) - .trigger('mouseup'); - - cy.get('@titleColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.greaterThan(columnWidth); - }); - - cy.get('@doiColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.lessThan(columnWidth); - }); + // only 1 investigation, so sort test kind of pointless + it.skip('should be able to sort by all sort directions on single and multiple columns', () => { + // Revert the default sort + cy.contains('[role="button"]', 'Start Date').click(); - // table width should grow if a column grows too large - cy.get('.react-draggable') + // ascending order + cy.contains('[role="button"]', 'Title') + .as('titleSortButton') .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 800 }) - .trigger('mouseup'); - - cy.get('@doiColumn').should(($column) => { - const { width } = $column[0].getBoundingClientRect(); - expect(width).to.be.equal(84); - }); + .click(); - cy.get('[aria-label="grid"]').then(($grid) => { - const { width } = $grid[0].getBoundingClientRect(); - cy.window().should(($window) => { - expect(width).to.be.greaterThan($window.innerWidth); - }); - }); - }); - - describe('should be able to sort by', () => { - beforeEach(() => { - //Revert the default sort - cy.contains('[role="button"]', 'Start Date').click(); - }); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); - it('ascending order', () => { - cy.contains('[role="button"]', 'Title').first().click(); + // descending order + cy.get('@titleSortButton').click(); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + // no order + cy.get('@titleSortButton').click(); - it('descending order', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Title').click(); - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); - - it('no order', () => { - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('[aria-sort="descending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('[aria-sort="descending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); - it('multiple columns', () => { - cy.contains('[role="button"]', 'Title').click(); - cy.contains('[role="button"]', 'Instrument').click(); + // multiple columns + cy.get('@titleSortButton').click(); + cy.contains('[role="button"]', 'Instrument').click(); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( - 'Stop system investment' - ); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains( + 'Stop system investment' + ); }); - describe('should be able to filter by', () => { - it('role', () => { - cy.get('[aria-rowcount="1"]').should('exist'); + it('should be able to filter with role, text & date filters on multiple columns', () => { + // role selector + cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('#role-selector').click(); - cy.get('[role="listbox"]') - .find('[role="option"]') - .should('have.length', 2); - cy.get('[role="option"][data-value="CI"]').click(); + cy.get('#role-selector').click(); + cy.get('[role="listbox"]') + .find('[role="option"]') + .should('have.length', 2); + cy.get('[role="option"][data-value="CI"]').click(); - cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[role="progressbar"]').should('be.visible'); + cy.get('[role="progressbar"]').should('not.exist'); - // check that size is correct after filtering - cy.get('[aria-rowindex="1"] [aria-colindex="8"]').contains('3.31 GB'); + cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('#role-selector').click(); - cy.get('[role="option"]').first().click(); - cy.get('[aria-rowcount="1"]').should('exist'); - }); + // check that size is correct after filtering + cy.get('[aria-rowindex="1"] [aria-colindex="8"]').contains('3.31 GB'); - it('text', () => { - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('input[id="Title-filter"]').type('color'); + cy.get('#role-selector').click(); + cy.get('[role="option"]').first().click(); - cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="6"]').contains( - 'INVESTIGATION 31' - ); - }); + cy.get('[aria-rowcount="1"]').should('exist'); - it('date between', () => { - cy.get('[aria-rowcount="1"]').should('exist'); + // text filter + cy.get('[aria-label="Filter by Title"]').type('stop'); - const date = new Date(); + cy.get('[role="progressbar"]').should('be.visible'); + cy.get('[role="progressbar"]').should('not.exist'); - cy.get('input[aria-label="Start Date filter to"]').type( - date.toISOString().slice(0, 10) - ); + cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[aria-rowindex="1"] [aria-colindex="6"]').contains( + 'INVESTIGATION 31' + ); - cy.get('input[id="Start Date filter from"]').type('2007-08-01'); - cy.get('[aria-rowcount="1"]').should('exist'); - }); + cy.get('input[aria-label="Start Date filter to"]') + .parent() + .find('button') + .click(); - it('multiple columns', () => { - cy.get('[aria-label="Filter by DOI"]').first().type('76'); + cy.get('.MuiPickersDay-root[type="button"]').first().click(); - cy.get('[aria-rowcount="1"]').should('exist'); + cy.get('[role="progressbar"]').should('be.visible'); + cy.get('[role="progressbar"]').should('not.exist'); - cy.get('[aria-label="Filter by Title"]').first().type('or'); + cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowcount="1"]').should('exist'); - }); + cy.get('input[aria-label="Start Date filter from"]').type('2008-01-01'); + + cy.get('[aria-rowcount="0"]').should('exist'); }); describe('should be able to view details', () => { - it('when no other row is showing details', () => { + it('and all the details are correct & also able to hide the panel', () => { cy.get('[aria-label="Show details"]').first().click(); // DataPublication PID @@ -286,10 +202,6 @@ describe('ISIS - MyData Table', () => { cy.get('#details-panel').should('be.visible'); cy.get('[aria-label="Hide details"]').should('exist'); - }); - - it('and view investigation details, users, samples and publications', () => { - cy.get('[aria-label="Show details"]').first().click(); cy.get('[aria-controls="investigation-details-panel"]').should( 'be.visible' @@ -321,6 +233,11 @@ describe('ISIS - MyData Table', () => { cy.get('#details-panel') .contains('Pressure meeting would year but energy.') .should('be.visible'); + + cy.get('[aria-label="Hide details"]').first().click(); + + cy.get('#details-panel').should('not.exist'); + cy.get('[aria-label="Hide details"]').should('not.exist'); }); it('and view datasets', () => { @@ -332,15 +249,6 @@ describe('ISIS - MyData Table', () => { '/browse/instrument/13/facilityCycle/12/investigation/31/dataset' ); }); - - it('and then not view details anymore', () => { - cy.get('[aria-label="Show details"]').first().click(); - - cy.get('[aria-label="Hide details"]').first().click(); - - cy.get('#details-panel').should('not.exist'); - cy.get('[aria-label="Hide details"]').should('not.exist'); - }); }); }); }); diff --git a/packages/datagateway-dataview/cypress/e2e/table/pageContainer.cy.ts b/packages/datagateway-dataview/cypress/e2e/table/pageContainer.cy.ts index 2927113fd..b81a0f81d 100644 --- a/packages/datagateway-dataview/cypress/e2e/table/pageContainer.cy.ts +++ b/packages/datagateway-dataview/cypress/e2e/table/pageContainer.cy.ts @@ -18,10 +18,6 @@ describe('PageContainer Component', () => { cy.clearDownloadCart(); }); - it('should display the open data warning when not logged in', () => { - cy.get('[aria-label="open-data-warning"]').should('exist'); - }); - it('should be able to click clear filters button to clear filters', () => { cy.url().then((url) => { cy.get('input[id="Title-filter"]').type('South'); @@ -37,6 +33,9 @@ describe('PageContainer Component', () => { it('should load correctly', () => { cy.title().should('equal', 'DataGateway DataView'); + // we're not logged in, so show open data warning + cy.get('[aria-label="open-data-warning"]').should('exist'); + cy.get('[aria-label="page-breadcrumbs"]').should('exist'); cy.get('[aria-label="view-count"]').should('exist'); @@ -46,9 +45,7 @@ describe('PageContainer Component', () => { cy.get('[aria-label="Go to selections"]').should('exist'); cy.get('[aria-label="page view Display as cards"]').should('exist'); - }); - it('should display correct entity count', () => { // Check that the entity count has displayed correctly. cy.get('[aria-label="view-count"]') .should('be.visible') @@ -103,18 +100,81 @@ describe('PageContainer Component', () => { ); }); - it('should display tooltips correctly', () => { - // The hover tool tip has an enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting + // test any table.component.tsx functionality here + // instead of any of the specs for instantiated tables + it('should be able to resize a column', () => { + let columnWidth = 0; + + cy.window() + .then((window) => { + const windowWidth = window.innerWidth; + // Account for select and details column widths + columnWidth = (windowWidth - 40 - 40) / 8; + }) + .then(() => expect(columnWidth).to.not.equal(0)); + + cy.get('[role="columnheader"]').eq(2).as('titleColumn'); + cy.get('[role="columnheader"]').eq(3).as('visitColumn'); + + cy.get('@titleColumn').should(($column) => { + const { width } = $column[0].getBoundingClientRect(); + expect(width).to.equal(columnWidth); + }); + + cy.get('@visitColumn').should(($column) => { + const { width } = $column[0].getBoundingClientRect(); + expect(width).to.equal(columnWidth); + }); + + cy.get('.react-draggable') + .first() + .as('firstColumnDragHandler') + .trigger('mousedown'); + cy.get('@firstColumnDragHandler').trigger('mousemove', { clientX: 200 }); + cy.get('@firstColumnDragHandler').trigger('mouseup'); + + cy.get('@titleColumn').should(($column) => { + const { width } = $column[0].getBoundingClientRect(); + expect(width).to.be.greaterThan(columnWidth); + }); + + cy.get('@visitColumn').should(($column) => { + const { width } = $column[0].getBoundingClientRect(); + expect(width).to.be.lessThan(columnWidth); + }); + + // table width should grow if a column grows too large + + cy.get('@firstColumnDragHandler').trigger('mousedown'); + cy.get('@firstColumnDragHandler').trigger('mousemove', { clientX: 800 }); + cy.get('@firstColumnDragHandler').trigger('mouseup'); + + cy.get('@visitColumn').should(($column) => { + const { width } = $column[0].getBoundingClientRect(); + expect(width).to.be.equal(84); + }); + + cy.get('[aria-label="grid"]').then(($grid) => { + const { width } = $grid[0].getBoundingClientRect(); + cy.window().should(($window) => { + expect(width).to.be.greaterThan($window.innerWidth); + }); + }); + }); + + it('should display table tooltips correctly (and be dismissable by pressing esc)', () => { cy.get('[data-testid="investigation-table-title"]') .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('exist'); + .as('firstTitle') + .trigger('mouseover', { force: true }); + cy.get('@firstTitle').get('[role="tooltip"]').should('exist'); + + cy.get('body').type('{esc}'); + + cy.get('@firstTitle').get('[role="tooltip"]').should('not.exist'); }); - it('should not display tooltips after column resizing', () => { + it('should not table display tooltips after column resizing', () => { let columnWidth = 0; cy.window() @@ -134,34 +194,31 @@ describe('PageContainer Component', () => { cy.get('.react-draggable') .first() - .trigger('mousedown') - .trigger('mousemove', { clientX: 1500 }) - .trigger('mouseup'); + .as('firstColumnDragHandler') + .trigger('mousedown'); + cy.get('@firstColumnDragHandler').trigger('mousemove', { clientX: 1500 }); + cy.get('@firstColumnDragHandler').trigger('mouseup'); cy.get('@titleColumn').should(($column) => { const { width } = $column[0].getBoundingClientRect(); expect(width).to.be.greaterThan(columnWidth); }); - // The hover tool tip has an enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting cy.get('[data-testid="investigation-table-title"]') .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('not.exist'); + .as('firstTitle') + .trigger('mouseover', { force: true }); + cy.get('@firstTitle').get('[role="tooltip"]').should('not.exist'); }); - it('should not display tooltips after making the window bigger', () => { + it('should not display table tooltips after making the window bigger', () => { cy.viewport(10000, 750); - // The hover tool tip has an enter delay of 500ms. - // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.get('[data-testid="investigation-table-title"]') .first() - .trigger('mouseover', { force: true }) - .wait(700) - .get('[role="tooltip"]') - .should('not.exist'); + .as('firstTitle') + .trigger('mouseover', { force: true }); + + cy.get('@firstTitle').get('[role="tooltip"]').should('not.exist'); }); }); diff --git a/packages/datagateway-dataview/package.json b/packages/datagateway-dataview/package.json index 45cdd8ed5..a4178b43d 100644 --- a/packages/datagateway-dataview/package.json +++ b/packages/datagateway-dataview/package.json @@ -66,7 +66,7 @@ "e2e": "start-server-and-test e2e:serve http://localhost:3000 cy:run", "cy:open": "cypress open", "cy:run": "cypress run", - "lint:js": "eslint --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src && yarn build", + "lint:js": "eslint --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src ./cypress && yarn build", "eject": "react-scripts eject", "pre-commit": "lint-staged" }, @@ -104,6 +104,7 @@ ] }, "devDependencies": { + "@babel/eslint-parser": "7.22.5", "@testing-library/jest-dom": "5.16.5", "@testing-library/react": "12.1.3", "@testing-library/react-hooks": "8.0.1", @@ -113,7 +114,6 @@ "@typescript-eslint/eslint-plugin": "5.61.0", "@typescript-eslint/parser": "5.61.0", "@welldone-software/why-did-you-render": "7.0.1", - "@babel/eslint-parser": "7.22.5", "blob-polyfill": "7.0.20220408", "cross-env": "7.0.3", "cypress": "11.2.0", diff --git a/packages/datagateway-download/cypress/e2e/adminDownloadStatus.cy.ts b/packages/datagateway-download/cypress/e2e/adminDownloadStatus.cy.ts index b0321b978..e59734e2f 100644 --- a/packages/datagateway-download/cypress/e2e/adminDownloadStatus.cy.ts +++ b/packages/datagateway-download/cypress/e2e/adminDownloadStatus.cy.ts @@ -1,14 +1,10 @@ describe('Admin Download Status', () => { - before(() => { - // Ensure the downloads are cleared before running tests. - cy.login({ username: 'root', password: 'pw', mechanism: 'simple' }); - - // Seed the initial downloads. - cy.clearDownloads(); - }); - beforeEach(() => { - cy.intercept('GET', '**/getPercentageComplete**'); + // set the viewport larger so all columns display nicely + // and sort indicators aren't covered + cy.viewport(1920, 1080); + + cy.intercept('GET', '**/getPercentageComplete**', '100'); cy.intercept('GET', '**/topcat/admin/downloads**').as( 'fetchAdminDownloads' ); @@ -25,11 +21,6 @@ describe('Admin Download Status', () => { }); }); - it('should load correctly and display admin download status table', () => { - cy.title().should('equal', 'DataGateway Download'); - cy.get('#datagateway-download').should('be.visible'); - }); - it('should refresh the table when clicking the refresh downloads button', () => { cy.get('[aria-label="Refresh download status table"]').should('exist'); @@ -52,177 +43,103 @@ 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') - .trigger('mousemove', { clientX: 600 }) - .trigger('mouseup'); - cy.contains('[role="button"]', 'Access Method').click(); - - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( - 'have.text', - 'globus' - ); - }); + it('should be able to sort by all sort directions on single and multiple columns', () => { + // remove default sort + cy.contains('[role="button"]', 'Requested Date').click(); - 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') - .trigger('mousemove', { clientX: 600 }) - .trigger('mouseup'); - cy.contains('[role="button"]', 'Access Method').click(); - cy.contains('[role="button"]', 'Access Method').click(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( - 'have.text', - 'https' - ); - }); + // ascending order + cy.contains('[role="button"]', 'Access Method') + .as('accessMethodSortButton') + .click(); - 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') - .trigger('mousemove', { clientX: 500 }) - .trigger('mouseup'); - cy.contains('[role="button"]', 'Prepared ID').click(); - cy.contains('[role="button"]', 'Prepared ID').click(); - cy.contains('[role="button"]', 'Prepared ID').click(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').should( - ($preparedId) => { - expect($preparedId[0].textContent).match( - /[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}/ - ); - } - ); - }); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( + 'have.text', + 'globus' + ); - 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') - .trigger('mousemove', { clientX: 550 }) - .trigger('mouseup'); - cy.contains('[role="button"]', 'Access Method').click(); - - cy.get('.react-draggable') - .eq(2) - .trigger('mousedown') - .trigger('mousemove', { clientX: 400 }) - .trigger('mouseup'); - cy.contains('[role="button"]', 'Username').click(); - - cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( - 'have.text', - 'globus' - ); - }); - }); + // descending order + cy.get('@accessMethodSortButton').click(); - describe('should be able to filter download items by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Availability"]') - .first() - .type('Available', { force: true }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( + 'have.text', + 'https' + ); - cy.get('[aria-rowindex="1"] [aria-colindex="6"]').should( - 'have.text', - 'Available' - ); - }); + // no order + cy.get('@accessMethodSortButton').click(); - it('date between', () => { - const currDate = new Date(); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( + 'have.text', + 'https' + ); - cy.get('input[id="Requested Date filter from"]').type( - currDate.toISOString().slice(0, 10) - ); + // multiple columns + cy.contains('[role="button"]', 'Deleted').click(); + cy.contains('[role="button"]', 'Availability').click(); - cy.get('input[id="Requested Date filter to"]').type( - currDate.toISOString().slice(0, 10) - ); + cy.get('[aria-rowindex="2"] [aria-colindex="6"]').should( + 'have.text', + 'Available' + ); + cy.get('[aria-rowindex="3"] [aria-colindex="6"]').should( + 'have.text', + 'Expired' + ); + }); - cy.get('[aria-rowcount="0"]').should('not.exist'); + it('should be able to filter with both text & date filters on multiple columns', () => { + cy.get('[aria-rowcount]') + .invoke('attr', 'aria-rowcount') + .as('initialRowCount'); + const now = Date.now(); + // plus and minus 5 seconds from "now" + const fromDate = new Date(now - 5000); + const toDate = new Date(now + 5000); + + cy.get('input[id="Requested Date filter from"]').type( + fromDate.toLocaleString('sv') + ); + + cy.get('input[id="Requested Date filter to"]').type( + toDate.toLocaleString('sv') + ); + + cy.get('@initialRowCount').then((initialRowCount) => { + cy.get(`[aria-rowcount="${initialRowCount}"]`).should('not.exist'); }); + cy.get('[aria-rowcount="0"]').should('not.exist'); + + cy.get('[aria-rowcount]') + .invoke('attr', 'aria-rowcount') + .as('dateFilterRowCount'); + + cy.get('[aria-label="Filter by Availability"]') + .first() + .type('Available', { force: true }); + + cy.get('[aria-rowindex="1"] [aria-colindex="6"]').should( + 'have.text', + 'Available' + ); - it('multiple columns', () => { - cy.get('[role="columnheader"]').eq(4).as('accessColumn'); - cy.get('[role="columnheader"]').eq(5).as('availabilityColumn'); - - cy.get('.react-draggable') - .eq(4) - .trigger('mousedown') - .trigger('mousemove', { clientX: 500 }) - .trigger('mouseup'); - - cy.get('.react-draggable') - .eq(5) - .trigger('mousedown') - .trigger('mousemove', { clientX: 700 }) - .trigger('mouseup'); - - cy.get('[aria-label="Filter by Access Method') - .first() - .type('globus', { force: true }); - cy.get('[aria-label="Filter by Availability"]') - .first() - .type('restoring', { force: true }); - - cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( - 'have.text', - 'globus' - ); + cy.get('@dateFilterRowCount').then((dateFilterRowCount) => { + cy.get(`[aria-rowcount="${dateFilterRowCount}"]`).should('not.exist'); }); + cy.get('[aria-rowcount="0"]').should('not.exist'); }); }); diff --git a/packages/datagateway-download/cypress/e2e/downloadCart.cy.ts b/packages/datagateway-download/cypress/e2e/downloadCart.cy.ts index 6d9594417..2ca7ad9e9 100644 --- a/packages/datagateway-download/cypress/e2e/downloadCart.cy.ts +++ b/packages/datagateway-download/cypress/e2e/downloadCart.cy.ts @@ -21,13 +21,12 @@ describe('Download Cart', () => { // Ensure we can move away from the table and come back to it. cy.get('[aria-label="Download selection panel"]').should('exist'); // Wait for the downloads to be fetched before moving back to the cart. - cy.get('[aria-label="Downloads"]') - .should('exist') - .click() - .wait('@fetchDownloads'); + cy.get('[aria-label="Downloads"]').should('exist').click(); + cy.wait('@fetchDownloads'); cy.get('[aria-label="Download status panel"]').should('exist'); - cy.get('[aria-label="Selection').click().wait('@fetchCart'); + cy.get('[aria-label="Selection').click(); + cy.wait('@fetchCart'); cy.get('[aria-label="Download selection panel"]').should('exist'); cy.get('[aria-rowcount=59]', { timeout: 10000 }).should('exist'); diff --git a/packages/datagateway-download/cypress/e2e/downloadConfirmation.cy.ts b/packages/datagateway-download/cypress/e2e/downloadConfirmation.cy.ts index beb439c53..e04998fc0 100644 --- a/packages/datagateway-download/cypress/e2e/downloadConfirmation.cy.ts +++ b/packages/datagateway-download/cypress/e2e/downloadConfirmation.cy.ts @@ -27,7 +27,7 @@ describe('Download Confirmation', () => { cy.get('[aria-label="Download confirmation dialog"]').should('exist'); }); - it('should load correctly and display the confirmation dialog for the cart items', () => { + it('should load correctly and display the confirmation dialog for the cart items & let the dialog be closed', () => { // Show the correct download size of the cart items. cy.contains('Download Size: 3.12 GB').should('exist'); @@ -46,19 +46,12 @@ describe('Download Confirmation', () => { cy.contains('#download-table-hundred', '3 minutes, 57 seconds').should( 'exist' ); - }); - it('should prevent download requests with an invalid email address', () => { - // Enter in an invalid email address. - cy.get('#confirm-download-email').type('email.address'); + cy.get('[aria-label="Close download confirmation dialog"]').should('exist'); - // Ensure that the download button is disabled. - cy.get('#download-confirmation-download').should('be.disabled'); + cy.get('[aria-label="Close download confirmation dialog"]').click(); - // Complete the remainder of the email and ensure the email is not invalid anymore - // as the download button is enabled. - cy.get('#confirm-download-email').type('@test.com'); - cy.get('#download-confirmation-download').should('be.enabled'); + cy.get('[aria-label="Download confirmation dialog"]').should('not.exist'); }); it('should be able to submit a download request and start immediate download with default values (HTTPS)', () => { @@ -78,6 +71,13 @@ describe('Download Confirmation', () => { 'exist' ); cy.contains('#confirm-success-access-method', 'HTTPS').should('exist'); + + // Click on the download status link and expect the download + // status panel to have been displayed. + cy.contains('#download-confirmation-status-link', 'View My Downloads') + .should('exist') + .click(); + cy.get('[aria-label="Download status panel"]').should('exist'); }); it('should not be able to submit a download request with a disabled access method (Globus)', () => { @@ -114,7 +114,16 @@ describe('Download Confirmation', () => { cy.get('#confirm-download-name').type('test-file-name'); // Set email address. - cy.get('#confirm-download-email').type('test@email.com'); + // Enter in an invalid email address. + cy.get('#confirm-download-email').type('email.address'); + + // Ensure that the download button is disabled. + cy.get('#download-confirmation-download').should('be.disabled'); + + // Complete the remainder of the email and ensure the email is not invalid anymore + // as the download button is enabled. + cy.get('#confirm-download-email').type('@test.com'); + cy.get('#download-confirmation-download').should('be.enabled'); // Request download. cy.get('#download-confirmation-download').click(); @@ -129,30 +138,9 @@ describe('Download Confirmation', () => { 'exist' ); cy.contains('#confirm-success-access-method', 'HTTPS').should('exist'); - cy.contains('#confirm-success-email-address', 'test@email.com').should( - 'exist' - ); - }); - - // This needs to be implemented once the tab has been included into the code. - it('should be able to link to the downloads status tab upon successful download confirmation', () => { - cy.get('#download-confirmation-download').click(); - - cy.get('#download-confirmation-success').should('exist'); - - // Click on the download status link and expect the download - // status panel to have been displayed. - cy.contains('#download-confirmation-status-link', 'View My Downloads') - .should('exist') - .click(); - cy.get('[aria-label="Download status panel"]').should('exist'); - }); - - it('should be able to close the download confirmation dialog', () => { - cy.get('[aria-label="Close download confirmation dialog"]').should('exist'); - - cy.get('[aria-label="Close download confirmation dialog"]').click(); - - cy.get('[aria-label="Download confirmation dialog"]').should('not.exist'); + cy.contains( + '#confirm-success-email-address', + 'email.address@test.com' + ).should('exist'); }); }); diff --git a/packages/datagateway-download/cypress/e2e/downloadStatus.cy.ts b/packages/datagateway-download/cypress/e2e/downloadStatus.cy.ts index 890d02c58..117ab83d7 100644 --- a/packages/datagateway-download/cypress/e2e/downloadStatus.cy.ts +++ b/packages/datagateway-download/cypress/e2e/downloadStatus.cy.ts @@ -10,7 +10,7 @@ describe('Download Status', () => { }); beforeEach(() => { - cy.intercept('GET', '**/getPercentageComplete**'); + cy.intercept('GET', '**/getPercentageComplete**', '100'); cy.intercept('GET', '**/topcat/user/downloads**').as('fetchDownloads'); cy.login(); @@ -21,19 +21,27 @@ describe('Download Status', () => { cy.visit('/download'); cy.get('[aria-label="Downloads"]').should('exist'); - cy.get('[aria-label="Downloads"]') - .click() - .then(() => { - cy.wait('@fetchDownloads'); - }); + cy.get('[aria-label="Downloads"]').click(); + cy.wait('@fetchDownloads'); }); }); - it('should load correctly and display download status table', () => { + it('should load correctly and display download status table & show correct info & links', () => { cy.title().should('equal', 'DataGateway Download'); cy.get('#datagateway-download').should('be.visible'); cy.get('[aria-label="Download status panel"]').should('exist'); + + cy.contains('[aria-colindex="1"]', 'test-file-1') + .should('be.visible') + .and('not.be.disabled'); + + // We are not clicking and proceeding to download the item in this test + // but instead checking that the link exists and it is possible to be clicked. + cy.get('a[aria-label="Download test-file-1"]').should('not.be.empty'); + cy.get('a[aria-label="Download test-file-1"]') + .should('have.prop', 'href') + .and('contain', 'getData'); }); it('should refresh the table when clicking the refresh downloads button', () => { @@ -61,155 +69,127 @@ 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(); + it('should be able to sort by all sort directions on single and multiple columns', () => { + // remove default sort + cy.contains('[role="button"]', 'Requested Date').click(); - cy.contains('[role="button"]', 'Download Name').click(); + // ascending + cy.contains('[role="button"]', 'Download Name') + .as('nameSortButton') + .click(); - cy.get('[aria-sort="ascending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); + cy.get('[aria-sort="ascending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should('be.visible'); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( - 'have.text', - 'test-file-1' - ); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( + 'have.text', + 'test-file-1' + ); - 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(); - - cy.get('[aria-sort="descending"]').should('exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should( - 'not.have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( - 'have.text', - 'test-file-4' - ); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').should( - 'have.text', - 'Expired' - ); - }); + // descending + cy.get('@nameSortButton').click(); - 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(); - - cy.get('[aria-sort="ascending"]').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); - cy.get('.MuiTableSortLabel-iconDirectionAsc').should( - 'have.css', - 'opacity', - '0' - ); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( - 'have.text', - 'test-file-1' - ); - - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').should( - 'have.text', - 'Available' - ); - }); + cy.get('[aria-sort="descending"]').should('exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should( + 'not.have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( + 'have.text', + 'test-file-4' + ); - 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.get('[aria-rowindex="1"] [aria-colindex="3"]').should( + 'have.text', + 'Expired' + ); - cy.contains('[role="button"]', 'Access Method').click(); - cy.contains('[role="button"]', 'Availability').click(); + // no order + cy.get('@nameSortButton').click(); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( - 'have.text', - 'test-file-4' - ); - }); + cy.get('[aria-sort="ascending"]').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionDesc').should('not.exist'); + cy.get('.MuiTableSortLabel-iconDirectionAsc').should( + 'have.css', + 'opacity', + '0' + ); + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( + 'have.text', + 'test-file-1' + ); + + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').should( + 'have.text', + 'Available' + ); + + // multiple columns + cy.contains('[role="button"]', 'Access Method').click(); + cy.contains('[role="button"]', 'Availability').click(); + + cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( + 'have.text', + 'test-file-4' + ); }); - describe('should be able to filter download items by', () => { - it('text', () => { - cy.get('[aria-label="Filter by Download Name"]').first().type('4'); + it('should be able to filter with both text & date filters on multiple columns', () => { + cy.get('input[id="Requested Date filter from"]').type( + '2020-01-31 00:00:00' + ); - cy.get('[aria-rowcount="1"]').should('exist'); + const date = new Date(); + date.setDate(1); + date.setMonth(date.getMonth() - 1); + // MUIv5 datetime pickers don't allow for time to be graphically selected + // This is because the relevant elements are elements with pointer-events: none + // Therefore, we settle for typing the date and time instead + cy.get('input[id="Requested Date filter to"]').type( + format(date, 'yyyy-MM-dd HH:mm:ss') + ); - cy.get('[aria-rowindex="1"] [aria-colindex="1"]').should( - 'have.text', - 'test-file-4' - ); - }); + // There should not be results for this time period. + cy.get('[aria-rowcount="0"]').should('exist'); - it('date between', () => { - cy.get('input[id="Requested Date filter from"]').type( - '2020-01-31 00:00:00' - ); - - const date = new Date(); - date.setDate(1); - date.setMonth(date.getMonth() - 1); - // MUIv5 datetime pickers don't allow for time to be graphically selected - // This is because the relevant elements are elements with pointer-events: none - // Therefore, we settle for typing the date and time instead - cy.get('input[id="Requested Date filter to"]').type( - format(date, 'yyyy-MM-dd HH:mm:ss') - ); - - // There should not be results for this time period. - cy.get('[aria-rowcount="0"]').should('exist'); - - const currDate = new Date(); - currDate.setHours(0, 0, 0, 0); - - cy.get('input[id="Requested Date filter from"]').clear(); - cy.get('input[id="Requested Date filter to"]').clear(); - cy.get('[aria-rowcount="4"]').should('exist'); - - cy.get('input[id="Requested Date filter from"]').type( - format(currDate, 'yyyy-MM-dd HH:mm:ss') - ); - - cy.get('[aria-rowcount="4"]').should('exist'); - - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').should( - 'contain', - format(currDate, 'yyyy-MM-dd') - ); - }); + const currDate = new Date(); + currDate.setHours(0, 0, 0, 0); - it('multiple columns', () => { - cy.get('[aria-label="Filter by Access Method"]').first().type('globus'); + cy.get('input[id="Requested Date filter from"]').clear(); + cy.get('input[id="Requested Date filter to"]').clear(); + cy.get('[aria-rowcount="4"]').should('exist'); - cy.get('[aria-label="Filter by Availability"]').first().type('restoring'); + cy.get('input[id="Requested Date filter from"]').type( + format(currDate, 'yyyy-MM-dd HH:mm:ss') + ); - cy.get('[aria-rowcount="2"]').should('exist'); - }); - }); + cy.get('[aria-rowcount="4"]').should('exist'); + + // account for whether the download progress feature is enabled or not + cy.get('[role="columnheader"]') + .eq(3) + .then(($fourthColHeader) => { + if ($fourthColHeader.text().includes('Progress')) { + cy.get('[aria-rowindex="1"] [aria-colindex="5"]').should( + 'contain', + format(currDate, 'yyyy-MM-dd') + ); + } else { + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').should( + 'contain', + format(currDate, 'yyyy-MM-dd') + ); + } + }); - it('should have a download link for an item', () => { - cy.contains('[aria-colindex="1"]', 'test-file-1') - .should('be.visible') - .and('not.be.disabled'); + cy.get('[aria-label="Filter by Access Method"]').first().type('globus'); - // We are not clicking and proceeding to download the item in this test - // but instead checking that the link exists and it is possible to be clicked. - cy.get('a[aria-label="Download test-file-1"]').should('not.be.empty'); - cy.get('a[aria-label="Download test-file-1"]') - .should('have.prop', 'href') - .and('contain', 'getData'); + cy.get('[aria-rowcount="2"]').should('exist'); + + cy.get('[aria-label="Filter by Availability"]').first().type('restoring'); + + cy.get('[aria-rowcount="1"]').should('exist'); }); it('should be able to remove a download', () => { diff --git a/packages/datagateway-download/cypress/e2e/downloadTab.cy.ts b/packages/datagateway-download/cypress/e2e/downloadTab.cy.ts index cc85bad38..bfe3b7ca0 100644 --- a/packages/datagateway-download/cypress/e2e/downloadTab.cy.ts +++ b/packages/datagateway-download/cypress/e2e/downloadTab.cy.ts @@ -12,17 +12,15 @@ describe('Download Cart', () => { cy.clearDownloadCart(); }); - it('should load correctly and display selection panel', () => { + it('should display the selection tab on every page reload', () => { cy.title().should('equal', 'DataGateway Download'); cy.get('#datagateway-download').should('be.visible'); cy.get('[aria-label="Selection"]').should('exist'); cy.get('[aria-label="Downloads"]').should('exist'); cy.get('[aria-label="Download selection panel"]').should('be.visible'); cy.get('[aria-label="Download status panel"]').should('not.be.visible'); - }); - it('should display the selection tab on every page reload', () => { - cy.get('[aria-label="Downloads"]').should('exist').click(); + cy.get('[aria-label="Downloads"]').click(); cy.get('[aria-label="Download status panel"]').should('be.visible'); cy.get('[aria-label="Download selection panel"]').should('not.be.visible'); diff --git a/packages/datagateway-download/cypress/tsconfig.json b/packages/datagateway-download/cypress/tsconfig.json index d38e7a12f..bd61c5f93 100644 --- a/packages/datagateway-download/cypress/tsconfig.json +++ b/packages/datagateway-download/cypress/tsconfig.json @@ -3,7 +3,11 @@ "strict": true, "baseUrl": "../node_modules", "target": "es5", - "lib": ["es5", "dom"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "types": ["cypress"] }, "include": ["**/*"] diff --git a/packages/datagateway-download/package.json b/packages/datagateway-download/package.json index 3179e51c1..0f72885b7 100644 --- a/packages/datagateway-download/package.json +++ b/packages/datagateway-download/package.json @@ -44,6 +44,7 @@ "typescript": "4.9.3" }, "devDependencies": { + "@babel/eslint-parser": "7.22.5", "@testing-library/jest-dom": "5.16.4", "@testing-library/react": "12.1.3", "@testing-library/react-hooks": "8.0.1", @@ -52,7 +53,6 @@ "@types/lodash.chunk": "4.2.6", "@typescript-eslint/eslint-plugin": "5.61.0", "@typescript-eslint/parser": "5.61.0", - "@babel/eslint-parser": "7.22.5", "cross-env": "7.0.3", "cypress": "11.2.0", "cypress-failed-log": "2.10.0", @@ -76,7 +76,7 @@ "e2e": "start-server-and-test e2e:serve http://localhost:3000 cy:run", "cy:open": "cypress open", "cy:run": "cypress run", - "lint:js": "eslint --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src && yarn build", + "lint:js": "eslint --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src ./cypress && yarn build", "eject": "react-scripts eject", "pre-commit": "lint-staged" }, diff --git a/packages/datagateway-download/src/downloadStatus/adminDownloadStatusTable.component.tsx b/packages/datagateway-download/src/downloadStatus/adminDownloadStatusTable.component.tsx index 5ccdf4f1f..f9125908e 100644 --- a/packages/datagateway-download/src/downloadStatus/adminDownloadStatusTable.component.tsx +++ b/packages/datagateway-download/src/downloadStatus/adminDownloadStatusTable.component.tsx @@ -175,7 +175,7 @@ const AdminDownloadStatusTable: React.FC = () => { label={label} onChange={(value: { value?: string | number; type: string } | null) => { if (value) { - if (dataKey === 'formattedStatus') { + if (dataKey === 'status') { const downloadStatus = ( Object.keys(downloadStatuses) as DownloadStatus[] ).find( @@ -320,8 +320,10 @@ const AdminDownloadStatusTable: React.FC = () => { }, { label: t('downloadStatus.status'), - dataKey: 'formattedStatus', + dataKey: 'status', filterComponent: textFilter, + cellContentRenderer: ({ rowData }) => + (rowData as FormattedDownload).formattedStatus, }, ...(settings.uiFeatures.downloadProgress ? [ @@ -362,7 +364,9 @@ const AdminDownloadStatusTable: React.FC = () => { }, { label: t('downloadStatus.deleted'), - dataKey: 'formattedIsDeleted', + dataKey: 'isDeleted', + cellContentRenderer: ({ rowData }) => + (rowData as FormattedDownload).formattedIsDeleted, }, ]} sort={sort} diff --git a/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.test.tsx b/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.test.tsx index 4b4b270f1..9337fd6b4 100644 --- a/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.test.tsx +++ b/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.test.tsx @@ -277,6 +277,7 @@ describe('Download Status Table', () => { await user.type(downloadStatusFilterBox, 'downloadStatus.complete'); expect(await screen.findByText('test-file-1')).toBeInTheDocument(); + expect(screen.queryByText('test-file-3')).toBeNull(); await user.clear(downloadMethodFilterBox); await user.clear(downloadStatusFilterBox); @@ -360,6 +361,19 @@ describe('Download Status Table', () => { expect(screen.queryByText('test-file-4')).toBeNull(); expect(screen.queryByText('test-file-5')).toBeNull(); + // create an invalid range + await user.type(dateFromFilterInput, '2020-02-28 00:00:00'); + + // should display error + expect(await screen.findAllByText('Invalid date-time range')); + + // Should show all files + expect(await screen.findByText('test-file-1')).toBeInTheDocument(); + expect(await screen.findByText('test-file-2')).toBeInTheDocument(); + expect(await screen.findByText('test-file-3')).toBeInTheDocument(); + expect(await screen.findByText('test-file-4')).toBeInTheDocument(); + expect(await screen.findByText('test-file-5')).toBeInTheDocument(); + cleanupDatePickerWorkaround(); }); diff --git a/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx b/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx index 4d22b177a..68cafe642 100644 --- a/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx +++ b/packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx @@ -149,13 +149,16 @@ const DownloadStatusTable: React.FC = ( if (!downloads) return []; const filteredData = downloads.filter((item) => { - for (const [key, filter] of Object.entries(filters)) { + const filterEntries = Object.entries(filters); + const satisfiedFilters: boolean[] = []; + for (const [key, filter] of filterEntries) { const tableValue = item[key]; const isTableValueAString = tableValue !== undefined && typeof tableValue === 'string'; if (!isTableValueAString) { - return false; + satisfiedFilters.push(false); + continue; } const isTextFilter = @@ -163,12 +166,17 @@ const DownloadStatusTable: React.FC = ( 'value' in filter && typeof filter.value === 'string'; if (isTextFilter) { - const isInclusionFilter = filter.type === 'include'; const filterKeyword = (filter.value as string).toLowerCase(); - return isInclusionFilter - ? tableValue.toLowerCase().includes(filterKeyword) - : !tableValue.toLowerCase().includes(filterKeyword); + satisfiedFilters.push( + filter.type === 'exact' + ? tableValue.toLowerCase() === filterKeyword + : filter.type === 'exclude' + ? !tableValue.toLowerCase().includes(filterKeyword) + : tableValue.toLowerCase().includes(filterKeyword) + ); + + continue; } const isDateFilter = @@ -183,27 +191,46 @@ const DownloadStatusTable: React.FC = ( const endDateFilter = filter.endDate ? toDate(filter.endDate) : null; if (startDateFilter && endDateFilter) { - return isWithinInterval(tableDate, { - start: startDateFilter, - end: endDateFilter, - }); + try { + satisfiedFilters.push( + isWithinInterval(tableDate, { + start: startDateFilter, + end: endDateFilter, + }) + ); + } catch (e) { + if (e instanceof RangeError) { + // isWithinInterval throws with RangeError if startDate > endDate + // in the date filter we tell the user this is invalid, + // so handle it there and do nothing here + } else { + throw e; + } + } + + continue; } if (startDateFilter) { - return ( + satisfiedFilters.push( isEqual(tableDate, startDateFilter) || - isAfter(tableDate, startDateFilter) + isAfter(tableDate, startDateFilter) ); + + continue; } if (endDateFilter) { - return ( + satisfiedFilters.push( isEqual(tableDate, endDateFilter) || - isBefore(tableDate, endDateFilter) + isBefore(tableDate, endDateFilter) ); + + continue; } } + satisfiedFilters.push(false); } - return true; + return satisfiedFilters.every((value) => value); }); function sortDownloadItems( diff --git a/packages/datagateway-search/cypress/e2e/search/datafileSearch.cy.ts b/packages/datagateway-search/cypress/e2e/search/datafileSearch.cy.ts index 92136c084..ad11453f6 100644 --- a/packages/datagateway-search/cypress/e2e/search/datafileSearch.cy.ts +++ b/packages/datagateway-search/cypress/e2e/search/datafileSearch.cy.ts @@ -30,11 +30,10 @@ describe('Datafile search tab', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@datafiles', '@datafiles', '@datafilesCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@datafiles', '@datafiles', '@datafilesCount'], { + timeout: 10000, + }); cy.get('#container-search-filters').should('exist'); @@ -43,30 +42,31 @@ describe('Datafile search tab', () => { it('should be able to search by text', () => { cy.clearDownloadCart(); - cy.get('#filled-search').type('1440'); + cy.get('#filled-search').type('1532'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('[aria-label="Search table"]') .contains('Datafile') .contains('1') - .click() - .wait(['@datafiles', '@datafiles', '@datafilesCount'], { - timeout: 10000, - }); + .click(); + cy.wait(['@datafiles', '@datafiles', '@datafilesCount'], { + timeout: 10000, + }); cy.get('[aria-rowcount="1"]').should('exist'); - cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1440'); + cy.get('[aria-rowindex="1"] [aria-colindex="3"]').contains('Datafile 1532'); + + // check that it's linking to its parent dataset correctly + cy.get('[href="/browse/investigation/45/dataset/105/datafile"]'); // Check that "select all" and individual selection are equivalent - cy.get(`[aria-rowindex="1"] [aria-colindex="1"]`) - .click() - .wait('@topcat', { timeout: 10000 }); + cy.get(`[aria-rowindex="1"] [aria-colindex="1"]`).click(); + cy.wait('@topcat', { timeout: 10000 }); cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( 'be.checked' ); @@ -82,7 +82,8 @@ describe('Datafile search tab', () => { date.toISOString().slice(0, 10) ); - cy.get('[aria-label="Submit search"]').click().wait('@datafilesCount', { + cy.get('[aria-label="Submit search"]').click(); + cy.wait('@datafilesCount', { timeout: 10000, }); @@ -102,11 +103,10 @@ describe('Datafile search tab', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('[aria-rowcount="50"]').should('exist'); @@ -114,22 +114,4 @@ describe('Datafile search tab', () => { .contains('Datafile') .should('not.exist'); }); - - it('should link to a parent dataset', () => { - cy.get('#filled-search').type('1532'); - - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); - cy.get('[aria-label="Search table"]') - .contains('Datafile') - .contains('1') - .click() - .wait(['@datafiles', '@datafiles', '@datafilesCount'], { - timeout: 10000, - }); - cy.get('[href="/browse/investigation/45/dataset/105/datafile"]'); - }); }); diff --git a/packages/datagateway-search/cypress/e2e/search/datasetSearch.cy.ts b/packages/datagateway-search/cypress/e2e/search/datasetSearch.cy.ts index c1b52b85c..10760f37c 100644 --- a/packages/datagateway-search/cypress/e2e/search/datasetSearch.cy.ts +++ b/packages/datagateway-search/cypress/e2e/search/datasetSearch.cy.ts @@ -30,34 +30,40 @@ describe('Dataset search tab', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@datasets', '@datasets', '@datasetsCount'], { - timeout: 10000, - }); + cy.get('#filled-search').type('12'); + cy.get('[aria-label="Start date input"]').type('2003-01-01'); + cy.get('[aria-label="End date input"]').type('2004-01-01'); + + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@datasets', '@datasets', '@datasetsCount'], { + timeout: 10000, + }); cy.get('#container-search-filters').should('exist'); cy.get('#container-search-table').should('exist'); + + // check links are being rendered correctly for datasets and investigations + cy.get('[href="/browse/investigation/12/dataset/12/datafile"]'); + cy.get('[href="/browse/investigation/12/dataset"]'); }); it('should be able to search by text', () => { cy.clearDownloadCart(); cy.get('#filled-search').type('police'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 15000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 15000, + }); cy.get('[aria-label="Search table"]') .contains('Dataset') .contains('2') - .click() - .wait(['@datasets', '@datasets', '@datasetsCount'], { - timeout: 15000, - }); + .click(); + cy.wait(['@datasets', '@datasets', '@datasetsCount'], { + timeout: 15000, + }); cy.get('[aria-rowcount="2"]').should('exist'); @@ -66,9 +72,8 @@ describe('Dataset search tab', () => { // Check that "select all" and individual selection are equivalent let i = 1; while (i < 3) { - cy.get(`[aria-rowindex="${i}"] [aria-colindex="1"]`) - .click() - .wait('@topcat', { timeout: 10000 }); + cy.get(`[aria-rowindex="${i}"] [aria-colindex="1"]`).click(); + cy.wait('@topcat', { timeout: 10000 }); i++; } cy.get('[aria-label="select all rows"]', { timeout: 10000 }).should( @@ -101,11 +106,10 @@ describe('Dataset search tab', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('[aria-rowcount="50"]').should('exist'); @@ -113,34 +117,4 @@ describe('Dataset search tab', () => { .contains('Dataset') .should('not.exist'); }); - - it('should link to a dataset', () => { - cy.get('#filled-search').type('12'); - cy.get('[aria-label="Start date input"]').type('2003-01-01'); - cy.get('[aria-label="End date input"]').type('2004-01-01'); - - cy.get('[aria-label="Submit search"]').click(); - - cy.get('[aria-label="Search table"]') - .contains('Dataset') - .contains('1') - .click(); - - cy.get('[href="/browse/investigation/12/dataset/12/datafile"]'); - }); - - it('should link to a parent investigation', () => { - cy.get('#filled-search').type('12'); - cy.get('[aria-label="Start date input"]').type('2003-01-01'); - cy.get('[aria-label="End date input"]').type('2004-01-01'); - - cy.get('[aria-label="Submit search"]').click(); - - cy.get('[aria-label="Search table"]') - .contains('Dataset') - .contains('1') - .click(); - - cy.get('[href="/browse/investigation/12/dataset"]'); - }); }); diff --git a/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts b/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts index 8f7d5b63c..bac209ef0 100644 --- a/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts +++ b/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts @@ -30,34 +30,34 @@ describe('Investigation search tab', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('#filled-search').type('strategy'); + + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('#container-search-filters').should('exist'); cy.get('#container-search-table').should('exist'); + + // check investigations are linked correctly + cy.get('[href="/browse/investigation/2/dataset"]'); }); it('should be able to search by title text', () => { cy.clearDownloadCart(); cy.get('#filled-search').type('strategy'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('[aria-rowcount="4"]').should('exist'); cy.get('[aria-rowindex="1"] [aria-colindex="6"]').contains('1-903289-21-1'); - // Small wait to ensure rows are selected correctly - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(1000); // Check that "select all" and individual selection are equivalent let i = 1; while (i < 5) { @@ -77,11 +77,10 @@ describe('Investigation search tab', () => { it('should be able to search by instrument text', () => { cy.get('#filled-search').type('knowledge media'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('[aria-label="Search table"]') .contains('Investigation') @@ -115,11 +114,10 @@ describe('Investigation search tab', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@datasets', '@datasets', '@datasetsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@datasets', '@datasets', '@datasetsCount'], { + timeout: 10000, + }); cy.get('[aria-rowcount="50"]').should('exist'); @@ -127,15 +125,4 @@ describe('Investigation search tab', () => { .contains('Investigation') .should('not.exist'); }); - - it('should link to an investigation', () => { - cy.get('#filled-search').type('strategy'); - - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigationsCount'], { - timeout: 10000, - }); - cy.get('[href="/browse/investigation/2/dataset"]'); - }); }); diff --git a/packages/datagateway-search/cypress/e2e/searchPageContainer.cy.ts b/packages/datagateway-search/cypress/e2e/searchPageContainer.cy.ts index a9af8f74a..8c9ef3e7a 100644 --- a/packages/datagateway-search/cypress/e2e/searchPageContainer.cy.ts +++ b/packages/datagateway-search/cypress/e2e/searchPageContainer.cy.ts @@ -1,31 +1,24 @@ describe('SearchPageContainer Component', () => { - let facilityName: string; + // let facilityName: string; - before(() => { - cy.readFile('server/e2e-settings.json').then((settings) => { - if (settings.facilityName) facilityName = settings.facilityName; - }); - }); + // before(() => { + // cy.readFile('server/e2e-settings.json').then((settings) => { + // if (settings.facilityName) facilityName = settings.facilityName; + // }); + // }); it('Should default back to 10 when any result is manually entered into the url', () => { cy.login(); - cy.visit('/search/data?view=card&results=100'); cy.intercept('**/investigations/count?where=%7B%22id*').as( 'investigationsCount' ); cy.intercept('**/investigations?*').as('investigations'); - cy.intercept('**/datasets/count?where=%7B%22id*').as('datasetsCount'); - cy.intercept('**/datasets?*').as('datasets'); - cy.intercept('**/datafiles/count?where=%7B%22id*').as('datafilesCount'); - cy.intercept('**/datafiles?*').as('datafiles'); - cy.intercept(`**/topcat/user/cart/${facilityName}/cartItems`).as('topcat'); - - cy.clearDownloadCart(); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.visit('/search/data?view=card&results=100'); + + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.get('[aria-label="card-buttons"]', { timeout: 10000 }).should( 'have.length', @@ -33,40 +26,67 @@ describe('SearchPageContainer Component', () => { ); }); + it('should be able to load results from a URL', () => { + cy.login(); + cy.intercept('**/investigations/count?where=%7B%22id*').as( + 'investigationsCount' + ); + cy.intercept('**/investigations?*').as('investigations'); + + cy.visit('/search/data/?view=card&searchText=test&startDate=2000-06-01'); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); + + //Should be in card view + cy.get('[aria-label="page view Display as table"]').should('exist'); + cy.get('[aria-label="page view Display as table"]').contains( + 'Display as table' + ); + + cy.get('[aria-label="Search table"]') + .contains('Investigation') + .contains('1') + .should('exist'); + cy.get('[aria-label="Search table"]') + .contains('Dataset') + .contains('5') + .should('exist'); + cy.get('[aria-label="Search table"]') + .contains('Datafile') + .contains('36') + .should('exist'); + }); + describe('SearchPageContainer Components', () => { beforeEach(() => { cy.login(); + cy.clearDownloadCart(); cy.visit('/search/data/'); cy.intercept('**/investigations/count?where=%7B%22id*').as( 'investigationsCount' ); cy.intercept('**/investigations?*').as('investigations'); - cy.clearDownloadCart(); cy.get('#filled-search').type('dog'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); }); it('should load correctly', () => { cy.title().should('equal', 'DataGateway Search'); cy.get('#container-search-filters').should('exist'); + cy.get('#container-search-table').should('exist'); + cy.location().should((loc) => { expect(loc.search).to.eq('?searchText=dog'); }); - }); - it('should display results correctly', () => { - cy.get('#container-search-table').should('exist'); - }); - - it('should have the correct url for the DOI link (Tableview) ', () => { - // DOI + // check table DOI link is correct cy.get('[data-testid="investigation-search-table-doi-link"]') .first() @@ -81,21 +101,6 @@ describe('SearchPageContainer Component', () => { }); }); - it('should be able to navigate through tabs without losing the filters (Table)', () => { - cy.title().should('equal', 'DataGateway Search'); - - cy.get('#container-search-filters').should('exist'); - cy.get('[aria-label="Filter by Title"]').type('ba'); - cy.contains('Visit ID').first().click(); - - cy.get('[id="simple-tab-dataset"]').click(); - cy.get('[id="simple-tab-investigation"]').click(); - - cy.get('[aria-rowcount="4"]').should('exist'); - - cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('18'); - }); - it('should be able to click clear filters button to clear filters', () => { cy.url().then((url) => { cy.get('#container-search-filters').should('exist'); @@ -118,25 +123,18 @@ describe('SearchPageContainer Component', () => { }); }); - it('should have the correct url for the DOI link (Cardview) ', () => { - // DOI - - cy.get('[aria-label="page view Display as cards"]').click(); + it('should be able to switch between tabs (and filters should not be lost)', () => { + cy.get('[aria-label="Search table"]') + .contains('Investigation') + .contains('5'); - cy.get('[data-testid="investigation-search-card-doi-link"]') - .first() - .then(($doi) => { - const doi = $doi.text(); + cy.get('[aria-label="Filter by Title"]').type('ba'); + cy.contains('Visit ID').first().click(); - const url = `https://doi.org/${doi}`; + cy.get('[aria-rowcount="4"]').should('exist'); - cy.get('[data-testid="investigation-search-card-doi-link"]') - .first() - .should('have.attr', 'href', url); - }); - }); + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('18'); - it('should be able to switch between tabs', () => { cy.get('[aria-label="Search table"]') .contains('Dataset') .contains('3') @@ -149,8 +147,12 @@ describe('SearchPageContainer Component', () => { cy.get('[aria-label="Search table"]') .contains('Investigation') - .contains('5') + .contains('4') .click(); + + cy.get('[aria-rowcount="4"]').should('exist'); + + cy.get('[aria-rowindex="1"] [aria-colindex="4"]').contains('18'); }); it('should be able to switch to card view', () => { @@ -165,6 +167,19 @@ describe('SearchPageContainer Component', () => { expect(loc.search).to.eq('?view=card&searchText=dog'); }); + // check card view DOI link is correct + cy.get('[data-testid="investigation-search-card-doi-link"]') + .first() + .then(($doi) => { + const doi = $doi.text(); + + const url = `https://doi.org/${doi}`; + + cy.get('[data-testid="investigation-search-card-doi-link"]') + .first() + .should('have.attr', 'href', url); + }); + cy.get('[aria-label="page view Display as table"]').click(); //Should now be in table view @@ -194,101 +209,73 @@ describe('SearchPageContainer Component', () => { }); it('should be able to choose number of results to display', () => { - cy.login(); - cy.visit('/search/data/'); - cy.intercept('**/investigations/count?where=%7B%22id*').as( - 'investigationsCount' - ); - cy.intercept('**/investigations?*').as('investigations'); + cy.get('[aria-label="Search text input"]').clear(); - cy.clearDownloadCart(); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); cy.get('[aria-label="page view Display as cards"]').click(); - cy.get('[aria-label="card-buttons"]', { timeout: 10000 }).should( - 'have.length', - 10 - ); - cy.get('select[id="select-max-results"]', { - timeout: 10000, - }) - .select('20') - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); - cy.get('[aria-label="card-buttons"]', { timeout: 10000 }).should( - 'have.length', - 20 - ); + cy.get('select[id="select-max-results"]') + .as('maxResultsSelect') + .find('option:selected', { timeout: 10000 }) + .should('have.text', '10'); + cy.get('[aria-label="card-buttons"]') + .as('cardButtons') + .should('have.length', 10); - cy.get('select[id="select-max-results"]', { - timeout: 10000, - }) - .select('30') - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); - cy.get('[aria-label="card-buttons"]', { timeout: 10000 }).should( - 'have.length', - 30 - ); + cy.get('@maxResultsSelect').select('20'); + + cy.get('@maxResultsSelect') + .find('option:selected', { timeout: 10000 }) + .should('have.text', '20'); + cy.get('@cardButtons').should('have.length', 20); + + cy.get('@maxResultsSelect').select('30'); + + cy.get('@maxResultsSelect') + .find('option:selected', { timeout: 10000 }) + .should('have.text', '30'); + + cy.get('@cardButtons').should('have.length', 30); }); - //This test appears to get a different number of results locally compared to the automated tests - //on github meaning the test fails - it.skip('should be able to change page in card view', () => { - cy.get('[aria-label="Search text input"]').find('#filled-search').clear(); + it('should be able to change page in card view', () => { + cy.get('[aria-label="Search text input"]').clear(); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); cy.get('[aria-label="page view Display as cards"]').click(); + // we're testing cards in the middle of pages, as CI and SG-preprod can differ + // by around 1 result, so using first/last item per page is going to be + // wrong on one env or the other + cy.get('[aria-label="Go to page 2"]', { timeout: 10000 }).first().click(); - cy.get('[data-testid="card"]') - .first() - .contains('Guy maintain us process official people suffer.'); + cy.contains('[data-testid="card"]', 'Star enter wide nearly off'); cy.get('[aria-label="Go to next page"]', { timeout: 10000 }) .first() .click(); - cy.get('[data-testid="card"]') - .first() - .contains('Yourself smile either I pass significant.'); + cy.contains('[data-testid="card"]', 'Crime town perhaps'); cy.get('[aria-label="Go to last page"]', { timeout: 10000 }) .first() .click(); - cy.get('[data-testid="card"]') - .first() - .contains('Window former upon writer help step account.'); + cy.contains('[data-testid="card"]', 'Imagine ball old window'); cy.get('[aria-label="Go to previous page"]', { timeout: 10000 }) .first() .click(); - cy.get('[data-testid="card"]') - .first() - .contains('Someone statement Republican plan watch.'); + cy.contains('[data-testid="card"]', 'Deep watch simple'); cy.get('[aria-label="Go to first page"]', { timeout: 10000 }) .first() .click(); - cy.get('[data-testid="card"]') - .first() - .contains('Including spend increase ability music skill former.'); + cy.contains('[data-testid="card"]', 'Now himself exist board space'); }); it('should display selection alert banner correctly', () => { - cy.get(`[aria-rowindex="1"] [aria-colindex="1"]`) - .click() - .wait('@investigations', { timeout: 10000 }); + cy.get(`[aria-rowindex="1"] [aria-colindex="1"]`).click(); + cy.wait('@investigations', { timeout: 10000 }); cy.get('[aria-label="selection-alert"]').should('exist'); cy.get('[aria-label="selection-alert-text"]') @@ -316,11 +303,10 @@ describe('SearchPageContainer Component', () => { //Close drop down menu cy.get('body').type('{esc}'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.location().should((loc) => { expect(loc.search).to.eq( @@ -390,11 +376,10 @@ describe('SearchPageContainer Component', () => { it('should be able to select a start date', () => { cy.get('[aria-label="Start date input"]').type('2009-01-01'); - cy.get('[aria-label="Submit search"]') - .click() - .wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); + cy.get('[aria-label="Submit search"]').click(); + cy.wait(['@investigations', '@investigations', '@investigationsCount'], { + timeout: 10000, + }); cy.location().should((loc) => { expect(loc.search).to.contains('?searchText=dog&startDate=2009-01-01'); @@ -405,32 +390,5 @@ describe('SearchPageContainer Component', () => { .contains('2') .should('exist'); }); - - it('should be able to load results from a URL', () => { - cy.visit( - '/search/data/?view=card&searchText=test&startDate=2000-06-01' - ).wait(['@investigations', '@investigations', '@investigationsCount'], { - timeout: 10000, - }); - - //Should be in card view - cy.get('[aria-label="page view Display as table"]').should('exist'); - cy.get('[aria-label="page view Display as table"]').contains( - 'Display as table' - ); - - cy.get('[aria-label="Search table"]') - .contains('Investigation') - .contains('1') - .should('exist'); - cy.get('[aria-label="Search table"]') - .contains('Dataset') - .contains('5') - .should('exist'); - cy.get('[aria-label="Search table"]') - .contains('Datafile') - .contains('36') - .should('exist'); - }); }); }); diff --git a/packages/datagateway-search/package.json b/packages/datagateway-search/package.json index 4b4c7ccbc..3cc9785f8 100644 --- a/packages/datagateway-search/package.json +++ b/packages/datagateway-search/package.json @@ -66,7 +66,7 @@ "e2e": "start-server-and-test e2e:serve http://localhost:3000 cy:run", "cy:open": "cypress open", "cy:run": "cypress run", - "lint:js": "eslint --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src && yarn build", + "lint:js": "eslint --ext=tsx --ext=ts --ext=js --ext=jsx --fix ./src ./cypress && yarn build", "eject": "react-scripts eject", "pre-commit": "lint-staged" }, @@ -105,6 +105,7 @@ ] }, "devDependencies": { + "@babel/eslint-parser": "7.22.5", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "12.1.3", "@testing-library/user-event": "^14.4.3", @@ -114,7 +115,6 @@ "@typescript-eslint/eslint-plugin": "5.61.0", "@typescript-eslint/parser": "5.61.0", "@wojtekmaj/enzyme-adapter-react-17": "0.6.6", - "@babel/eslint-parser": "7.22.5", "cross-env": "7.0.3", "cypress": "11.2.0", "cypress-failed-log": "2.10.0",