Skip to content

Commit

Permalink
Merge pull request #159 from ddjnw1yu/testing-updates
Browse files Browse the repository at this point in the history
Testing updates
  • Loading branch information
alan-wu authored Jul 17, 2024
2 parents 43d7f03 + 0fe69a0 commit ed419db
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 286 deletions.
35 changes: 22 additions & 13 deletions tests/cypress/e2e/databrowser.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { retryableBefore } from "../support/retryableBefore.js"
import { stringToArray } from "../support/stringToArray.js"

const browseCategories = ['dataset', 'model', 'simulation']

Expand All @@ -10,25 +11,25 @@ const pageLimit = Cypress.env('PAGE_LIMIT')
/**
* List of keywords
*/
const searchKeywords = [...new Set(Cypress.env('SEARCH_KEYWORDS').split(',').map(item => item.trim()).filter(item => item))]
const searchKeywords = stringToArray(Cypress.env('SEARCH_KEYWORDS'), ',')

let filterFacets = []
/**
* Single facet
*/
const filterFacet = [...new Set(Cypress.env('FILTER_FACET').split(',').map(item => item.trim()).filter(item => item))]
const filterFacet = stringToArray(Cypress.env('FILTER_FACET'), ',')
if (filterFacet && filterFacet.length === 1) {
filterFacets.push(filterFacet)
}
/**
* List of facets
*/
const multipleFilterFacets = [...new Set(Cypress.env('MULTIPLE_FILTER_FACETS').split(',').map(item => item.trim()).filter(item => item))]
const multipleFilterFacets = stringToArray(Cypress.env('MULTIPLE_FILTER_FACETS'), ',')
if (multipleFilterFacets && multipleFilterFacets.length > 1) {
filterFacets.push(multipleFilterFacets)
}

browseCategories.forEach((category) => {
browseCategories.forEach((category, bcIndex) => {

describe(`Find Data in ${category}`, { testIsolation: false }, function () {
retryableBefore(function () {
Expand Down Expand Up @@ -141,19 +142,20 @@ browseCategories.forEach((category) => {
cy.waitForLoadingMask()

// Check for result
cy.get(':nth-child(1) > p').then(($result) => {
if ($result.text().includes(' 0 Results | Showing')) {
cy.get('.el-col-md-16 > :nth-child(1) > p').then(($result) => {
if ($result.text().match(/^0 Results \| Showing/i)) {
// Empty text should exist if no result
cy.get('.el-table__empty-text').should('exist').and('have.text', 'No Results')
this.skip()
} else {
cy.get('.table-wrap').then(($content) => {
const keywordExist = $content.text().toLowerCase().includes(keyword.toLowerCase())
if (keywordExist) {
// Check for keyword
cy.wrap($content).contains(new RegExp(keyword, 'i')).should('exist')
cy.wrap($content).contains(new RegExp(`^${keyword}$`, 'i')).should('exist')

// Check for highlighted keyword
cy.get('b').contains(new RegExp(keyword, 'i')).should('exist')
cy.get('b').contains(new RegExp(`^${keyword}$`, 'i')).should('exist')
} else {
// *** Ignore when keyword cannot be found or
// *** Find some other solutions in the future
Expand All @@ -172,6 +174,13 @@ browseCategories.forEach((category) => {
filterFacets.forEach((facetList) => {

it(`Faceted Browse Search - ${facetList}`, function () {
// Clear search input
cy.url().then((url) => {
if (url.includes('search=')) {
cy.get('.nuxt-icon.nuxt-icon--fill.body1.close-icon').click()
}
})

// Check for filters applied box
cy.get('.no-facets').should('contain', 'No filters applied')

Expand Down Expand Up @@ -205,7 +214,7 @@ browseCategories.forEach((category) => {
})

// Check for the number of facet tags in filters applied box
cy.get('.el-card__body > .capitalize:visible').contains(new RegExp(facet, 'i')).should('exist')
cy.get('.el-card__body > .capitalize:visible').contains(new RegExp(`^${facet}$`, 'i')).should('exist')
})

// Check for URL
Expand All @@ -215,8 +224,8 @@ browseCategories.forEach((category) => {
cy.waitForLoadingMask()

// Check for result correctness
cy.get(':nth-child(1) > p').then(($result) => {
if ($result.text().includes('0 Results | Showing')) {
cy.get('.el-col-md-16 > :nth-child(1) > p').then(($result) => {
if ($result.text().match(/^0 Results \| Showing/i)) {
// Empty text should exist if no result
cy.get('.el-table__empty-text').should('exist').and('have.text', 'No Results')
} else {
Expand All @@ -225,7 +234,7 @@ browseCategories.forEach((category) => {
facetList.forEach((facet) => {
const facetExistInCard = $content.text().toLowerCase().includes(facet.toLowerCase())
if (facetExistInCard) {
cy.wrap($content).contains(new RegExp(facet, 'i')).should('exist')
cy.wrap($content).contains(new RegExp(`^${facet}$`, 'i')).should('exist')
} else {
// *** Ignore when facets cannot be found or
// *** Find some other solutions in the future
Expand All @@ -236,7 +245,7 @@ browseCategories.forEach((category) => {
})

for (let index = 0; index < 2; index++) {
if (index === 1) {
if (bcIndex = 0 && index === 1) {
// Combine with search
cy.get('.el-input__inner').clear()
cy.get('.el-input__inner').type('dataset')
Expand Down
5 changes: 3 additions & 2 deletions tests/cypress/e2e/datasets.cy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { retryableBefore } from "../support/retryableBefore.js"
import { stringToArray } from "../support/stringToArray.js"

/**
* List of dataset ids
*/
const datasetIds = [...new Set(Cypress.env('DATASET_IDS').split(',').map(item => item.trim()).filter(item => item))]
const datasetIds = stringToArray(Cypress.env('DATASET_IDS'), ',')

datasetIds.forEach(datasetId => {

Expand Down Expand Up @@ -157,7 +158,7 @@ datasetIds.forEach(datasetId => {
// Check for Experimental Design
cy.get('.dataset-description-info > .mb-8').contains('Experimental Design:').should('exist')
cy.get('.dataset-description-info').contains('Protocol Links:').should('exist')
cy.get('.dataset-description-info').within(($el) => {
cy.get('.dataset-description-info').contains(/Protocol Links:/i).parents('.experimental-design-container').within(($el) => {
if ($el.text().includes('https://doi.org/')) {
cy.get('.link2').should('exist')
cy.get('.link2').should('have.length.above', 0)
Expand Down
110 changes: 56 additions & 54 deletions tests/cypress/e2e/homepage.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ describe('Homepage', { testIsolation: false }, function () {
cy.visitLoadedPage('')
})

beforeEach(function () {
cy.intercept('**/query?**').as('query')
})

it(`Portal Target is ${Cypress.config().baseUrl}`, function () { })
it(`Testing Portal Target: ${Cypress.config().baseUrl}`, function () { })

it('Navigation Bar', function () {
// Check for navigation bar
Expand All @@ -22,34 +18,39 @@ describe('Homepage', { testIsolation: false }, function () {
})

it('Page hero', function () {
// Check for banner
cy.get('h1').should('contain', 'SPARC')
cy.get('[class="page-hero-img"]').should('exist')
// Check for page hero
cy.get('.page-hero').should('exist').within(() => {
// Check for content title
cy.get('h1').should('exist').and('contain', 'SPARC')

// Check for content description
cy.get('h5').should('exist')

// Check for content image
cy.get('[class="page-hero-img"]').should('exist').and('have.prop', 'naturalWidth').should('be.greaterThan', 0)
})
})

it('Featured data', function () {
it('SPARC by the numbers', function () {
// Check for content title
cy.get('.featured-data > .categories-container > h2').should('have.text', 'Find by')
cy.get('.container.p-32 > .heading2').should('exist').and('contain', 'SPARC by the numbers')

cy.wait(5000)

cy.get('.featured-data > .gallery > .resources-gallery-strip > .card-line > .key-image-span > .data-wrap > .data-item').as('category')
// Check for consortia
cy.get('.container.p-32 > .body1 > b > .heading2').first().should('exist').then(($el) => {
const numberOfConsortia = parseInt($el.text())

cy.get('@category').each(($cat) => {
cy.wrap($cat).should('have.attr', 'href').and('contain', 'selectedFacetIds')
cy.get('.container.p-32 > .data-wrap.py-16 > .consortia-item').should('have.length', numberOfConsortia)
cy.get('.container.p-32 > .data-wrap.py-16 > .consortia-item').should('have.attr', 'href').and('contain', '/about/consortia/')
})
cy.get('@category').first().click()

cy.wait('@query', { timeout: 20000 })
cy.waitForLoadingMask()

cy.url().should('contain', 'data?type=dataset&selectedFacetIds=')
cy.go('back')
// Check for contributor
cy.get('.container.p-32 > .body1 > b > .heading2').last().should('exist').then(($el) => {
const numberOfContributor = parseInt($el.text())
expect(numberOfContributor).to.be.greaterThan(0)

cy.waitForLoadingMask()

// Check for the number of categories
cy.get('@category').should('have.length', 6)
cy.get('.container.p-32 > .data-wrap.pt-16 > .consortia-item').should('have.length.above', 0)
cy.get('.container.p-32 > .data-wrap.pt-16 > .consortia-item').should('have.attr', 'href').and('contain', '/data?type=')
})
})

it('Portal features', function () {
Expand All @@ -64,26 +65,38 @@ describe('Homepage', { testIsolation: false }, function () {
cy.get('.button-link > .el-button > span').should('exist')
})

// Check for button function
cy.get(':nth-child(1) > .feature-container > .button-link > .el-button').click()
// Check for button link
cy.get(':nth-child(1) > .feature-container > .button-link').should('contain', 'Data and Models').and('have.attr', 'href', '/data?type=dataset')
cy.get(':nth-child(2) > .feature-container > .button-link').should('contain', 'Maps').and('have.attr', 'href', '/maps')
cy.get(':nth-child(3) > .feature-container > .button-link').should('contain', 'Discover').and('have.attr', 'href').and('contain', '/resources')
cy.get(':nth-child(4) > .feature-container > .button-link').should('contain', 'Submit').and('have.attr', 'href', '/share-data')
})

cy.wait('@query', { timeout: 20000 })
cy.waitForLoadingMask()
it('Find by', function () {
cy.get('.categories-container > .heading2').should('have.text', 'Find by')

cy.url().should('contain', 'data?type=dataset')
cy.get('.mobile-navigation > :nth-child(1) > :nth-child(1) > a', { timeout: 30000 }).should('have.class', 'active')
cy.go('back')
// Check for categories selection item
cy.get('.categories-container > .categories-select').click()
cy.get('.el-select-dropdown > .el-scrollbar > .el-select-dropdown__wrap > .el-select-dropdown__list > .el-select-dropdown__item').should('have.length.above', 0)
cy.get('.categories-container > .categories-select').click()

cy.waitForLoadingMask()
cy.wait(5000)

cy.get('.featured-data > .gallery > .resources-gallery-strip > .card-line > .key-image-span > .data-wrap > .data-item').should('have.attr', 'href').and('contain', '/data?type=dataset&selectedFacetIds=')

// Check for pagination
cy.get('.sparc-design-system-pagination').should('exist')
cy.get('.is-active').should('contain', '1')
cy.get('.btn-next').click()
cy.get('.is-active').should('contain', '2')
})

it('Projects and datasets', function () {
it('Resources and datasets', function () {
// Check for content title
cy.get('.section-container.py-32 > .heading2').should('contain', 'Resources & Datasets')

// Check for card description
cy.get('.row > :nth-child(1) > .mb-16').should('contain', 'you might be interested in:')
cy.get('.row > :nth-child(1) > .mb-16').should('contain', 'Here is a resource you might be interested in:')
cy.get('.row > :nth-child(2) > .mb-16').should('have.text', 'Featured Datasets')

// Check for card content
Expand All @@ -94,27 +107,16 @@ describe('Homepage', { testIsolation: false }, function () {
cy.get('.subpage-row > :nth-child(2) > .button-link > .el-button').should('exist')
})

// Check for card 'view all' link
cy.get('.row > :nth-child(1) > .view-all-link').should('contain', 'View All')
cy.get(':nth-child(2) > .view-all-link').should('contain', 'View All Datasets')

// Check for button redirect to dataset
cy.get(':nth-child(2) > .card-container > .subpage-row > :nth-child(2) > .dataset-name').then(($link) => {
const title = $link.text().replace('\n', '').trim()
cy.wrap($link).siblings('.button-link').click()

cy.wait('@query', { timeout: 20000 })
cy.waitForLoadingMask()
// Check for title redirect link
cy.get(':nth-child(1) > .card-container > .subpage-row > :nth-child(2) > .dataset-name').should('have.attr', 'href').and('contain', '/resources/')
cy.get(':nth-child(2) > .card-container > .subpage-row > :nth-child(2) > .dataset-name').should('have.attr', 'href').and('contain', '/datasets/')

cy.get('.el-col-sm-16 > .heading2').should('contain', title)
})
cy.go('back')

cy.waitForLoadingMask()
// Check for card 'view all' link
cy.get('.row > :nth-child(1) > .view-all-link').should('contain', 'View All Tools & Resources').and('have.attr', 'href', '/tools-and-resources/tools')
cy.get(':nth-child(2) > .view-all-link').should('contain', 'View All Datasets').and('have.attr', 'href', '/data?type=dataset')
})

it('Homepage news', function () {
cy.visitLoadedPage('')
it('News and upcoming events', function () {
// Check for content title
cy.get('.featured-datasets > .heading2').should('contain', 'News & Upcoming Events')

Expand All @@ -129,7 +131,7 @@ describe('Homepage', { testIsolation: false }, function () {
cy.get(':nth-child(2) > .el-button').should('contain', 'Learn More')

// Check for card 'view all' link
cy.get('.sparc-card__content-wrap__content > .view-all-link').should('exist')
cy.get('.sparc-card__content-wrap__content > .view-all-link').should('contain', 'View All News & Events').and('have.attr', 'href', '/news-and-events')
})

it('Stay connected', function () {
Expand Down
Loading

0 comments on commit ed419db

Please sign in to comment.