/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { CommandbarPage } from '../../support/commandbar.po';

describe('Visibility in the Commandbar', {retries: {openMode: 2, runMode: 2}}, () => {
  let page: CommandbarPage;

  before(() => {
    page = new CommandbarPage();
    page.navigateTo();
  });

  it('should show the commandbar', () => {
    page.getCommandBar().should('exist');
  });

  it('should show commandbar icon wishlist', () => {
    page.resizeToADesktopLandscapeSize();
    page.expectCommandbarIconVisible('wishlist');
  });

  it('should hide commandbar icon wishlist', () => {
    page.resizeToAMobileLandscapeSize();
    cy.get('bci-burger').click();
    page.expectCommandbarIconNotVisible('wishlist');
  });

  describe.skip('Badges', () => {
    it('should show 1 when selecting one filter in the options menu', () => {
      page.resizeToAMobileLandscapeSize();
      page
        .getMoreActionsButton()
        .click({force: true})
        .then(() => page.getOptionsMenuItems().eq(1).click({force: true}))
        .then(() => page.getBadgeElement().should('contain.text', 1))
        .then(() => page.clickOnBackdrop());
    });

    it('should not show anything when increasing screen size with a selected filter', () => {
      page.resizeToADesktopLandscapeSize();
      page.getBadgeElement().should('contain.text', '0');
    });

    it('should show 1 when resizing back to mobile screen size', () => {
      page.resizeToAMobileLandscapeSize();
      page.getBadgeElement().should('contain.text', '1');
    });

    it.skip('should show 2 when another filter is selected', () => {
      page
        .getCommandBarOptionsButton()
        .last()
        .click({force: true});
      page.getOptionsMenuItems().should('have.length', 6);
      page.getCommandBarSortButton().last().click();
      page.getBadgeElement().should('contain.text', '2');
    });
  });
});
