From da1934b92264d2cab800a8a576db90e67da16737 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 16 Mar 2021 15:58:48 +0000 Subject: [PATCH] Added more tests --- src/Ombi/ClientApp/src/index.html | 2 +- tests/cypress/support/commands.ts | 10 +++-- .../tests/navigation/navigation-bar.spec.ts | 42 +++++++++++++++++++ tests/global.d.ts | 2 +- tests/package.json | 2 +- tests/yarn.lock | 8 ++-- 6 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 tests/cypress/tests/navigation/navigation-bar.spec.ts diff --git a/src/Ombi/ClientApp/src/index.html b/src/Ombi/ClientApp/src/index.html index 870886bad..1a1fe5d30 100644 --- a/src/Ombi/ClientApp/src/index.html +++ b/src/Ombi/ClientApp/src/index.html @@ -51,7 +51,7 @@ var line = lines[Math.floor(Math.random() * lines.length)]; window.loading_screen = window.pleaseWait({ - template: `
+ template: `

diff --git a/tests/cypress/support/commands.ts b/tests/cypress/support/commands.ts index db28e01d0..2a4e47aa9 100644 --- a/tests/cypress/support/commands.ts +++ b/tests/cypress/support/commands.ts @@ -23,6 +23,7 @@ // // -- This will overwrite an existing command -- // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) +import 'cypress-wait-until'; Cypress.Commands.add("landingSettings", (enabled) => { cy.fixture('login/landingPageSettings').then((settings) => { @@ -31,7 +32,7 @@ Cypress.Commands.add("landingSettings", (enabled) => { }) }) -Cypress.Commands.add('login', (username, password) => { +Cypress.Commands.add('loginWithCreds', (username, password) => { cy.request({ method: 'POST', url: '/api/v1/token', @@ -86,12 +87,13 @@ Cypress.Commands.add('createUser', (username, password, claims) => { Cypress.Commands.add('generateUniqueId', () => { const uniqueSeed = Date.now().toString(); const id = Cypress._.uniqueId(uniqueSeed); - return id; + cy.wrap(id); }); Cypress.Commands.add("getByData", (selector, ...args) => { - return cy.get(`[data-test=${selector}]`, ...args); - }); + return cy.get(`[data-test=${selector}]`, ...args); +}); + Cypress.Commands.add("getByData", (selector) => { return cy.get(`[data-test=${selector}]`); diff --git a/tests/cypress/tests/navigation/navigation-bar.spec.ts b/tests/cypress/tests/navigation/navigation-bar.spec.ts new file mode 100644 index 000000000..7064c718e --- /dev/null +++ b/tests/cypress/tests/navigation/navigation-bar.spec.ts @@ -0,0 +1,42 @@ +import { discoverPage as Page } from "@/integration/page-objects"; + +describe("Navigation Bar Tests", () => { + it("Navigation Bar should show admin options when logged in as an admin", () => { + cy.login(); + Page.visit(); + + Page.navbar.adminDonate.should("be.visible"); + Page.navbar.settings.should("be.visible"); + Page.navbar.userManagement.should("be.visible"); + Page.navbar.requests.should("be.visible"); + Page.navbar.discover.should("be.visible"); + Page.navbar.userPreferences.should("be.visible"); + Page.navbar.logout.should("be.visible"); + }); + + it("Navigation Bar should not show admin options when logged in as an non-admin", () => { + cy.generateUniqueId().then((id) => { + cy.login(); + const roles = []; + roles.push({ value: "RequestMovie", enabled: true }); + cy.createUser(id, "a", roles).then(() => { + cy.removeLogin(); + cy.loginWithCreds(id, "a"); + + cy.intercept("GET", "search/Movie/Popular").as("discoverLoad"); + Page.visit(); + + cy.wait("@discoverLoad"); + + Page.navbar.profileUsername.should('have.text', id); + Page.navbar.adminDonate.should("not.exist"); + Page.navbar.settings.should("not.exist"); + Page.navbar.userManagement.should("not.exist"); + Page.navbar.requests.should("be.visible"); + Page.navbar.discover.should("be.visible"); + Page.navbar.userPreferences.should("be.visible"); + Page.navbar.logout.should("be.visible"); + }); + }); + }); +}); diff --git a/tests/global.d.ts b/tests/global.d.ts index 4545c29b2..f6aec338a 100644 --- a/tests/global.d.ts +++ b/tests/global.d.ts @@ -5,7 +5,7 @@ declare namespace Cypress { interface Chainable { landingSettings(enabled: boolean): Chainable; - login(username: string, password: string): Chainable; + loginWithCreds(username: string, password: string): Chainable; login(): Chainable; removeLogin(): Chainable; verifyNotification(text: string): Chainable; diff --git a/tests/package.json b/tests/package.json index 111521e19..81ec10880 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,6 +1,6 @@ { "devDependencies": { - "cypress": "^6.6.0", + "cypress": "6.7.1", "cypress-wait-until": "^1.7.1", "typescript": "^4.2.3" }, diff --git a/tests/yarn.lock b/tests/yarn.lock index d0fb2726f..5ee10f4e9 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -374,10 +374,10 @@ cypress-wait-until@^1.7.1: resolved "https://registry.yarnpkg.com/cypress-wait-until/-/cypress-wait-until-1.7.1.tgz#3789cd18affdbb848e3cfc1f918353c7ba1de6f8" integrity sha512-8DL5IsBTbAxBjfYgCzdbohPq/bY+IKc63fxtso1C8RWhLnQkZbVESyaclNr76jyxfId6uyzX8+Xnt0ZwaXNtkA== -cypress@^6.6.0: - version "6.6.0" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-6.6.0.tgz#659c64cdb06e51b6be18fdac39d8f192deb54fa0" - integrity sha512-+Xx3Zn653LJHUsCb9h1Keql2jlazbr1ROmbY6DFJMmXKLgXP4ez9cE403W93JNGRbZK0Tng3R/oP8mvd9XAPVg== +cypress@6.7.1: + version "6.7.1" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-6.7.1.tgz#6b8e1ba9badbded284ddc8575873b64211250ea6" + integrity sha512-MC9yt1GqpL4WVDQ0STI89K+PdLeC3T3NuAb2N61d6vYGR9pJy8w3Fqe0OWZwaRTJtg9eAyHXPGmFsyKeNQ3tmg== dependencies: "@cypress/listr-verbose-renderer" "^0.4.1" "@cypress/request" "^2.88.5"