mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Jest fixes 47
This commit is contained in:
+36
-50
@@ -1,73 +1,62 @@
|
|||||||
const { defineConfig } = require("cypress");
|
const { defineConfig } = require('cypress')
|
||||||
const net = require("net");
|
const net = require('net')
|
||||||
|
|
||||||
const DEFAULT_DB_HOST =
|
const DEFAULT_DB_HOST = process.env.CYPRESS_DB_HOST ?? process.env.MARIADB_HOST ?? '127.0.0.1'
|
||||||
process.env.CYPRESS_DB_HOST ?? process.env.MARIADB_HOST ?? "127.0.0.1";
|
const DEFAULT_DB_PORT = Number(process.env.CYPRESS_DB_PORT ?? process.env.MARIADB_PORT ?? 3306)
|
||||||
const DEFAULT_DB_PORT = Number(
|
const DEFAULT_DB_WAIT_TIMEOUT_MS = Number(process.env.CYPRESS_DB_WAIT_TIMEOUT ?? 30_000)
|
||||||
process.env.CYPRESS_DB_PORT ?? process.env.MARIADB_PORT ?? 3306,
|
|
||||||
);
|
|
||||||
const DEFAULT_DB_WAIT_TIMEOUT_MS = Number(
|
|
||||||
process.env.CYPRESS_DB_WAIT_TIMEOUT ?? 30_000,
|
|
||||||
);
|
|
||||||
|
|
||||||
const RETRY_DELAY_MS = 1_000;
|
const RETRY_DELAY_MS = 1_000
|
||||||
const SOCKET_TIMEOUT_MS = 2_000;
|
const SOCKET_TIMEOUT_MS = 2_000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ host?: string; port?: number; timeoutMs?: number }} [options]
|
* @param {{ host?: string; port?: number; timeoutMs?: number }} [options]
|
||||||
* @param {{ dbHost?: string; dbPort?: number; dbWaitTimeoutMs?: number }} [env]
|
* @param {{ dbHost?: string; dbPort?: number; dbWaitTimeoutMs?: number }} [env]
|
||||||
*/
|
*/
|
||||||
async function waitForDatabase(options = {}, env = {}) {
|
async function waitForDatabase(options = {}, env = {}) {
|
||||||
const host = options.host ?? env.dbHost ?? DEFAULT_DB_HOST;
|
const host = options.host ?? env.dbHost ?? DEFAULT_DB_HOST
|
||||||
const port = Number(options.port ?? env.dbPort ?? DEFAULT_DB_PORT);
|
const port = Number(options.port ?? env.dbPort ?? DEFAULT_DB_PORT)
|
||||||
const timeoutMs = Number(
|
const timeoutMs = Number(options.timeoutMs ?? env.dbWaitTimeoutMs ?? DEFAULT_DB_WAIT_TIMEOUT_MS)
|
||||||
options.timeoutMs ?? env.dbWaitTimeoutMs ?? DEFAULT_DB_WAIT_TIMEOUT_MS,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!Number.isFinite(port)) {
|
if (!Number.isFinite(port)) {
|
||||||
throw new Error(`Invalid database port provided for waitForDbHealthy: ${port}`);
|
throw new Error(`Invalid database port provided for waitForDbHealthy: ${port}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deadline = Date.now() + timeoutMs;
|
const deadline = Date.now() + timeoutMs
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const attemptConnection = () => {
|
const attemptConnection = () => {
|
||||||
const socket = net.createConnection({ host, port });
|
const socket = net.createConnection({ host, port })
|
||||||
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
socket.removeAllListeners();
|
socket.removeAllListeners()
|
||||||
};
|
}
|
||||||
|
|
||||||
const scheduleRetry = (error) => {
|
const scheduleRetry = error => {
|
||||||
cleanup();
|
cleanup()
|
||||||
socket.destroy();
|
socket.destroy()
|
||||||
|
|
||||||
if (Date.now() >= deadline) {
|
if (Date.now() >= deadline) {
|
||||||
reject(
|
reject(new Error(`Timed out waiting for MariaDB at ${host}:${port} (${error.message})`))
|
||||||
new Error(
|
return
|
||||||
`Timed out waiting for MariaDB at ${host}:${port} (${error.message})`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(attemptConnection, RETRY_DELAY_MS);
|
setTimeout(attemptConnection, RETRY_DELAY_MS)
|
||||||
};
|
}
|
||||||
|
|
||||||
socket.once("connect", () => {
|
socket.once('connect', () => {
|
||||||
cleanup();
|
cleanup()
|
||||||
socket.end();
|
socket.end()
|
||||||
resolve(null);
|
resolve(null)
|
||||||
});
|
})
|
||||||
|
|
||||||
socket.once("error", scheduleRetry);
|
socket.once('error', scheduleRetry)
|
||||||
socket.setTimeout(SOCKET_TIMEOUT_MS, () => {
|
socket.setTimeout(SOCKET_TIMEOUT_MS, () => {
|
||||||
scheduleRetry(new Error("Connection attempt timed out"));
|
scheduleRetry(new Error('Connection attempt timed out'))
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
attemptConnection();
|
attemptConnection()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
@@ -86,17 +75,14 @@ module.exports = defineConfig({
|
|||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
baseUrl: 'http://localhost:5173/',
|
baseUrl: 'http://localhost:5173/',
|
||||||
specPattern: [
|
specPattern: ['cypress/e2e/**/*.cy.{js,jsx,ts,tsx}', 'cypress/e2e/**/*.spec.{js,jsx,ts,tsx}'],
|
||||||
'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
|
|
||||||
'cypress/e2e/**/*.spec.{js,jsx,ts,tsx}',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
databaseResetUrl: "http://localhost:4000/test/reset-test-database",
|
databaseResetUrl: 'http://localhost:4000/test/reset-test-database',
|
||||||
dbHost: DEFAULT_DB_HOST,
|
dbHost: DEFAULT_DB_HOST,
|
||||||
dbPort: DEFAULT_DB_PORT,
|
dbPort: DEFAULT_DB_PORT,
|
||||||
dbWaitTimeoutMs: DEFAULT_DB_WAIT_TIMEOUT_MS,
|
dbWaitTimeoutMs: DEFAULT_DB_WAIT_TIMEOUT_MS,
|
||||||
},
|
},
|
||||||
viewportHeight: 900,
|
viewportHeight: 900,
|
||||||
viewportWidth: 1200,
|
viewportWidth: 1200,
|
||||||
});
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Open each page, table view and detail view, and check at least some correct text appears', () => {
|
describe('Open each page, table view and detail view, and check at least some correct text appears', () => {
|
||||||
|
|||||||
+71
-66
@@ -21,8 +21,7 @@ const createRegion = (regionTarget: DeleteTarget, name: string) => {
|
|||||||
|
|
||||||
describe('Delete flow', () => {
|
describe('Delete flow', () => {
|
||||||
before('Wait for database and reset', () => {
|
before('Wait for database and reset', () => {
|
||||||
cy.task('waitForDbHealthy')
|
cy.resetDatabase()
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach('Login as delete-capable coordinator', () => {
|
beforeEach('Login as delete-capable coordinator', () => {
|
||||||
@@ -38,26 +37,28 @@ describe('Delete flow', () => {
|
|||||||
|
|
||||||
const name = regionName('Success')
|
const name = regionName('Success')
|
||||||
|
|
||||||
cy.wrap(null).then(() => createRegion(regionTarget, name)).then(createdId => {
|
cy.wrap(null)
|
||||||
cy.intercept('DELETE', `**/region/${createdId}`).as('deleteRegion')
|
.then(() => createRegion(regionTarget, name))
|
||||||
|
.then(createdId => {
|
||||||
|
cy.intercept('DELETE', `**/region/${createdId}`).as('deleteRegion')
|
||||||
|
|
||||||
cy.on('window:confirm', message => {
|
cy.on('window:confirm', message => {
|
||||||
expect(message).to.eq(regionTarget.confirmText)
|
expect(message).to.eq(regionTarget.confirmText)
|
||||||
return true
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get(regionTarget.deleteButton).click()
|
||||||
|
|
||||||
|
cy.wait('@deleteRegion').its('response.statusCode').should('be.oneOf', [200])
|
||||||
|
|
||||||
|
cy.contains('Deleted item successfully.').should('be.visible')
|
||||||
|
|
||||||
|
cy.url().should('include', '/region')
|
||||||
|
cy.contains(name).should('not.exist')
|
||||||
|
|
||||||
|
cy.visit(`/region/${createdId}`)
|
||||||
|
cy.contains('Error loading data')
|
||||||
})
|
})
|
||||||
|
|
||||||
cy.get(regionTarget.deleteButton).click()
|
|
||||||
|
|
||||||
cy.wait('@deleteRegion').its('response.statusCode').should('be.oneOf', [200])
|
|
||||||
|
|
||||||
cy.contains('Deleted item successfully.').should('be.visible')
|
|
||||||
|
|
||||||
cy.url().should('include', '/region')
|
|
||||||
cy.contains(name).should('not.exist')
|
|
||||||
|
|
||||||
cy.visit(`/region/${createdId}`)
|
|
||||||
cy.contains('Error loading data')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -70,33 +71,35 @@ describe('Delete flow', () => {
|
|||||||
|
|
||||||
const name = regionName('Cancel')
|
const name = regionName('Cancel')
|
||||||
|
|
||||||
cy.wrap(null).then(() => createRegion(regionTarget, name)).then(createdId => {
|
cy.wrap(null)
|
||||||
let deleteCallCount = 0
|
.then(() => createRegion(regionTarget, name))
|
||||||
cy.intercept('DELETE', `**/region/${createdId}`, req => {
|
.then(createdId => {
|
||||||
deleteCallCount += 1
|
let deleteCallCount = 0
|
||||||
req.reply({ statusCode: 500 })
|
cy.intercept('DELETE', `**/region/${createdId}`, req => {
|
||||||
}).as('deleteRegionCancel')
|
deleteCallCount += 1
|
||||||
|
req.reply({ statusCode: 500 })
|
||||||
|
}).as('deleteRegionCancel')
|
||||||
|
|
||||||
cy.on('window:confirm', message => {
|
cy.on('window:confirm', message => {
|
||||||
expect(message).to.eq(regionTarget.confirmText)
|
expect(message).to.eq(regionTarget.confirmText)
|
||||||
return false
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get(regionTarget.deleteButton).click()
|
||||||
|
|
||||||
|
cy.then(() => {
|
||||||
|
expect(deleteCallCount).to.eq(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.contains('Deleted item successfully.').should('not.exist')
|
||||||
|
cy.url().should('match', /\/region\/\d+$/)
|
||||||
|
cy.contains(name).should('be.visible')
|
||||||
|
|
||||||
|
cy.visit('/region')
|
||||||
|
cy.contains(name).should('be.visible')
|
||||||
|
cy.visit(`/region/${createdId}`)
|
||||||
|
cy.contains(name).should('be.visible')
|
||||||
})
|
})
|
||||||
|
|
||||||
cy.get(regionTarget.deleteButton).click()
|
|
||||||
|
|
||||||
cy.then(() => {
|
|
||||||
expect(deleteCallCount).to.eq(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
cy.contains('Deleted item successfully.').should('not.exist')
|
|
||||||
cy.url().should('match', /\/region\/\d+$/)
|
|
||||||
cy.contains(name).should('be.visible')
|
|
||||||
|
|
||||||
cy.visit('/region')
|
|
||||||
cy.contains(name).should('be.visible')
|
|
||||||
cy.visit(`/region/${createdId}`)
|
|
||||||
cy.contains(name).should('be.visible')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -110,29 +113,31 @@ describe('Delete flow', () => {
|
|||||||
const name = regionName('Failure')
|
const name = regionName('Failure')
|
||||||
const failureMessage = 'Test delete failure'
|
const failureMessage = 'Test delete failure'
|
||||||
|
|
||||||
cy.wrap(null).then(() => createRegion(regionTarget, name)).then(createdId => {
|
cy.wrap(null)
|
||||||
cy.intercept('DELETE', `**/region/${createdId}`, {
|
.then(() => createRegion(regionTarget, name))
|
||||||
statusCode: 500,
|
.then(createdId => {
|
||||||
body: { message: failureMessage },
|
cy.intercept('DELETE', `**/region/${createdId}`, {
|
||||||
}).as('deleteRegionFailure')
|
statusCode: 500,
|
||||||
|
body: { message: failureMessage },
|
||||||
|
}).as('deleteRegionFailure')
|
||||||
|
|
||||||
cy.on('window:confirm', message => {
|
cy.on('window:confirm', message => {
|
||||||
expect(message).to.eq(regionTarget.confirmText)
|
expect(message).to.eq(regionTarget.confirmText)
|
||||||
return true
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get(regionTarget.deleteButton).click()
|
||||||
|
|
||||||
|
cy.wait('@deleteRegionFailure').its('response.statusCode').should('eq', 500)
|
||||||
|
|
||||||
|
cy.contains(failureMessage).should('be.visible')
|
||||||
|
cy.contains('Deleted item successfully.').should('not.exist')
|
||||||
|
cy.url().should('match', /\/region\/\d+$/)
|
||||||
|
cy.contains(name).should('be.visible')
|
||||||
|
|
||||||
|
cy.visit('/region')
|
||||||
|
cy.contains(name).should('be.visible')
|
||||||
})
|
})
|
||||||
|
|
||||||
cy.get(regionTarget.deleteButton).click()
|
|
||||||
|
|
||||||
cy.wait('@deleteRegionFailure').its('response.statusCode').should('eq', 500)
|
|
||||||
|
|
||||||
cy.contains(failureMessage).should('be.visible')
|
|
||||||
cy.contains('Deleted item successfully.').should('not.exist')
|
|
||||||
cy.url().should('match', /\/region\/\d+$/)
|
|
||||||
cy.contains(name).should('be.visible')
|
|
||||||
|
|
||||||
cy.visit('/region')
|
|
||||||
cy.contains(name).should('be.visible')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Adding species in Locality -> Species tab for an existing locality', () => {
|
describe('Adding species in Locality -> Species tab for an existing locality', () => {
|
||||||
@@ -144,7 +144,6 @@ describe('Adding species in Locality -> Species tab for an existing locality', (
|
|||||||
cy.contains('Genus Amblycoptus belongs to family Soricidae, not Bovidae.')
|
cy.contains('Genus Amblycoptus belongs to family Soricidae, not Bovidae.')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
it('minus action only marks the clicked species row as removed', () => {
|
it('minus action only marks the clicked species row as removed', () => {
|
||||||
cy.visit(`/locality/20920?tab=2`)
|
cy.visit(`/locality/20920?tab=2`)
|
||||||
cy.contains('Lantian-Shuijiazui')
|
cy.contains('Lantian-Shuijiazui')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('User redirecting after logging in works', () => {
|
describe('User redirecting after logging in works', () => {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const doesNotHaveStagingMode = viewUrl => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Test individual features across the app', () => {
|
describe('Test individual features across the app', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Occurrence editing', () => {
|
describe('Occurrence editing', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating a person', () => {
|
describe('Creating a person', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating a journal', () => {
|
describe('Creating a journal', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating a region', () => {
|
describe('Creating a region', () => {
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
describe('Sequence edit behavior', () => {
|
describe('Sequence edit behavior', () => {
|
||||||
before('Wait for database and reset state', () => {
|
before('Wait for database and reset state', () => {
|
||||||
cy.task('waitForDbHealthy')
|
cy.resetDatabase()
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach('Login as admin', () => {
|
beforeEach('Login as admin', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating a species', () => {
|
describe('Creating a species', () => {
|
||||||
@@ -100,7 +100,7 @@ describe('Editing a species', () => {
|
|||||||
|
|
||||||
describe('Taxonomy checks work', () => {
|
describe('Taxonomy checks work', () => {
|
||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach('Login as admin', () => {
|
beforeEach('Login as admin', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating time bound', () => {
|
describe('Creating time bound', () => {
|
||||||
|
|||||||
+23
-23
@@ -2,7 +2,7 @@ const buildTimeUnitName = (base = 'Testing Time Unit Creation') =>
|
|||||||
`${base} ${Date.now()}-${Math.floor(Math.random() * 1e6)}`
|
`${base} ${Date.now()}-${Math.floor(Math.random() * 1e6)}`
|
||||||
|
|
||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating a time unit', () => {
|
describe('Creating a time unit', () => {
|
||||||
@@ -317,30 +317,30 @@ describe('Deleting a time unit', () => {
|
|||||||
const deletePath = `**/time-unit/${slug}`
|
const deletePath = `**/time-unit/${slug}`
|
||||||
cy.intercept('DELETE', deletePath).as('deleteTimeUnit')
|
cy.intercept('DELETE', deletePath).as('deleteTimeUnit')
|
||||||
|
|
||||||
cy.fixture('login').its('deleteTargets').then(deleteTargets => {
|
cy.fixture('login')
|
||||||
const confirmText = deleteTargets.find(target => target.entity === 'TimeUnit')
|
.its('deleteTargets')
|
||||||
?.confirmText
|
.then(deleteTargets => {
|
||||||
const expectedConfirm =
|
const confirmText = deleteTargets.find(target => target.entity === 'TimeUnit')?.confirmText
|
||||||
confirmText ||
|
const expectedConfirm =
|
||||||
'Are you sure you want to delete this item? This operation cannot be undone.'
|
confirmText || 'Are you sure you want to delete this item? This operation cannot be undone.'
|
||||||
|
|
||||||
cy.on('window:confirm', message => {
|
cy.on('window:confirm', message => {
|
||||||
expect(message).to.eq(expectedConfirm)
|
expect(message).to.eq(expectedConfirm)
|
||||||
return true
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('[id=delete-button]').click()
|
||||||
|
|
||||||
|
cy.wait('@deleteTimeUnit').its('response.statusCode').should('be.oneOf', [200, 204])
|
||||||
|
|
||||||
|
cy.contains('Deleted item successfully.').should('be.visible')
|
||||||
|
|
||||||
|
cy.url().should('include', '/time-unit')
|
||||||
|
cy.contains(displayName).should('not.exist')
|
||||||
|
|
||||||
|
cy.visit(`/time-unit/${slug}`)
|
||||||
|
cy.contains('Error loading data')
|
||||||
})
|
})
|
||||||
|
|
||||||
cy.get('[id=delete-button]').click()
|
|
||||||
|
|
||||||
cy.wait('@deleteTimeUnit').its('response.statusCode').should('be.oneOf', [200, 204])
|
|
||||||
|
|
||||||
cy.contains('Deleted item successfully.').should('be.visible')
|
|
||||||
|
|
||||||
cy.url().should('include', '/time-unit')
|
|
||||||
cy.contains(displayName).should('not.exist')
|
|
||||||
|
|
||||||
cy.visit(`/time-unit/${slug}`)
|
|
||||||
cy.contains('Error loading data')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Button Tests', () => {
|
describe('Button Tests', () => {
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
/// <reference types="cypress" />
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
describe('Update log navigation', () => {
|
describe('Update log navigation', () => {
|
||||||
before('Wait for database to become ready', () => {
|
|
||||||
cy.task('waitForDbHealthy')
|
|
||||||
})
|
|
||||||
|
|
||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach('Login as admin', () => {
|
beforeEach('Login as admin', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Change password form validates passwords correctly and shows errors to the user', () => {
|
describe('Change password form validates passwords correctly and shows errors to the user', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
before('Reset database', () => {
|
before('Reset database', () => {
|
||||||
cy.request(Cypress.env('databaseResetUrl'))
|
cy.resetDatabase()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Broadly test what different user rights see', () => {
|
describe('Broadly test what different user rights see', () => {
|
||||||
|
|||||||
@@ -25,13 +25,16 @@
|
|||||||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||||||
|
|
||||||
Cypress.Commands.add('login', username => {
|
Cypress.Commands.add('login', username => {
|
||||||
cy.clearLocalStorage()
|
cy.clearAllLocalStorage()
|
||||||
|
cy.clearAllSessionStorage()
|
||||||
|
cy.clearCookies()
|
||||||
|
cy.intercept('POST', '**/user/login').as('loginRequest')
|
||||||
cy.visit('/login')
|
cy.visit('/login')
|
||||||
cy.get('[data-cy="login-button"]', { timeout: 10000 }).should('be.visible').click()
|
cy.get('[data-cy="username-basic"]', { timeout: 10000 }).should('be.visible').clear().type(username)
|
||||||
cy.get('[data-cy="username-basic"]').type(username)
|
cy.get('[data-cy="password-basic"]').should('be.visible').clear().type('test', { log: false })
|
||||||
cy.get('[data-cy="password-basic"]').type('test')
|
cy.get('[data-cy="login-button"]').should('be.visible').click()
|
||||||
cy.get('[data-cy="login-button"]').click()
|
cy.wait('@loginRequest').its('response.statusCode').should('eq', 200)
|
||||||
cy.contains(`${username}`)
|
cy.location('pathname', { timeout: 10000 }).should('not.eq', '/login')
|
||||||
})
|
})
|
||||||
|
|
||||||
Cypress.Commands.add('loginAsDeleteCoordinator', () => {
|
Cypress.Commands.add('loginAsDeleteCoordinator', () => {
|
||||||
@@ -50,7 +53,8 @@ Cypress.Commands.add('pageForbidden', url => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Cypress.Commands.add('resetDatabase', () => {
|
Cypress.Commands.add('resetDatabase', () => {
|
||||||
cy.task('resetDatabase')
|
cy.task('waitForDbHealthy')
|
||||||
|
cy.request(Cypress.env('databaseResetUrl')).its('status').should('eq', 200)
|
||||||
})
|
})
|
||||||
|
|
||||||
// use this once you have edited some data and want to save it
|
// use this once you have edited some data and want to save it
|
||||||
|
|||||||
Reference in New Issue
Block a user