From aacf2289de0de9980a012987bafbb4cf345e15b2 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sun, 26 Feb 2023 09:37:41 -0500 Subject: [PATCH] Improve the web tests (#1430) * Improve the web tests * That's not portable * Use regex here * Set concurrency on web CI --- .github/workflows/web.yml | 5 +++-- web/components/Docs.tsx | 2 +- web/components/Header.tsx | 4 ++-- web/cypress.config.js | 6 ++++-- web/cypress/.eslintrc.json | 7 +++++++ web/cypress/e2e/basic.cy.js | 14 ++++++++++---- web/package-lock.json | 22 ++++++++++++++++++++++ web/package.json | 1 + web/pages/config_settings.tsx | 4 +++- web/pages/lua.tsx | 4 +++- web/pages/variables.tsx | 6 +++--- 11 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 web/cypress/.eslintrc.json diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index c6fee294..f48ba4c6 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -1,11 +1,12 @@ name: Web CI - on: push: branches: [main] pull_request: branches: [main] - +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: build: runs-on: ubuntu-latest diff --git a/web/components/Docs.tsx b/web/components/Docs.tsx index 83da901a..3033e2d1 100644 --- a/web/components/Docs.tsx +++ b/web/components/Docs.tsx @@ -31,7 +31,7 @@ export default function Docs({ docs, braces, assign }: DocsProps) { >
- +
diff --git a/web/components/Header.tsx b/web/components/Header.tsx index 1f89f528..f99fd098 100644 --- a/web/components/Header.tsx +++ b/web/components/Header.tsx @@ -56,8 +56,8 @@ export default function Header({

- - {name} + + {name}

{router.asPath != '/' && ( diff --git a/web/cypress.config.js b/web/cypress.config.js index f45d4d43..361d1290 100644 --- a/web/cypress.config.js +++ b/web/cypress.config.js @@ -1,8 +1,10 @@ -const { defineConfig } = require('cypress'); +/* eslint-disable @typescript-eslint/no-var-requires */ +const { defineConfig } = require('cypress') module.exports = defineConfig({ + scrollBehavior: 'center', e2e: { baseUrl: 'http://localhost:3000', supportFile: false, }, -}); +}) diff --git a/web/cypress/.eslintrc.json b/web/cypress/.eslintrc.json new file mode 100644 index 00000000..f7e5a6b3 --- /dev/null +++ b/web/cypress/.eslintrc.json @@ -0,0 +1,7 @@ +{ + "extends": ["eslint:recommended", "plugin:cypress/recommended", "prettier"], + "plugins": ["cypress"], + "settings": { + "sort-imports": "error" + } +} diff --git a/web/cypress/e2e/basic.cy.js b/web/cypress/e2e/basic.cy.js index fc498e7c..efea8b41 100644 --- a/web/cypress/e2e/basic.cy.js +++ b/web/cypress/e2e/basic.cy.js @@ -4,7 +4,7 @@ describe('check index renders', () => { }) it('displays the title text', () => { - cy.get('h1').contains('Conky') + cy.get('[data-cy="top-link"]').contains(/^Conky$/) }) }) describe('check config settings', () => { @@ -13,7 +13,8 @@ describe('check config settings', () => { }) it('displays the title text', () => { - cy.get('h1').contains('Configuration settings') + cy.get('[data-cy="top-link"]').contains(/^Conky$/) + cy.get('[data-cy="page-heading"]').contains(/^Configuration settings$/) }) }) describe('check variables', () => { @@ -22,7 +23,11 @@ describe('check variables', () => { }) it('displays the title text', () => { - cy.get('h1').contains('Variables') + cy.get('[data-cy="top-link"]').contains(/^Conky$/) + cy.get('[data-cy="page-heading"]').contains(/^Variables$/) + }) + it('has anchor links and can focus on them', () => { + cy.get('[data-anchor-name="cpu"]').click().and('be.visible') }) }) describe('check lua', () => { @@ -31,6 +36,7 @@ describe('check lua', () => { }) it('displays the title text', () => { - cy.get('h1').contains('Lua API') + cy.get('[data-cy="top-link"]').contains(/^Conky$/) + cy.get('[data-cy="page-heading"]').contains(/^Lua API$/) }) }) diff --git a/web/package-lock.json b/web/package-lock.json index 6d3ca83d..db3fcccf 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -38,6 +38,7 @@ "eslint": "^8.34.0", "eslint-config-next": "^13.2.1", "eslint-config-prettier": "^8.6.0", + "eslint-plugin-cypress": "^2.12.1", "eslint-plugin-mdx": "^2.0.5", "js-yaml": "^4.1.0", "netlify-plugin-cypress": "^2.2.1", @@ -5105,6 +5106,27 @@ "ms": "^2.1.1" } }, + "node_modules/eslint-plugin-cypress": { + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-cypress/-/eslint-plugin-cypress-2.12.1.tgz", + "integrity": "sha512-c2W/uPADl5kospNDihgiLc7n87t5XhUbFDoTl6CfVkmG+kDAb5Ux10V9PoLPu9N+r7znpc+iQlcmAqT1A/89HA==", + "dev": true, + "dependencies": { + "globals": "^11.12.0" + }, + "peerDependencies": { + "eslint": ">= 3.2.1" + } + }, + "node_modules/eslint-plugin-cypress/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/eslint-plugin-import": { "version": "2.27.5", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz", diff --git a/web/package.json b/web/package.json index f126c879..d2d1d576 100644 --- a/web/package.json +++ b/web/package.json @@ -52,6 +52,7 @@ "eslint": "^8.34.0", "eslint-config-next": "^13.2.1", "eslint-config-prettier": "^8.6.0", + "eslint-plugin-cypress": "^2.12.1", "eslint-plugin-mdx": "^2.0.5", "js-yaml": "^4.1.0", "netlify-plugin-cypress": "^2.2.1", diff --git a/web/pages/config_settings.tsx b/web/pages/config_settings.tsx index e48337a8..9cc66312 100644 --- a/web/pages/config_settings.tsx +++ b/web/pages/config_settings.tsx @@ -22,7 +22,9 @@ export default function ConfigSettings(props: ConfigSettingsProps) { />
-

Configuration settings

+

+ Configuration settings +

diff --git a/web/pages/lua.tsx b/web/pages/lua.tsx index a056ad15..601e45f6 100644 --- a/web/pages/lua.tsx +++ b/web/pages/lua.tsx @@ -15,7 +15,9 @@ export default function Lua(props: LuaProps) {
-

Lua API

+

+ Lua API +

diff --git a/web/pages/variables.tsx b/web/pages/variables.tsx index 74a7b1b2..e85905b0 100644 --- a/web/pages/variables.tsx +++ b/web/pages/variables.tsx @@ -17,9 +17,9 @@ export default function Variables(props: VariablesProps) { description="Conky object variables documentation" />
-
-

Variables

-
+

+ Variables +