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";
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", () => {
beforeEach(() => {
cy.manageCommand("cypress_reset");
@ -12,67 +24,49 @@ describe("Navigation tests", () => {
describe("Expert / Trainer", () => {
beforeEach(() => {
login("test-trainer1@example.com", "test");
login(...EXPERT_LOGIN);
});
it("should show course preview on learn", () => {
cy.visit("/course/test-lehrgang/learn/");
visitCoursePage("learn");
cy.get('[data-cy="course-preview-bar"]').should("exist");
})
});
it("should show course preview on competence", () => {
cy.visit("/course/test-lehrgang/competence/");
visitCoursePage("competence");
cy.get('[data-cy="course-preview-bar"]').should("exist");
});
it("should have correct course preview navigation", () => {
cy.visit("/course/test-lehrgang/learn/");
it("should have see correct navigation", () => {
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');
})
})
visitCoursePage("learn");
checkNavigationLink("preview-learn-path-link", "cockpit");
checkNavigationLink("preview-competence-profile-link", "learn");
});
it("should have correct expert navigation", () => {
// when course session is selected -> cockpit
cy.visit("/course/test-lehrgang/cockpit");
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")
visitCoursePage("cockpit");
checkNavigationLink("navigation-cockpit-link", "cockpit");
checkNavigationLink("navigation-preview-link", "learn");
});
});
describe("Participant", () => {
beforeEach(() => {
login("test-student1@example.com", "test");
login(...PARTICIPANT_LOGIN);
});
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");
});
it("should not show course preview on learn path", () => {
cy.visit("/course/test-lehrgang/comptence");
cy.get('[data-cy="course-preview-bar"]').should("not.exist");
});
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")
it("should have correct navigation", () => {
visitCoursePage("learn");
checkNavigationLink("navigation-competence-profile-link", "competence");
checkNavigationLink("navigation-learning-path-link", "learn");
});
});
});
});