chore: make tests a bit easier to read

This commit is contained in:
Livio Bieri 2023-09-21 15:56:44 +02:00
parent 5247b6061b
commit d87f922dec
1 changed files with 30 additions and 36 deletions

View File

@ -1,5 +1,17 @@
import {login} from "./helpers"; import {login} from "./helpers";
const BASE_URL = "/course/test-lehrgang";
const EXPERT_LOGIN = ["test-trainer1@example.com", "test"];
const PARTICIPANT_LOGIN = ["test-student1@example.com", "test"];
const visitCoursePage = (subPath) => {
cy.visit(`${BASE_URL}/${subPath}`);
}
const checkNavigationLink = (dataCy, expectedLink) => {
cy.get(`[data-cy="${dataCy}"]`).should('have.attr', 'href').and('eq', `${BASE_URL}/${expectedLink}`);
}
describe("Navigation tests", () => { describe("Navigation tests", () => {
beforeEach(() => { beforeEach(() => {
cy.manageCommand("cypress_reset"); cy.manageCommand("cypress_reset");
@ -12,67 +24,49 @@ describe("Navigation tests", () => {
describe("Expert / Trainer", () => { describe("Expert / Trainer", () => {
beforeEach(() => { beforeEach(() => {
login("test-trainer1@example.com", "test"); login(...EXPERT_LOGIN);
}); });
it("should show course preview on learn", () => { it("should show course preview on learn", () => {
cy.visit("/course/test-lehrgang/learn/"); visitCoursePage("learn");
cy.get('[data-cy="course-preview-bar"]').should("exist"); cy.get('[data-cy="course-preview-bar"]').should("exist");
}) });
it("should show course preview on competence", () => { it("should show course preview on competence", () => {
cy.visit("/course/test-lehrgang/competence/"); visitCoursePage("competence");
cy.get('[data-cy="course-preview-bar"]').should("exist"); cy.get('[data-cy="course-preview-bar"]').should("exist");
}); });
it("should have correct course preview navigation", () => { it("should have correct course preview navigation", () => {
cy.visit("/course/test-lehrgang/learn/"); visitCoursePage("learn");
checkNavigationLink("preview-learn-path-link", "cockpit");
it("should have see correct navigation", () => { checkNavigationLink("preview-competence-profile-link", "learn");
cy.get('[data-cy="preview-learn-path-link"]').should('have.attr', 'href').and('eq', '/course/test-lehrgang/cockpit'); });
cy.get('[data-cy="preview-competence-profile-link""]').should('have.attr', 'href').and('eq', '/course/test-lehrgang/learn');
})
})
it("should have correct expert navigation", () => { it("should have correct expert navigation", () => {
// when course session is selected -> cockpit visitCoursePage("cockpit");
cy.visit("/course/test-lehrgang/cockpit"); checkNavigationLink("navigation-cockpit-link", "cockpit");
checkNavigationLink("navigation-preview-link", "learn");
cy.get('[data-cy="navigation-cockpit-link"]').should('have.attr', 'href').and('eq', '/course/test-lehrgang/cockpit');
cy.get('[data-cy="navigation-preview-link"]').should('have.attr', 'href').and('eq', '/course/test-lehrgang/learn');
cy.get('[data-cy="navigation-learning-path-link"]').should("not.exist")
cy.get('[data-cy="navigation-competence-profile-link"]').should("not.exist")
}); });
}); });
describe("Participant", () => { describe("Participant", () => {
beforeEach(() => { beforeEach(() => {
login("test-student1@example.com", "test"); login(...PARTICIPANT_LOGIN);
}); });
it("should not show course preview on learn path", () => { it("should not show course preview on learn path", () => {
cy.visit("/course/test-lehrgang/learn"); visitCoursePage("learn");
cy.get('[data-cy="course-preview-bar"]').should("not.exist"); cy.get('[data-cy="course-preview-bar"]').should("not.exist");
}); });
it("should not show course preview on learn path", () => { it("should have correct navigation", () => {
cy.visit("/course/test-lehrgang/comptence"); visitCoursePage("learn");
cy.get('[data-cy="course-preview-bar"]').should("not.exist"); checkNavigationLink("navigation-competence-profile-link", "competence");
}); checkNavigationLink("navigation-learning-path-link", "learn");
it("should have see correct navigation", () => {
// when course session is selected -> learn
cy.visit("/course/test-lehrgang/learn");
cy.get('[data-cy="navigation-competence-profile-link"]').should('have.attr', 'href').and('eq', '/course/test-lehrgang/competence');
cy.get('[data-cy="navigation-learning-path-link"]').should('have.attr', 'href').and('eq', '/course/test-lehrgang/learn');
cy.get('[data-cy="navigation-cockpit-link"]').should("not.exist")
cy.get('[data-cy="navigation-preview-lin"]').should("not.exist")
}); });
}); });
}); });
}); });