import { login } from "./helpers";

describe("learningPath page", () => {
  beforeEach(() => {
    cy.manageCommand("cypress_reset");
  });

  it("can open learningPath page", () => {
    login("admin", "test");
    cy.visit("/course/versicherungsvermittler-in/learn");

    cy.get('[data-cy="learning-path-title"]').should(
      "contain",
      "Versicherungsvermittler/-in"
    );
  });

  it("/course/versicherungsvermittler-in/learn", () => {
    login("admin", "test");
    cy.visit("/course/versicherungsvermittler-in/learn");

    cy.get('[data-cy="circle-analyse"]').click({ force: true });

    cy.url().should(
      "include",
      "/course/versicherungsvermittler-in/learn/analyse"
    );
    cy.get('[data-cy="circle-title"]').should("contain", "Analyse");
  });

  it("open listView and click on circle will open circle", () => {
    login("admin", "test");
    cy.visit("/course/versicherungsvermittler-in/learn");

    cy.get('[data-cy="show-list-view"]').click();
    cy.get('[data-cy="full-screen-modal"]').should("be.visible");

    cy.get('[data-cy="circle-analyse-vertical"]').click({ force: true });

    cy.url().should(
      "include",
      "/course/versicherungsvermittler-in/learn/analyse"
    );
    cy.get('[data-cy="circle-title"]').should("contain", "Analyse");
  });

  it("weiter gehts button will open next circle", () => {
    login("admin", "test");
    cy.visit("/course/versicherungsvermittler-in/learn");

    // first click will open first circle
    cy.get('[data-cy="lp-continue-button"]').should("contain", "Los geht's");
    cy.get('[data-cy="lp-continue-button"]').click();
    cy.get('[data-cy="circle-title"]').should("contain", "Basis");
    cy.get('[data-cy="back-to-learning-path-button"]').click();

    // mark a learning content in second circle
    cy.get('[data-cy="circle-analyse"]').click({ force: true });
    cy.get(
      '[data-cy="versicherungsvermittler-in-lp-circle-analyse-lc-fachcheck-fahrzeug-checkbox"] > .cy-checkbox'
    ).click();
    cy.get('[data-cy="back-to-learning-path-button"]').click();

    // click on continue should go to unit-test-circle
    cy.get('[data-cy="lp-continue-button"]').should("contain", "Weiter geht's");
    cy.get('[data-cy="lp-continue-button"]').click();
    cy.get('[data-cy="circle-title"]').should("contain", "Analyse");
  });
});
