
import {getModules, getMe} from '../../support/helpers';
import mocks from '../../fixtures/mocks';

const operations = {
  MeQuery() {
    return getMe({
      schoolClasses: ['FLID2018a', 'Andere Klasse'],
      teacher: true,
    });
  },
  ModulesQuery: getModules,
  UpdateSettings: {
    updateSettings: {
      success: true,
    },
  },
  MySchoolClassQuery: {
    me: {},
  },
  UpdateLastModule: {
    updateLastModule: {
      success: true,
    },
  },
  SyncModuleVisibility: {
    syncModuleVisibility: {
      success: true,
    },
  },
};

describe('Apply module visibility', () => {
  beforeEach(() => {
    cy.server();
    cy.task('getSchema').then(schema => {
      cy.mockGraphql({
      schema,
      // endpoint: '/api/graphql'
      mocks,
      operations,
    });
    });
  });

  it('clicks through the UI', () => {
    // Cypress.config({
    //   baseUrl: 'http://localhost:8080',
    // });
    cy.viewport('macbook-15');

    // login as teacher
    cy.fakeLogin('nico.zickgraf', 'test');
    // cy.apolloLogin('nico.zickgraf', 'test');
    // cy.wait('@gqlBetaLogin');
    // go to module
    cy.visit('/module/lohn-und-budget');
    cy.selectClass('Andere Klasse');
    // click on settings
    cy.getByDataCy('module-settings-button').click();
    // click on select button
    cy.getByDataCy('select-school-class-button').click();
    // select schoolclass
    cy.getByDataCy('school-class-visibility-dropdown').select('FLID2018a');
    // save changes
    cy.getByDataCy('save-visibility-button').click();

    cy.getByDataCy('module-title').should('exist');
  });
});
