Skip to content

Commit

Permalink
refactor create schema tests to cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
sserrata committed Oct 16, 2024
1 parent 893b432 commit 04d4a8b
Show file tree
Hide file tree
Showing 7 changed files with 5,716 additions and 10 deletions.
4,738 changes: 4,738 additions & 0 deletions cypress/integration/__snapshots__/testSchemaSnapshots.spec.ts.snap

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions cypress/integration/testSchemaSnapshots.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

describe("Schema Snapshots", () => {
const urls = [
"https://docusaurus-openapi.tryingpan.dev/tests/all-of-with-array-items",
"https://docusaurus-openapi.tryingpan.dev/tests/all-of-with-deep-merging",
"https://docusaurus-openapi.tryingpan.dev/tests/all-of-with-nested-all-of",
"https://docusaurus-openapi.tryingpan.dev/tests/all-of-with-same-level-properties",
"https://docusaurus-openapi.tryingpan.dev/tests/all-of-with-shared-required-properties",
"https://docusaurus-openapi.tryingpan.dev/tests/any-of-with-one-of",
"https://docusaurus-openapi.tryingpan.dev/tests/any-of-with-primitives",
"https://docusaurus-openapi.tryingpan.dev/tests/basic-discriminator-with-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/basic-discriminator-without-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-all-of-and-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-all-of-without-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-nested-schemas-and-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-nested-schemas-without-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-required-properties-and-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-required-properties-without-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-shared-properties-and-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/discriminator-with-shared-properties-without-mapping",
"https://docusaurus-openapi.tryingpan.dev/tests/get-entities-by-multiple-status",
"https://docusaurus-openapi.tryingpan.dev/tests/get-entities-by-status",
"https://docusaurus-openapi.tryingpan.dev/tests/multiple-all-of-with-nested-properties",
"https://docusaurus-openapi.tryingpan.dev/tests/one-of-with-complex-types",
"https://docusaurus-openapi.tryingpan.dev/tests/one-of-with-nested-one-of",
"https://docusaurus-openapi.tryingpan.dev/tests/one-of-with-primitive-types",
"https://docusaurus-openapi.tryingpan.dev/tests/one-of-with-required-properties",
"https://docusaurus-openapi.tryingpan.dev/tests/one-of-with-shared-properties",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/additionalbookinfo",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/baseallof",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/baseallofmapping",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/basebasic",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/basebasicmapping",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/basenested",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/basenestedmapping",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/baserequired",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/baserequiredmapping",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/baseshared",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/basesharedmapping",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/book",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/bookbase",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/enumdescriptionsentity",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/existingschema-1",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/existingschema-2",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/nestedtypea",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/nestedtypeb",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/typea",
"https://docusaurus-openapi.tryingpan.dev/tests/schemas/typeb",
];

urls.forEach((url) => {
const pageName = url.split("/").pop(); // Extract the page name from the URL
it(`should match the snapshot for ${pageName}`, () => {
cy.visit(url);
// Pause the test to inspect the state of the DOM
cy.pause();
// Wait for the container to be visible and then snapshot it
cy.get(".theme-api-markdown", { timeout: 10000 })
.should("be.visible")
.toMatchSnapshot(pageName!);
});
});
});
7 changes: 7 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

// @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies
import { initPlugin } from "cypress-plugin-snapshots/plugin";

const plugins: Cypress.PluginConfig = (on, config) => {
// Initialize cypress-plugin-snapshots
initPlugin(on, config);

// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
Expand Down
19 changes: 19 additions & 0 deletions cypress/support/cypress-plugin-snapshots.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

declare namespace Cypress {
interface Chainable<Subject = any> {
/**
* Custom command to match snapshot
* @example cy.document().toMatchSnapshot()
*/
toMatchSnapshot(
name: string,
options?: SnapshotOptions
): Chainable<Subject>;
}
}
2 changes: 2 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
* ========================================================================== */

import "@testing-library/cypress/add-commands";
// eslint-disable-next-line import/no-extraneous-dependencies
import "cypress-plugin-snapshots/commands";
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@typescript-eslint/parser": "^6.13.2",
"babel-eslint": "^10.0.0",
"cypress": "^8.7.0",
"cypress-plugin-snapshots": "^1.4.4",
"eslint": "^7.5.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-cypress": "^2.12.1",
Expand Down
Loading

0 comments on commit 04d4a8b

Please sign in to comment.