import { login } from "./helpers";

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

    login("admin", "test");
    cy.visit("/course/test-lehrgang/learn/analyse");
  });

  it("can open circle page", () => {
    cy.get('[data-cy="circle-title"]').should("contain", "Analyse");
  });

  it("can toggle learning content", () => {
    cy.get('[data-cy="circle-title"]').should("contain", "Analyse");

    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lc-einleitung-circle-analyse-checkbox"] > .cy-checkbox'
    ).click();

    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lc-einleitung-circle-analyse-checkbox"] > .cy-checkbox-checked'
    ).should("have.class", "cy-checkbox-checked");

    // completion data should still be there after reload
    cy.reload();
    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lc-einleitung-circle-analyse-checkbox"] > .cy-checkbox-checked'
    ).should("have.class", "cy-checkbox-checked");
  });

  it("can open learning contents and complete them by continuing", () => {
    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lu-fahrzeug"] > div'
    ).should("have.class", "self-evaluation-unknown");

    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lc-rafael-fasel-wechselt-sein-auto"]'
    ).click();
    cy.get('[data-cy="ln-title"]').should(
      "contain",
      "Rafael Fasel wechselt sein Auto"
    );
    cy.get('[data-cy="complete-and-continue"]').click();

    cy.get('[data-cy="ln-title"]').should("contain", "Fachcheck Fahrzeug");
    cy.get('[data-cy="complete-and-continue"]').click();

    cy.get('[data-cy="ln-title"]').should(
      "contain",
      "Selbsteinschätzung Fahrzeug"
    );
    cy.get('[data-cy="success"]').click();
    cy.get('[data-cy="complete-and-continue"]').click();

    cy.get('[data-cy="ln-title"]').should(
      "contain",
      "Selbsteinschätzung Fahrzeug"
    );
    cy.get('[data-cy="success"]').click();
    cy.get('[data-cy="complete-and-continue"]').click();

    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lc-rafael-fasel-wechselt-sein-auto-checkbox"] > .cy-checkbox-checked'
    ).should("have.class", "cy-checkbox-checked");
    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lc-fachcheck-fahrzeug-checkbox"] > .cy-checkbox-checked'
    ).should("have.class", "cy-checkbox-checked");

    cy.get(
      '[data-cy="test-lehrgang-lp-circle-analyse-lu-fahrzeug"] > div'
    ).should("have.class", "self-evaluation-success");
  });

  it("continue button works", () => {
    cy.get('[data-cy="ls-continue-button"]').should("contain", "Los geht's");
    cy.get('[data-cy="ls-continue-button"]').click();

    cy.get('[data-cy="ln-title"]').should(
      "contain",
      'Einleitung Circle "Analyse"'
    );
    cy.get('[data-cy="complete-and-continue"]').click();

    cy.get('[data-cy="ls-continue-button"]').should("contain", "Weiter geht's");
    cy.get('[data-cy="ls-continue-button"]').click();
    cy.get('[data-cy="ln-title"]').should(
      "contain",
      "Rafael Fasel wechselt sein Auto"
    );
  });

  it("can open learning content by url", () => {
    cy.visit("/course/test-lehrgang/learn/analyse/reiseversicherung");
    cy.get('[data-cy="ln-title"]').should("contain", "Reiseversicherung");

    cy.get('[data-cy="close-learning-content"]').click();
    cy.get('[data-cy="circle-title"]').should("contain", "Analyse");
  });
});
