import minimalModule from '../../../fixtures/module.minimal';
import {getMinimalMe} from '../../../support/helpers';

const getOperations = ({readOnly, classReadOnly = false}) => ({
  MeQuery: getMinimalMe({readOnly, classReadOnly}),
  ModuleDetailsQuery: {
    module: {
      ...minimalModule,
    },
  },
});

const moduleNavigationTest = ({readOnly, classReadOnly = false, displayMenu}) => {
  cy.mockGraphqlOps({
      operations: getOperations({readOnly, classReadOnly}),
    });

    const shouldMenuExist = displayMenu ? 'exist' : 'not.exist';

    cy.visit('module/module-slug');

    cy.getByDataCy('module-navigation').should('exist');
    cy.getByDataCy('module-teacher-menu').should(shouldMenuExist);
};

describe('Module Navigation - read only', () => {
  beforeEach(() => {
    cy.setup();
  });

  it('is shown', () => {
    moduleNavigationTest({readOnly: false, displayMenu: true});
  });

  it('is not shown when no valid license', () => {
    moduleNavigationTest({readOnly: true, displayMenu: false});
  });

  it('is not shown when inactive school class', () => {
    moduleNavigationTest({readOnly: false, classReadOnly: true, displayMenu: false});
  });
});
