import {getMinimalMe} from '../../support/helpers';

// const me = require('../../fixtures/me.new-student.json');

describe('New student', () => {
  before(() => {
    cy.setup();
  });

  // todo: unskip me
  it.skip('shows "Enter Code" page and adds the user to a class', () => {
    const {me} = getMinimalMe({isTeacher: false});

    let onboardingVisited = false;
    let selectedClass;
    let schoolClasses = [];

    const name = 'KF1A';
    const id = 'selectedClassId';

    console.log('me', me);

    const getSelectedClass = () => {
      return selectedClass;
    };

    const getMe = () => {
      return {
        ...me,
        onboardingVisited,
        schoolClasses: {edges: schoolClasses},
        selectedClass: getSelectedClass(),
      };
    };

    console.log('getMe()', getMe());

    cy.mockGraphqlOps({
      operations: {
        MeQuery() {
          return {
            me: getMe(),
          };
        },
        JoinClass() {
          console.log('joining class');
          selectedClass = {
            id,
            name,
          };
          schoolClasses.push(selectedClass);
          return {
            joinClass: {
              success: true,
              schoolClass: selectedClass,
            },
          };
        },
        MySchoolClassQuery: {
          me: getMe(),
        },
        UpdateOnboardingProgress: () => {
          onboardingVisited = true;
          return {
            updateOnboardingProgress: {
              success: true,
            },
          };
        },
      },
    });

    cy.visit('/');
    cy.get('[data-cy=join-form-title]').should('contain', 'Einer Klasse beitreten');
    cy.get('[data-cy=join-form-input]').type('XXXX');
    cy.get('[data-cy=join-form-confirm]').click();
    cy.getByDataCy('onboarding-skip-link').click();
    cy.get('[data-cy=user-widget-avatar]').click();
    cy.get('[data-cy=class-list-link]').click();
    cy.get('[data-cy=group-list-title]').should('contain', 'Klassenliste');
  });
});
