Skip to content

Commit

Permalink
Merge pull request #96 from ministryofjustice/fix/cypress-build-failure
Browse files Browse the repository at this point in the history
(Hopefully) Fix Cypress build failure
  • Loading branch information
Gweaton committed Feb 3, 2021
2 parents 8604425 + 084c7c9 commit 493bb55
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 328 deletions.
24 changes: 24 additions & 0 deletions integration_tests/support/commands.js
Expand Up @@ -6,3 +6,27 @@ Cypress.Commands.add('login', () => {
Cypress.Commands.add('withinFieldsetThatContains', (text, action) => {
cy.contains(text).parent('fieldset').within(action)
})

const getTable = (subject, options = {}) => {
if (subject.get().length > 1) {
throw new Error(`Selector "${subject.selector}" returned more than 1 element.`)
}

const tableElement = subject.get()[0]
const headers = [...tableElement.querySelectorAll('thead th')].map(e => e.textContent)

const rows = [...tableElement.querySelectorAll('tbody tr')].map(row => {
return [...row.querySelectorAll('td')].map(e => e.textContent)
})

return rows.map(row =>
row.reduce((acc, curr, index) => {
if (options.onlyColumns && !options.onlyColumns.includes(headers[index])) {
return { ...acc }
}
return { ...acc, [headers[index]]: curr }
}, {})
)
}

Cypress.Commands.add('getTable', { prevSubject: true }, getTable)
2 changes: 0 additions & 2 deletions integration_tests/support/index.js
@@ -1,5 +1,3 @@
import './commands'
import './interventionsServiceStubs'
import './communityApiStubs'

require('cypress-get-table')
325 changes: 0 additions & 325 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -143,7 +143,6 @@
"@typescript-eslint/parser": "^4.4.1",
"concurrently": "^5.3.0",
"cypress": "^6.2.1",
"cypress-get-table": "^1.0.1",
"cypress-multi-reporters": "^1.4.0",
"eslint": "^7.11.0",
"eslint-config-airbnb-base": "^14.2.0",
Expand Down

0 comments on commit 493bb55

Please sign in to comment.