Skip to content

Commit

Permalink
fix: update docs links #5276 (#5463)
Browse files Browse the repository at this point in the history
- refactor docs links tests for easier debugging
  • Loading branch information
petermakowski authored Jun 20, 2024
1 parent 7094ae1 commit 792cf5b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
50 changes: 40 additions & 10 deletions cypress/e2e/docs-links/docs-links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,57 @@ import docsUrls from "../../../src/app/base/docsUrls";

const urls = Object.values(docsUrls);

context("docs resource exists", () => {
beforeEach(() => {
cy.setCookie("_cookies_accepted", "all");
});
beforeEach(() => {
cy.setCookie("_cookies_accepted", "all");
});

context("loads the page", () => {
urls.forEach((url) => {
it(url, () => {
// test that the page loads, can be redirected
cy.visit(url);
const { hash } = new URL(url);
if (hash) {
cy.get(hash).should("exist");
}
});
});
});

context("docs resources have no redirects", () => {
context("is a direct link", () => {
urls.forEach((url) => {
it(url, () => {
cy.visit(url);
cy.url().should("equal", url);

// print warning if the URL is redirected
cy.request({
url,
followRedirect: false,
}).then((resp) => {
if (resp.redirectedToUrl) {
expect(
resp.redirectedToUrl,
`URL NEEDS TO BE UPDATED
-----------------------------
FROM:
${url}
TO:
${resp.redirectedToUrl}
error`
).to.eq(url);
}
});
});
});
});

context("contains the specified heading", () => {
urls.forEach((url) => {
it(`URL: ${url}`, () => {
const { hash } = new URL(url);
if (hash) {
cy.visit(url);
cy.get(hash).should("exist");
}
});
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"commit": "git-cz",
"cypress-open": "yarn cypress open",
"cypress-run-a11y": "yarn cypress run --config specPattern=cypress/e2e/accessibility/**/*.ts",
"cypress-run-docs": "yarn cypress run --config specPattern=cypress/e2e/docs-links/**/*.ts ",
"cypress-run": "yarn cypress run",
"lint": "npmPkgJsonLint . && eslint src cypress && tsc --project tsconfig.json --noEmit && tsc --project cypress/tsconfig.json --noEmit",
"link-components": "yarn link \"@canonical/react-components\" && yarn link \"react\" && yarn install",
Expand Down
33 changes: 14 additions & 19 deletions src/app/base/docsUrls.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
const docsUrls = {
aboutNativeTLS:
"https://maas.io/docs/how-to-enable-maas-native-tls#heading--how-to-enable-tls",
addMachines:
"https://maas.io/docs/how-to-make-machines-available#heading--how-to-create-delete-and-configure-machines",
aboutNativeTLS: "https://maas.io/docs/how-to-implement-tls#enabling-tls-2",
addMachines: "https://maas.io/docs/how-to-manage-machines",
addNodesViaChassis:
"https://maas.io/docs/how-to-make-machines-available#heading--how-to-add-machines-via-a-chassis",
"https://maas.io/docs/how-to-manage-machines#add-machines-via-chassis-ui-2",
autoRenewTLSCert:
"https://maas.io/docs/how-to-enable-maas-native-tls#heading--how-to-auto-renew-certificates",
cloudInit:
"https://maas.io/docs/how-to-customise-machines#heading--cloud-init",
"https://maas.io/docs/how-to-customise-machines#pre-seed-cloud-init-2",
configurationJourney:
"https://maas.io/docs/how-to-do-a-fresh-install-of-maas#heading--configure-maas",
"https://maas.io/docs/how-to-install-maas#configure-maas-with-the-ui-10",
customisingDeployedMachines: "https://maas.io/docs/how-to-customise-machines",
dhcp: "https://maas.io/docs/how-to-enable-dhcp",
ipmi: "https://maas.io/docs/power-drivers-reference#heading--ipmi",
ipRanges:
"https://maas.io/docs/how-to-enable-dhcp#heading--how-to-manage-ip-ranges",
ipmi: "https://maas.io/docs/reference-power-drivers#ipmi-6",
ipRanges: "https://maas.io/docs/how-to-enable-dhcp#create-an-ip-range-ui-2",
kvmIntroduction: "https://maas.io/docs/about-virtual-machines",
networkDiscovery:
"https://maas.io/docs/about-maas-networks#heading--about-network-discovery",
"https://maas.io/docs/about-maas-networks#network-discovery-5",
rackController: "https://maas.io/docs/how-to-configure-controllers",
sshKeys: "https://maas.io/docs/how-to-manage-user-accounts#heading--ssh-keys",
tagsAutomatic:
"https://maas.io/docs/how-to-tag-machines#heading--Automatic-tags",
sshKeys: "https://maas.io/docs/how-to-manage-user-access#add-ssh-keys-5",
tagsAutomatic: "https://maas.io/docs/how-to-manage-tags#automatic-tags-17",
tagsKernelOptions:
"https://maas.io/docs/how-to-tag-machines#heading--update-tag-kernel-options",
"https://maas.io/docs/how-to-manage-tags#update-tag-kernel-options-22",
tagsXpathExpressions:
"https://maas.io/docs/how-to-tag-machines#heading--how-to-create-automatic-tags",
vaultIntegration: "https://maas.io/docs/how-to-use-hashicorp-vault-with-maas",
windowsImages:
"https://maas.io/docs/how-to-customise-images#heading--custom-windows-images",
"https://maas.io/docs/how-to-manage-tags#automatic-tags-17",
vaultIntegration: "https://maas.io/docs/how-to-integrate-vault",
windowsImages: "https://maas.io/docs/how-to-build-a-windows-image",
} as const;

export default docsUrls;

0 comments on commit 792cf5b

Please sign in to comment.