Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add cypress docs/api test #786

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/CYPRESS_ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: maas.io e2e test failed
about: ''
title: 'maas.io/docs links test failed on {{ env.BRANCH_NAME }}'
assignees: ''

---

[maas.io e2e test failed](<https://github.com/{{> env.REPO }}/actions/runs/{{ env.RUN_ID }}) on the {{ env.BRANCH_NAME }} branch.
28 changes: 28 additions & 0 deletions .github/workflows/api-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: API Docs
on:
schedule:
- cron: "0 10 * * 1-5" # At 10:00 every day-of-week from Monday through Friday.
jobs:
api-docs:
name: maas.io/docs/api
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@main
- name: Get branch name
uses: nelonoel/[email protected]
- name: Run Cypress docs tests
uses: cypress-io/github-action@v4
with:
browser: chrome
config: baseUrl=http://maas.io/
spec: "cypress/e2e/**/*.{js,jsx,ts,tsx}"
- name: Create issue on failure
if: failure()
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
with:
filename: .github/CYPRESS_ISSUE_TEMPLATE.md
update_existing: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@ bzr-repo/
.venv
.dotrun.json

cypress/screenshots/**/*.png

# JS modules copied from node_modules
static/js/modules/*
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN --mount=type=cache,target=/root/.cache/pip pip3 install --user --requirement

# Build stage: Install yarn dependencies
# ===
FROM node:12 AS yarn-dependencies
FROM node:14 AS yarn-dependencies
WORKDIR /srv
COPY . .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn yarn install --production
Expand Down
8 changes: 8 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
baseUrl: "https://maas.io/",
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
},
});
22 changes: 22 additions & 0 deletions cypress/e2e/apiDocs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

context("/docs/api", () => {
beforeEach(() => {
cy.setCookie("_cookies_accepted", "all");
cy.visit("/docs/api");
});

it("displays side navigation correctly", () => {
cy.get(".p-side-navigation__drawer").should("not.be.visible");
cy.findByRole("link", { name: /Toggle side navigation/ }).click();
cy.get(".p-side-navigation__drawer").should("be.visible");
cy.get(".p-side-navigation__drawer")
.findAllByRole("link")
.should("have.length.least", 1);
});

it("displays content correctly", () => {
cy.visit("/docs/api");
cy.findByRole("heading", { level: 1, name: "MAAS API" }).should("exist");
cy.findByRole("heading", { level: 2, name: "Operations" }).should("exist");
});
});
1 change: 1 addition & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/cypress/add-commands";
Binary file added cypress/videos/apiDocs.spec.js.mp4
petermakowski marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
"author": "Canonical webteam",
"license": "LGPL v3",
"devDependencies": {
"@testing-library/cypress": "9.0.0",
"cypress": "12.12.0",
"stylelint": "14.16.1",
"stylelint-config-recommended-scss": "5.0.2",
"stylelint-order": "5.0.0"
},
"dependencies": {
"autoprefixer": "10.4.13",
"@canonical/cookie-policy": "3.4.0",
"@canonical/discourse-rad-parser": "^1.0.1",
"@canonical/global-nav": "3.2.4",
"@canonical/latest-news": "1.4.1",
"@canonical/discourse-rad-parser": "1.0.1",
"autoprefixer": "10.4.13",
"postcss": "8.4.20",
"postcss-cli": "9.1.0",
"sass": "1.57.1",
Expand Down
Loading