From 065646ed5dc63fb65049a24cdfabd893576349eb Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 29 Mar 2023 17:13:51 +0530 Subject: [PATCH] test: cypress setup --- .gitignore | 2 ++ cypress.config.js | 12 ++++++++ cypress/e2e/course_creation.cy.js | 14 +++++++++ cypress/fixtures/example.json | 5 +++ cypress/support/commands.js | 51 +++++++++++++++++++++++++++++++ cypress/support/e2e.js | 20 ++++++++++++ package.json | 28 +++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 cypress.config.js create mode 100644 cypress/e2e/course_creation.cy.js create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/support/commands.js create mode 100644 cypress/support/e2e.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index ba820a93..81bbfe1a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ lms/public/dist __pycache__/ *.py[cod] *$py.class +node_modules +package-lock.json \ No newline at end of file diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 00000000..79d7508a --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,12 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + projectId: "", + adminPassword: "admin", + testUser: "ash@ipp.com", + retries: { + runMode: 2, + openMode: 0, + }, + e2e: {}, +}); diff --git a/cypress/e2e/course_creation.cy.js b/cypress/e2e/course_creation.cy.js new file mode 100644 index 00000000..8dcb0154 --- /dev/null +++ b/cypress/e2e/course_creation.cy.js @@ -0,0 +1,14 @@ +describe("Course Creation", () => { + beforeEach(() => { + cy.login(); + cy.visit("/courses"); + }); + + it("creates a new course", () => { + cy.get("button").contains("Create a Course").click(); + cy.get("button").contains("Add Tag").click(); + cy.get(".course-card-pills").type("Test"); + cy.get("#title").type("Test Course"); + cy.get("#intro").type("Test Course Short Introduction"); + }); +}); diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 00000000..02e42543 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 00000000..31945180 --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,51 @@ +// *********************************************** +// 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) => { ... }) + +Cypress.Commands.add("login", (email, password) => { + if (!email) { + email = Cypress.config("testUser") || "Administrator"; + } + if (!password) { + password = Cypress.config("adminPassword"); + } + cy.request({ + url: "/api/method/login", + method: "POST", + body: { usr: email, pwd: password }, + }); +}); + +Cypress.Commands.add("button", (text) => { + return cy.get(`button:contains("${text}")`); +}); + +Cypress.Commands.add("iconButton", (text) => { + return cy.get(`button[aria-label="${text}"]`); +}); + +Cypress.Commands.add("dialog", (selector) => { + return cy.get(`[role=dialog] ${selector}`); +}); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js new file mode 100644 index 00000000..3a252243 --- /dev/null +++ b/cypress/support/e2e.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/e2e.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import "./commands"; + +// Alternatively you can use CommonJS syntax: +// require('./commands') diff --git a/package.json b/package.json new file mode 100644 index 00000000..c690a31a --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "frappe_lms", + "version": "1.0.0", + "description": "Easy to use, open-source, Learning Management System", + "scripts": { + "test-local": "cypress open --e2e --browser chrome" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/frappe/lms.git" + }, + "author": "Frappe", + "license": "AGPL-3.0-or-later", + "bugs": { + "url": "https://github.com/frappe/lms/issues" + }, + "homepage": "https://github.com/frappe/lms#readme", + "devDependencies": { + "cypress": "^10" + }, + "dependencies": { + "@4tw/cypress-drag-drop": "^2", + "@cypress/code-coverage": "^3", + "@testing-library/cypress": "^8", + "@testing-library/dom": "8.17.1", + "cypress-real-events": "^1.7.6" + } +}