diff --git a/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts b/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts index 2674b741d..329c24513 100644 --- a/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts +++ b/packages/datagateway-search/cypress/e2e/search/investigationSearch.cy.ts @@ -1,35 +1,12 @@ describe('Investigation search tab', () => { - let facilityName: string; - - before(() => { - cy.readFile('server/e2e-settings.json').then((settings) => { - if (settings.facilityName) facilityName = settings.facilityName; - }); - }); - beforeEach(() => { cy.login(); cy.visit('/search/data/'); - cy.intercept('**/search/documents*', { - fixture: 'investigationSearchResults.json', - }); - cy.intercept('**/investigations?*').as('investigations'); - cy.intercept('**/datasets/count*', { - body: 1, - }); - cy.intercept('**/datafiles/count*', { - body: 1, - }); - cy.intercept(`**/topcat/user/cart/${facilityName}*`, { - body: { - cartItems: [], - }, - }); - // only the dataset tab is tested here, so we want to hide investigation & datafile tabs + // only the investigation tab is tested here, so we want to hide dataset & datafile tabs // open search type dropdown menu cy.findByRole('button', { name: 'Types (3)' }).click(); - // uncheck investigation + cy.findByRole('listbox').within(() => { cy.findByRole('checkbox', { name: 'Dataset checkbox' }).click(); cy.findByRole('checkbox', { name: 'Datafile checkbox' }).click(); @@ -40,33 +17,33 @@ describe('Investigation search tab', () => { it('should perform search query and show search results correctly', () => { // type in search query - cy.findByRole('searchbox', { name: 'Search text input' }).type('carbon'); + cy.findByRole('searchbox', { name: 'Search text input' }).type('dog'); // uncheck my data cy.findByRole('checkbox', { name: 'My data' }).click(); // click on search button cy.findByRole('button', { name: 'Submit search' }).click(); cy.findByRole('tab', { name: 'Investigation' }).within(() => { - cy.findByText('6').should('exist'); + cy.findByText('5').should('exist'); }); - // expecting 7 rows, 6 for search results, 1 for the header row - cy.findAllByRole('row').should('have.length', 7); + // expecting 6 rows, 5 for search results, 1 for the header row + cy.findAllByRole('row').should('have.length', 6); cy.findByRole('button', { name: 'Toggle Type filter panel' }).click(); cy.findAllByLabelText('Type filter panel') .filter(':visible') .within(() => { - cy.findByRole('button', { name: 'Add experiment filter' }) + cy.findByRole('button', { name: 'Add INVESTIGATIONTYPE 2 filter' }) .should('exist') .within(() => { - cy.findByText('191').should('exist'); + cy.findByText('3').should('exist'); }); - cy.findByRole('button', { name: 'Add calibration filter' }) + cy.findByRole('button', { name: 'Add INVESTIGATIONTYPE 1 filter' }) .should('exist') .within(() => { - cy.findByText('109').should('exist'); + cy.findByText('2').should('exist'); }); }); @@ -76,52 +53,88 @@ describe('Investigation search tab', () => { cy.findAllByLabelText('Parameter name filter panel') .filter(':visible') .within(() => { - cy.findByRole('button', { name: 'Add bcat_inv_str filter' }) + cy.findByRole('button', { name: 'Add PARAMETERTYPE 2 filter' }) + .should('exist') + .within(() => { + cy.findByText('2').should('exist'); + }); + + cy.findByRole('button', { name: 'Add PARAMETERTYPE 11 filter' }) + .should('exist') + .within(() => { + cy.findByText('1').should('exist'); + }); + }); + + cy.findByRole('button', { + name: 'Toggle Sample filter panel', + }).click(); + cy.findAllByLabelText('Sample filter panel') + .filter(':visible') + .within(() => { + cy.findByRole('button', { name: 'Add SAMPLETYPE 38 filter' }) + .should('exist') + .within(() => { + cy.findByText('1').should('exist'); + }); + }); + + cy.findByRole('button', { + name: 'Toggle Instrument filter panel', + }).click(); + cy.findAllByLabelText('Instrument filter panel') + .filter(':visible') + .within(() => { + cy.findByRole('button', { name: 'Add INSTRUMENT 8 filter' }) .should('exist') .within(() => { - cy.findByText('241').should('exist'); + cy.findByText('2').should('exist'); }); - cy.findByRole('button', { name: 'Add run_number_range filter' }) + cy.findByRole('button', { name: 'Add INSTRUMENT 14 filter' }) .should('exist') .within(() => { - cy.findByText('189').should('exist'); + cy.findByText('1').should('exist'); }); }); }); it('should be able to open the details panel of a specific row', () => { // type in search query - cy.findByRole('searchbox', { name: 'Search text input' }).type('carbon'); + cy.findByRole('searchbox', { name: 'Search text input' }).type('dog'); // uncheck my data cy.findByRole('checkbox', { name: 'My data' }).click(); // click on search button cy.findByRole('button', { name: 'Submit search' }).click(); - // 7 rows, 6 for search results, 1 for the header row - cy.findAllByRole('row').should('have.length', 7); + // 6 rows, 5 for search results, 1 for the header row + cy.findAllByRole('row').should('have.length', 6); cy.findAllByRole('row') .eq(1) .within(() => { cy.findByRole('button', { name: 'Show details' }).click(); }); + + cy.findByTestId('investigation-details-panel').within(() => { + cy.findByText('Majority about dog idea bag summer', { + exact: false, + }).should('exist'); + cy.findByText('02/02/2013').should('exist'); + cy.findByText('INVESTIGATION 52').should('exist'); + }); }); it('should be able to add/remove to/from download cart', () => { // type in search query - cy.findByRole('searchbox', { name: 'Search text input' }).type('carbon'); + cy.findByRole('searchbox', { name: 'Search text input' }).type('dog'); // uncheck my data cy.findByRole('checkbox', { name: 'My data' }).click(); // click on search button cy.findByRole('button', { name: 'Submit search' }).click(); - // 7 rows, 6 for search results, 1 for the header row - cy.findAllByRole('row').should('have.length', 7); - - cy.intercept(`**/topcat/user/cart/${facilityName}/cartItems`, { - fixture: 'downloadCartItems.json', - }); + // 6 rows, 5 for search results, 1 for the header row + cy.findAllByRole('row').should('have.length', 6); cy.findAllByRole('row') .eq(1) @@ -130,12 +143,6 @@ describe('Investigation search tab', () => { cy.findByRole('checkbox').should('be.checked'); }); - cy.intercept(`**/topcat/user/cart/${facilityName}/cartItems`, { - body: { - cartItems: [], - }, - }); - cy.findAllByRole('row') .eq(1) .within(() => { @@ -146,14 +153,13 @@ describe('Investigation search tab', () => { it('should be able to filter search results by facets', () => { // type in search query - cy.findByRole('searchbox', { name: 'Search text input' }).type('carbon'); + cy.findByRole('searchbox', { name: 'Search text input' }).type('dog'); // uncheck my data cy.findByRole('checkbox', { name: 'My data' }).click(); // click on search button cy.findByRole('button', { name: 'Submit search' }).click(); - // 7 rows, 6 for search results, 1 for the header row - cy.findAllByRole('row').should('have.length', 7); + cy.findAllByRole('row').should('have.length', 6); // open the filter panel, then select some filters cy.findByRole('button', { name: 'Toggle Type filter panel' }).click(); @@ -163,26 +169,29 @@ describe('Investigation search tab', () => { .filter(':visible') .within(() => { cy.findByRole('button', { - name: 'Add experiment filter', - }).click(); - - cy.findByRole('button', { - name: 'Add experiment filter', - }).within(() => { + name: 'Add INVESTIGATIONTYPE 2 filter', + }) + .as('filter') + .click(); + cy.get('@filter').within(() => { cy.findByRole('checkbox').should('be.checked'); }); }); - // intercept search request to return predefined filtered search result - cy.intercept('**/search/documents*', { - fixture: 'filteredInvestigationSearchResults.json', - }); - // apply the filter - cy.findAllByRole('button', { name: 'Apply' }).filter(':visible').click(); + cy.findAllByRole('button', { name: 'Apply' }).click(); // the search result should be filtered - cy.findAllByRole('row').should('have.length', 2); + cy.findAllByRole('row').should('have.length', 4); + + // check that filter chips are displayed + cy.findByTestId('tabpanel-datafile').within(() => { + cy.findByLabelText('Selected filters') + .should('exist') + .within(() => { + cy.findByText('Type: INVESTIGATIONTYPE 2').should('exist'); + }); + }); // open the filter panel to check that the filter is selected cy.findByRole('button', { name: 'Toggle Type filter panel' }).click(); @@ -190,156 +199,157 @@ describe('Investigation search tab', () => { .filter(':visible') .within(() => { cy.findByRole('button', { - name: 'Remove experiment filter', + name: 'Remove INVESTIGATIONTYPE 2 filter', }).within(() => { cy.findByRole('checkbox').should('be.checked'); - cy.findByText('191').should('exist'); }); - - cy.findByRole('button', { name: 'Add calibration filter' }).should( - 'not.exist' - ); }); + // open another filter panel to see the panel shows the updated list of filters cy.findByRole('button', { name: 'Toggle Parameter name filter panel', }).click(); cy.findAllByLabelText('Parameter name filter panel') .filter(':visible') .within(() => { - cy.findByRole('button', { name: 'Add bcat_inv_str filter' }) - .should('exist') - .within(() => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('241').should('exist'); - }); + // the filtered search results don't include this facet + cy.findByRole('button', { + name: 'Add PARAMETERTYPE 11 filter', + }).should('not.exist'); - cy.findByRole('button', { name: 'Add run_number_range filter' }).should( - 'not.exist' - ); + cy.findByRole('button', { + name: 'Add PARAMETERTYPE 2 filter', + }).within(() => { + cy.findByRole('checkbox').should('not.be.checked'); + cy.findByRole('checkbox').click(); + }); }); + cy.findByRole('button', { name: 'Apply' }).click(); + + cy.findAllByRole('row').should('have.length', 2); + + // remove both filters, one by deselecting the filter, one via removing the chip + // check that filter chips are displayed cy.findByTestId('tabpanel-investigation').within(() => { cy.findByLabelText('Selected filters') .should('exist') .within(() => { - cy.findByText('Type: experiment').should('exist'); + cy.findByRole('button', { + name: 'Parameter name: PARAMETERTYPE 2', + exact: false, + }).should('exist'); + cy.findByRole('button', { + name: 'Type: INVESTIGATIONTYPE 2', + exact: false, + }) + .should('exist') + .within(() => { + // remove the filter chip + cy.findByTestId('CancelIcon').click(); + }); }); }); - // try to remove the filter - cy.findAllByLabelText('Type filter panel') + cy.findAllByRole('row').should('have.length', 3); + + cy.findByRole('button', { + name: 'Toggle Parameter name filter panel', + }).click(); + cy.findAllByLabelText('Parameter name filter panel') .filter(':visible') .within(() => { cy.findByRole('button', { - name: 'Remove experiment filter', + name: 'Remove PARAMETERTYPE 2 filter', }).click(); }); - cy.intercept('**/search/documents*', { - fixture: 'investigationSearchResults.json', - }); - - // apply the changes cy.findByRole('button', { name: 'Apply' }).click(); - // 7 rows, 6 for search results, 1 for the header row - cy.findAllByRole('row').should('have.length', 7); + cy.findAllByRole('row').should('have.length', 6); // filter chips should not exist anymore - cy.findByTestId('tabpanel-investigation').within(() => { + cy.findByTestId('tabpanel-datafile').within(() => { cy.findByLabelText('Selected filters') .children() .should('have.length', 0); }); - // open the filter panel to check that the filter is not selected anymore - cy.findByRole('button', { name: 'Toggle Type filter panel' }).click(); - cy.findAllByLabelText('Type filter panel') + cy.findAllByLabelText('Parameter name filter panel') .filter(':visible') .within(() => { - cy.findByRole('button', { - name: 'Add experiment filter', - }).within(() => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('191').should('exist'); - }); + cy.findByRole('button', { name: 'Add PARAMETERTYPE 2 filter' }) + .should('exist') + .within(() => { + cy.findByRole('checkbox').should('not.be.checked'); + cy.findByText('2').should('exist'); + }); - cy.findByRole('button', { name: 'Add calibration filter' }).within( - () => { + cy.findByRole('button', { name: 'Add PARAMETERTYPE 11 filter' }) + .should('exist') + .within(() => { cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('109').should('exist'); - } - ); + cy.findByText('1').should('exist'); + }); }); cy.findByRole('button', { name: 'Toggle Parameter name filter panel', }).click(); - cy.findAllByLabelText('Parameter name filter panel') + + cy.findByRole('button', { + name: 'Toggle Type filter panel', + }).click(); + + cy.findAllByLabelText('Type filter panel') .filter(':visible') .within(() => { - cy.findByRole('button', { name: 'Add bcat_inv_str filter' }) - .should('exist') - .within(() => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('241').should('exist'); - }); - - cy.findByRole('button', { name: 'Add run_number_range filter' }) + cy.findByRole('button', { name: 'Add INVESTIGATIONTYPE 2 filter' }) .should('exist') .within(() => { cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('189').should('exist'); + cy.findByText('3').should('exist'); }); }); - }); - it('should allow filters to be removed by removing filter chips', () => { - // type in search query - cy.findByRole('searchbox', { name: 'Search text input' }).type('carbon'); - // uncheck my data - cy.findByRole('checkbox', { name: 'My data' }).click(); - // click on search button - cy.findByRole('button', { name: 'Submit search' }).click(); - - // 7 rows, 6 for search results, 1 for the header row - cy.findAllByRole('row').should('have.length', 7); + cy.findByRole('button', { + name: 'Toggle Type filter panel', + }).click(); - // open the filter panel, then select some filters - cy.findByRole('button', { name: 'Toggle Type filter panel' }).click(); + cy.findByRole('button', { + name: 'Toggle Sample filter panel', + }).click(); // select the filter we want - cy.findAllByLabelText('Type filter panel') + cy.findAllByLabelText('Sample filter panel') .filter(':visible') .within(() => { cy.findByRole('button', { - name: 'Add experiment filter', - }).click(); + name: 'Add SAMPLETYPE 38 filter', + }) + .as('filter') + .click(); + cy.get('@filter').within(() => { + cy.findByRole('checkbox').should('be.checked'); + }); }); - // intercept search request to return predefined filtered search result - cy.intercept('**/search/documents*', { - fixture: 'filteredInvestigationSearchResults.json', - }); - // apply the filter - cy.findAllByRole('button', { name: 'Apply' }).filter(':visible').click(); + cy.findAllByRole('button', { name: 'Apply' }).click(); // the search result should be filtered cy.findAllByRole('row').should('have.length', 2); - cy.intercept('**/search/documents*', { - fixture: 'investigationSearchResults.json', - }); - // check that filter chips are displayed cy.findByTestId('tabpanel-investigation').within(() => { cy.findByLabelText('Selected filters') .should('exist') .within(() => { - cy.findByRole('button', { name: 'Type: experiment' }) + cy.findByRole('button', { + name: 'Sample: SAMPLETYPE 38', + exact: false, + }) .should('exist') .within(() => { // remove the filter chip @@ -348,65 +358,187 @@ describe('Investigation search tab', () => { }); }); + cy.findByRole('button', { + name: 'Toggle Instrument filter panel', + }).click(); + + // select the filter we want + cy.findAllByLabelText('Instrument filter panel') + .filter(':visible') + .within(() => { + cy.findByRole('button', { + name: 'Add INSTRUMENT 8 filter', + }) + .as('filter') + .click(); + cy.get('@filter').within(() => { + cy.findByRole('checkbox').should('be.checked'); + }); + }); + + // apply the filter + cy.findAllByRole('button', { name: 'Apply' }).click(); + // the search result should be filtered - cy.findAllByRole('row').should('have.length', 7); + cy.findAllByRole('row').should('have.length', 3); - // filter chips should not exist anymore + // check that filter chips are displayed cy.findByTestId('tabpanel-investigation').within(() => { cy.findByLabelText('Selected filters') - .children() - .should('have.length', 0); + .should('exist') + .within(() => { + cy.findByText('Instrument: INSTRUMENT 8').should('exist'); + }); }); + }); - // open the filter panel to check that the filter is not selected anymore - cy.findByRole('button', { name: 'Toggle Type filter panel' }).click(); - cy.findAllByLabelText('Type filter panel') - .filter(':visible') + it('should be able to filter search results by parameter filters', () => { + // type in search query + cy.findByRole('searchbox', { name: 'Search text input' }).type('dog'); + // uncheck my data + cy.findByRole('checkbox', { name: 'My data' }).click(); + // click on search button + cy.findByRole('button', { name: 'Submit search' }).click(); + + cy.findAllByRole('row').should('have.length', 6); + + cy.findByRole('button', { + name: 'Toggle Parameter name filter panel', + }).click(); + cy.findByText('Parameter filters') + .parent() .within(() => { - cy.findByRole('button', { - name: 'Add experiment filter', - }).within(() => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('191').should('exist'); + cy.findByRole('button', { name: 'Add' }).click(); + }); + + cy.findByRole('button', { name: /Parameter name /i }).click(); + + // numeric parameter + cy.findByRole('option', { name: 'PARAMETERTYPE 2' }).click(); + + cy.findByRole('button', { name: /Parameter type /i }).click(); + + cy.findByRole('option', { name: 'Numeric' }).click(); + + cy.findByRole('spinbutton', { name: 'Minimum value' }).type('5'); + + cy.findByRole('spinbutton', { name: 'Maximum value' }).type('10'); + + cy.findByRole('button', { name: 'Add filter' }).click(); + + cy.findByRole('button', { name: 'Apply' }).click(); + + cy.findAllByRole('row').should('have.length', 2); + + // check that filter chips are displayed & remove + cy.findByTestId('tabpanel-investigation').within(() => { + cy.findByLabelText('Selected filters') + .should('exist') + .within(() => { + cy.findByRole('button', { + name: 'PARAMETERTYPE 2: 5 to 10', + exact: false, + }) + .should('exist') + .within(() => { + cy.findByTestId('CancelIcon').click(); + }); }); + }); - cy.findByRole('button', { name: 'Add calibration filter' }).within( - () => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('109').should('exist'); - } - ); + cy.findByRole('button', { + name: 'Toggle Parameter name filter panel', + }).click(); + cy.findByText('Parameter filters') + .parent() + .within(() => { + cy.findByRole('button', { name: 'Add' }).click(); }); + cy.findByRole('button', { name: /Parameter name /i }).click(); + + // string parameter + cy.findByRole('option', { name: 'PARAMETERTYPE 47' }).click(); + + cy.findByRole('button', { name: /Parameter type /i }).click(); + + cy.findByRole('option', { name: 'String' }).click(); + + cy.findByRole('button', { name: /Parameter equals /i }).click(); + + cy.findByRole('option', { name: /value 47/i }).click(); + + cy.findByRole('button', { name: 'Add filter' }).click(); + + cy.findByRole('button', { name: 'Apply' }).click(); + + cy.findAllByRole('row').should('have.length', 2); + + // check that filter chips are displayed & remove + cy.findByTestId('tabpanel-investigation').within(() => { + cy.findByLabelText('Selected filters') + .should('exist') + .within(() => { + cy.findByRole('button', { + name: 'PARAMETERTYPE 47: value 47', + exact: false, + }) + .should('exist') + .within(() => { + cy.findByTestId('CancelIcon').click(); + }); + }); + }); + cy.findByRole('button', { name: 'Toggle Parameter name filter panel', }).click(); - cy.findAllByLabelText('Parameter name filter panel') - .filter(':visible') + cy.findByText('Parameter filters') + .parent() .within(() => { - cy.findByRole('button', { name: 'Add bcat_inv_str filter' }) - .should('exist') - .within(() => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('241').should('exist'); - }); - - cy.findByRole('button', { name: 'Add run_number_range filter' }) - .should('exist') - .within(() => { - cy.findByRole('checkbox').should('not.be.checked'); - cy.findByText('189').should('exist'); - }); + cy.findByRole('button', { name: 'Add' }).click(); }); + + cy.findByRole('button', { name: /Parameter name /i }).click(); + + // datetime parameter + cy.findByRole('option', { name: 'PARAMETERTYPE 25' }).click(); + + cy.findByRole('button', { name: /Parameter type /i }).click(); + + cy.findByRole('option', { name: 'Date and time' }).click(); + + cy.findByRole('button', { name: /Parameter is in /i }).click(); + + cy.findByRole('option', { name: /Older/i }).click(); + + cy.findByRole('button', { name: 'Add filter' }).click(); + + cy.findByRole('button', { name: 'Apply' }).click(); + + cy.findAllByRole('row').should('have.length', 2); + + // check that filter chips are displayed + cy.findByTestId('tabpanel-investigation').within(() => { + cy.findByLabelText('Selected filters') + .should('exist') + .within(() => { + cy.findByRole('button', { + name: 'PARAMETERTYPE 25: Older', + exact: false, + }).should('exist'); + }); + }); }); it('should link to an investigation', () => { - cy.get('#filled-search').type('dog'); + // type in search query + cy.findByRole('searchbox', { name: 'Search text input' }).type('dog'); + // uncheck my data + cy.findByRole('checkbox', { name: 'My data' }).click(); + // click on search button + cy.findByRole('button', { name: 'Submit search' }).click(); - cy.get('[aria-label="Submit search"]').click(); - cy.wait(['@investigations'], { - timeout: 10000, - }); - cy.get('[href="/browse/investigation/6/dataset"]'); + cy.get('[href="/browse/investigation/3/dataset"]'); }); });