Skip to content

Commit

Permalink
Minor test cleanup. Ensure artifacts are available based on e2e searc…
Browse files Browse the repository at this point in the history
…h results
  • Loading branch information
tdonohue committed Aug 27, 2021
1 parent fbfd4a2 commit 3c3f225
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
33 changes: 19 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,8 @@ jobs:
docker-compose -f ./docker/cli.yml -f ./docker/cli.assetstore.yml run --rm dspace-cli
docker container ls
# Wait until the REST API returns a 200 response (or for a max of 30 seconds)
# https://github.com/nev7n/wait_for_response
#- name: Wait for DSpace REST Backend to be ready (for e2e tests)
# uses: nev7n/wait_for_response@v1
# with:
# We use the 'sites' endpoint to also ensure the database is ready
# url: 'http://localhost:8080/server/api/core/sites'
# responseCode: 200
# timeout: 30000

#- name: Get DSpace REST Backend info/properties
# run: curl http://localhost:8080/server/api

# Run integration tests via Cypress.io
# NOTE: to run these e2e tests locally, just use 'ng e2e'
# (NOTE: to run these e2e tests locally, just use 'ng e2e')
- name: Run e2e tests (integration tests)
uses: cypress-io/github-action@v2
with:
Expand All @@ -128,6 +115,24 @@ jobs:
# Wait for 2 mins max for everything to respond
wait-on-timeout: 120

# Cypress always creates a video of all e2e tests (whether they succeeded or failed)
# Save those in an Artifact
- name: Upload e2e test videos to Artifacts
uses: actions/upload-artifact@v1
if: always()
with:
name: e2e-test-videos
path: cypress/videos

# If e2e tests fail, Cypress creates a screenshot of what happened
# Save those in an Artifact
- name: Upload e2e test failure screenshots to Artifacts
uses: actions/upload-artifact@v1
if: failure()
with:
name: e2e-test-screenshots
path: cypress/screenshots

# Start up the app with SSR enabled (run in background)
- name: Start app in SSR (server-side rendering) mode
run: |
Expand Down
7 changes: 4 additions & 3 deletions cypress/integration/item-statistics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe('Item Statistics Page', () => {
const ITEMSTATISTICSPAGE = '/statistics/items/e98b0f27-5c19-49a0-960d-eb6ad5287067';
const ITEMUUID = 'e98b0f27-5c19-49a0-960d-eb6ad5287067';
const ITEMSTATISTICSPAGE = '/statistics/items/' + ITEMUUID;

it('should contain element ds-item-statistics-page when navigating to an item statistics page', () => {
cy.visit(ITEMSTATISTICSPAGE);
Expand All @@ -14,11 +15,11 @@ describe('Item Statistics Page', () => {

it('should contain a "Total visits" section', () => {
cy.visit(ITEMSTATISTICSPAGE);
cy.get('ds-statistics-table h3').contains('Total visits');
cy.get('.' + ITEMUUID + '_TotalVisits').should('exist');
});

it('should contain a "Total visits per month" section', () => {
cy.visit(ITEMSTATISTICSPAGE);
cy.get('ds-statistics-table h3').contains('Total visits per month');
cy.get('.' + ITEMUUID + '_TotalVisitsPerMonth').should('exist');
});
});
3 changes: 2 additions & 1 deletion cypress/integration/pagenotfound.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe('PageNotFound', () => {
it('should contain element ds-pagenotfound when navigating to page that doesnt exist', () => {
cy.visit('/e9019a69-d4f1-4773-b6a3-bd362caa46f2');
// request an invalid page (UUIDs at root path aren't valid)
cy.visit('/e9019a69-d4f1-4773-b6a3-bd362caa46f2', { failOnStatusCode: false });
cy.get('ds-pagenotfound').should('exist');
});

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/search-navbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const page = {
fillOutQueryInNavBar(query) {
// Click the magnifying glass
cy.get('.navbar-container #search-navbar-container form a').click();
// Fill out a query and click Enter
// Fill out a query in input that appears
cy.get('.navbar-container #search-navbar-container form input[name = "query"]').type(query);
},
submitQueryByPressingEnter() {
Expand Down
21 changes: 12 additions & 9 deletions cypress/integration/search-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
describe('Search Page', () => {
// unique ID of the search form (for selecting specific elements below)
const SEARCHFORM_ID = '#search-form';

it('should contain query value when navigating to page with query parameter', () => {
const queryString = 'test query';
cy.visit('/search?query=' + queryString);
cy.get('#search-form input').should('have.value', queryString);
cy.get(SEARCHFORM_ID + ' input[name="query"]').should('have.value', queryString);
});


it('should have right scope selected when navigating to page with scope parameter', () => {
// First, visit search with no params just to get the set of the scope options
cy.visit('/search');
cy.get('#search-form select[name="scope"] > option').as('options');
cy.get(SEARCHFORM_ID + ' select[name="scope"] > option').as('options');

// Find length of scope options, select a random index
cy.get('@options').its('length')
Expand All @@ -24,15 +26,15 @@ describe('Search Page', () => {
// Visit the search page with the randomly selected option as a pararmeter
cy.visit('/search?scope=' + randomScope);
// Verify that scope is selected when the page reloads
cy.get('#search-form select[name="scope"]').find('option:selected').should('have.value', randomScope);
cy.get(SEARCHFORM_ID + ' select[name="scope"]').find('option:selected').should('have.value', randomScope);
});
});


it('should redirect to the correct url when scope was set and submit button was triggered', () => {
// First, visit search with no params just to get the set of scope options
cy.visit('/search');
cy.get('#search-form select[name="scope"] > option').as('options');
cy.get(SEARCHFORM_ID + ' select[name="scope"] > option').as('options');

// Find length of scope options, select a random index (i.e. a random option in selectbox)
cy.get('@options').its('length')
Expand All @@ -44,19 +46,20 @@ describe('Search Page', () => {
.then((option) => {
const randomScope: any = option.val();
// Select the option at our random index & click the search button
cy.get('#search-form select[name="scope"]').select(randomScope);
cy.get('#search-form button.search-button').click();
cy.get(SEARCHFORM_ID + ' select[name="scope"]').select(randomScope);
cy.get(SEARCHFORM_ID + ' button.search-button').click();
// Result should be the page URL should include that scope & page will reload with scope selected
cy.url().should('include', 'scope=' + randomScope);
cy.get('#search-form select[name="scope"]').find('option:selected').should('have.value', randomScope);
cy.get(SEARCHFORM_ID + ' select[name="scope"]').find('option:selected').should('have.value', randomScope);
});
});

it('should redirect to the correct url when query was set and submit button was triggered', () => {
const queryString = 'Another interesting query string';
cy.visit('/search');
cy.get('#search-form input[name="query"]').type(queryString);
cy.get('#search-form button.search-button').click();
// Type query in searchbox & click search button
cy.get(SEARCHFORM_ID + ' input[name="query"]').type(queryString);
cy.get(SEARCHFORM_ID + ' button.search-button').click();
cy.url().should('include', 'query=' + encodeURI(queryString));
});

Expand Down

0 comments on commit 3c3f225

Please sign in to comment.