mempool/frontend/cypress/support/commands.ts

148 lines
4.0 KiB
TypeScript
Raw Normal View History

// ***********************************************
// This example namespace declaration will help
// with Intellisense and code completion in your
// IDE or Text Editor.
// ***********************************************
// declare namespace Cypress {
// interface Chainable<Subject = any> {
// customCommand(param: any): typeof customCommand;
// }
// }
//
// function customCommand(param: any): void {
// console.warn(param);
// }
//
// NOTE: You can use it like so:
// Cypress.Commands.add('customCommand', customCommand);
//
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
'use strict'
import 'cypress-wait-until';
Updates to the e2e suite (#659) * initial version of the update config script * fix duplicated content * update cypress ci settings * add workflow to run e2e tests when pushing * record cypress results to the dashboard * pull the cypress record key and project id from the secrets * add start-server-and-test to replace concurrently * replace concurrently with start-server-and-test * remove concurrently * add new cypress target to record * update cypress to 7.7.0 * add tests for signet * add tests for testnet * run tests on chrome and firefox * update test matrix: add edge and run firefox on container * fix copypasta * update docker image for firefox * fix task name again * fix edge tests task name * improve bisq tests * update workflow config * enable cypress debug logs * add a manual trigger for the e2e tests * add config:defaults target * use more of the GHA options * fix config command * add cypress-fail-on-console-error * upgrade cypress to v8.0.0 * add helper to wait for the loader skeleton to be gone * use skeleton waiter on the tests * remove manual test trigger * fix tv test when only one mempool block is available * add waiter for pagination * add extra steps to debug firefox launch issue * remove whoami step * Revert "upgrade cypress to v8.0.0" This reverts commit cb3ff7d906c2a2219d7e2b2c16a92c311e3f6817. * remove userinfo debug step * enable test retries in run mode * update proxy config to reduce ECONNRESET errors * add mock-socket dev dependency * add helpers to mock websockets and detect page idleness * stabilize mainnet tests * fix tv mode test on Liquid * add basic tests for the mainnet status page * cleanup mainnet tests * update bisq tests * update signet tests * update testnet tests * add initial support for parameterized websocket mocks * move testing dependencies to optionalDependencies * comment out mempool size check until the live updates are fixed * comment out tx regex test * update fixture for the new difficulty adjustment component * fix the assertions on the status page
2021-07-25 20:03:47 +02:00
import { PageIdleDetector } from './PageIdleDetector';
import { mockWebSocket } from './websocket';
/* global Cypress */
const codes = {
2022-06-04 05:46:33 +02:00
ArrowLeft: 37,
ArrowUp: 38,
ArrowRight: 39,
ArrowDown: 40
}
Updates to the e2e suite (#659) * initial version of the update config script * fix duplicated content * update cypress ci settings * add workflow to run e2e tests when pushing * record cypress results to the dashboard * pull the cypress record key and project id from the secrets * add start-server-and-test to replace concurrently * replace concurrently with start-server-and-test * remove concurrently * add new cypress target to record * update cypress to 7.7.0 * add tests for signet * add tests for testnet * run tests on chrome and firefox * update test matrix: add edge and run firefox on container * fix copypasta * update docker image for firefox * fix task name again * fix edge tests task name * improve bisq tests * update workflow config * enable cypress debug logs * add a manual trigger for the e2e tests * add config:defaults target * use more of the GHA options * fix config command * add cypress-fail-on-console-error * upgrade cypress to v8.0.0 * add helper to wait for the loader skeleton to be gone * use skeleton waiter on the tests * remove manual test trigger * fix tv test when only one mempool block is available * add waiter for pagination * add extra steps to debug firefox launch issue * remove whoami step * Revert "upgrade cypress to v8.0.0" This reverts commit cb3ff7d906c2a2219d7e2b2c16a92c311e3f6817. * remove userinfo debug step * enable test retries in run mode * update proxy config to reduce ECONNRESET errors * add mock-socket dev dependency * add helpers to mock websockets and detect page idleness * stabilize mainnet tests * fix tv mode test on Liquid * add basic tests for the mainnet status page * cleanup mainnet tests * update bisq tests * update signet tests * update testnet tests * add initial support for parameterized websocket mocks * move testing dependencies to optionalDependencies * comment out mempool size check until the live updates are fixed * comment out tx regex test * update fixture for the new difficulty adjustment component * fix the assertions on the status page
2021-07-25 20:03:47 +02:00
Cypress.Commands.add('waitForSkeletonGone', () => {
2022-06-04 05:46:33 +02:00
cy.waitUntil(() => {
return Cypress.$('.skeleton-loader').length === 0;
}, { verbose: true, description: "waitForSkeletonGone", errorMsg: "skeleton loaders never went away", timeout: 15000, interval: 50 });
Updates to the e2e suite (#659) * initial version of the update config script * fix duplicated content * update cypress ci settings * add workflow to run e2e tests when pushing * record cypress results to the dashboard * pull the cypress record key and project id from the secrets * add start-server-and-test to replace concurrently * replace concurrently with start-server-and-test * remove concurrently * add new cypress target to record * update cypress to 7.7.0 * add tests for signet * add tests for testnet * run tests on chrome and firefox * update test matrix: add edge and run firefox on container * fix copypasta * update docker image for firefox * fix task name again * fix edge tests task name * improve bisq tests * update workflow config * enable cypress debug logs * add a manual trigger for the e2e tests * add config:defaults target * use more of the GHA options * fix config command * add cypress-fail-on-console-error * upgrade cypress to v8.0.0 * add helper to wait for the loader skeleton to be gone * use skeleton waiter on the tests * remove manual test trigger * fix tv test when only one mempool block is available * add waiter for pagination * add extra steps to debug firefox launch issue * remove whoami step * Revert "upgrade cypress to v8.0.0" This reverts commit cb3ff7d906c2a2219d7e2b2c16a92c311e3f6817. * remove userinfo debug step * enable test retries in run mode * update proxy config to reduce ECONNRESET errors * add mock-socket dev dependency * add helpers to mock websockets and detect page idleness * stabilize mainnet tests * fix tv mode test on Liquid * add basic tests for the mainnet status page * cleanup mainnet tests * update bisq tests * update signet tests * update testnet tests * add initial support for parameterized websocket mocks * move testing dependencies to optionalDependencies * comment out mempool size check until the live updates are fixed * comment out tx regex test * update fixture for the new difficulty adjustment component * fix the assertions on the status page
2021-07-25 20:03:47 +02:00
});
Cypress.Commands.add(
2022-06-04 05:46:33 +02:00
"waitForPageIdle",
() => {
console.warn("Waiting for page idle state");
const pageIdleDetector = new PageIdleDetector();
pageIdleDetector.WaitForPageToBeIdle();
}
Updates to the e2e suite (#659) * initial version of the update config script * fix duplicated content * update cypress ci settings * add workflow to run e2e tests when pushing * record cypress results to the dashboard * pull the cypress record key and project id from the secrets * add start-server-and-test to replace concurrently * replace concurrently with start-server-and-test * remove concurrently * add new cypress target to record * update cypress to 7.7.0 * add tests for signet * add tests for testnet * run tests on chrome and firefox * update test matrix: add edge and run firefox on container * fix copypasta * update docker image for firefox * fix task name again * fix edge tests task name * improve bisq tests * update workflow config * enable cypress debug logs * add a manual trigger for the e2e tests * add config:defaults target * use more of the GHA options * fix config command * add cypress-fail-on-console-error * upgrade cypress to v8.0.0 * add helper to wait for the loader skeleton to be gone * use skeleton waiter on the tests * remove manual test trigger * fix tv test when only one mempool block is available * add waiter for pagination * add extra steps to debug firefox launch issue * remove whoami step * Revert "upgrade cypress to v8.0.0" This reverts commit cb3ff7d906c2a2219d7e2b2c16a92c311e3f6817. * remove userinfo debug step * enable test retries in run mode * update proxy config to reduce ECONNRESET errors * add mock-socket dev dependency * add helpers to mock websockets and detect page idleness * stabilize mainnet tests * fix tv mode test on Liquid * add basic tests for the mainnet status page * cleanup mainnet tests * update bisq tests * update signet tests * update testnet tests * add initial support for parameterized websocket mocks * move testing dependencies to optionalDependencies * comment out mempool size check until the live updates are fixed * comment out tx regex test * update fixture for the new difficulty adjustment component * fix the assertions on the status page
2021-07-25 20:03:47 +02:00
);
Cypress.Commands.add('mockMempoolSocket', () => {
mockWebSocket();
});
2022-06-04 05:46:33 +02:00
Cypress.Commands.add('changeNetwork', (network: "testnet" | "signet" | "liquid" | "bisq" | "mainnet") => {
cy.get('.dropdown-toggle').click().then(() => {
cy.get(`a.${network}`).click().then(() => {
cy.waitForPageIdle();
if (network !== 'bisq') {
cy.waitForSkeletonGone();
}
});
2022-06-04 05:46:33 +02:00
});
});
// https://github.com/bahmutov/cypress-arrows/blob/8f0303842a343550fbeaf01528d01d1ff213b70c/src/index.js
2022-06-04 05:46:33 +02:00
function keydownCommand($el, key) {
const message = `sending the "${key}" keydown event`
const log = Cypress.log({
name: `keydown: ${key}`,
message: message,
consoleProps: function () {
return {
Subject: $el
}
2022-06-04 05:46:33 +02:00
}
})
const e = $el.createEvent('KeyboardEvent')
Object.defineProperty(e, 'key', {
get: function () {
return key
}
})
Object.defineProperty(e, 'keyCode', {
get: function () {
return this.keyCodeVal
}
})
Object.defineProperty(e, 'which', {
get: function () {
return this.keyCodeVal
}
})
var metaKey = false
Object.defineProperty(e, 'metaKey', {
get: function () {
return metaKey
}
})
Object.defineProperty(e, 'shiftKey', {
get: function () {
return false
}
})
e.keyCodeVal = codes[key]
e.initKeyboardEvent('keydown', true, true,
$el.defaultView, false, false, false, false, e.keyCodeVal, e.keyCodeVal)
$el.dispatchEvent(e)
log.snapshot().end()
return $el
}
Cypress.Commands.add('keydown', { prevSubject: "dom" }, keydownCommand)
Cypress.Commands.add('left', { prevSubject: "dom" }, $el => keydownCommand($el, 'ArrowLeft'))
Cypress.Commands.add('right', { prevSubject: "dom" }, $el => keydownCommand($el, 'ArrowRight'))
Cypress.Commands.add('up', { prevSubject: "dom" }, $el => keydownCommand($el, 'ArrowUp'))
Cypress.Commands.add('down', { prevSubject: "dom" }, $el => keydownCommand($el, 'ArrowDown'))