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

const me = require('../../fixtures/me.join-class.json');

describe('Onboarding', () => {
  beforeEach(() => {
    cy.server();

    cy.task('getSchema').then(schema => {
      cy.mockGraphql({
        schema,
      });
    });
  });

  it('shows the onboarding steps and finishes them', () => {
    cy.fakeLogin('hansli', 'test');

    cy.mockGraphqlOps({
      operations: {
        MeQuery: {
          me: {
            ...me.me,
            onboardingVisited: false
          }
        },
        ...mockUpdateOnboardingProgress()
      }
    });

    cy.visit('/');
    cy.assertStartPage(true);
    cy.get('[data-cy=onboarding-next-link]').click();
    cy.get('[data-cy=onboarding-next-link]').click();
    cy.get('[data-cy=onboarding-next-link]').click();
    cy.get('[data-cy=onboarding-next-link]').click();
    cy.assertStartPage(false);
  });

  it('shows the onboarding steps and skips them', () => {
    cy.fakeLogin('hansli', 'test');

    cy.mockGraphqlOps({
      operations: {
        MeQuery: {
          me: {
            ...me.me,
            onboardingVisited: false
          }
        },
        ...mockUpdateOnboardingProgress()
      }
    });

    cy.visit('/');
    cy.assertStartPage(true);
    cy.skipOnboarding();
    cy.assertStartPage(false);
  });

  it('does not show the onboarding', () => {
    cy.fakeLogin('hansli', 'test');

    cy.mockGraphqlOps({
      operations: {
        MeQuery: me,
        ...mockUpdateOnboardingProgress()
      }
    });

    cy.visit('/');
    cy.assertStartPage(false);
  });
});
