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

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

  it('shows the onboarding steps and finishes them', () => {
    let onboardingVisited = false;
    cy.mockGraphqlOps({
      operations: {
        MeQuery: () => ({
          me: {
            onboardingVisited,
          },
        }),
        UpdateOnboardingProgress: () => {
          onboardingVisited = true;
          return {
            updateOnboardingProgress: {
              success: true,
            },
          };
        },
        NewsTeasers: {}
      },
    });

    cy.visit('/');
    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();
    assertStartPage(false);
  });

  it('shows the onboarding steps and skips them', () => {
    let onboardingVisited = false;
    cy.mockGraphqlOps({
      operations: {
        MeQuery: {
          me: {
            onboardingVisited,
          },
        },
        UpdateOnboardingProgress: () => {
          onboardingVisited = true;
          return {
            updateOnboardingProgress: {
              success: true,
            },
          };
        },
      },
    });

    cy.visit('/');
    assertStartPage(true);
    cy.getByDataCy('onboarding-skip-link').click();
    assertStartPage(false);
  });

  it('does not show the onboarding', () => {
    cy.mockGraphqlOps({
      operations: {
        MeQuery: {
          me: {}
        }
      },
    });

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