import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import ButtonGroupPage from '../../../../pages/eui/10x/ux/ux-button-group-10x.po.js'

describe('eUI - <ux-button-group> Component Object @CCQA-724', async() => {
  let buttonGroupPage = new ButtonGroupPage();
  it('should navigate to <ux-button-group> component', async() => {
    browser.addTestMeta({uuid:"b2782f00-8029-11eb-9439-0242ac130002", zephyrKey: "CCQA-724", zephyrStep: "361446", reportGroups: ["eUI.10x.ux"]});
    await buttonGroupPage.open(Routing.getUxComponentUrl('ux-button-group'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(buttonGroupPage.pageTitle);
    let appDocPageId = await $(buttonGroupPage.appDocPageById('ux-button-group'));
    let navigationList = await $(buttonGroupPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-button-group> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-button-group', 'Page title text is not as expected')
    await expect(appDocPageId).toExist({wait:1000, message:'Page Id is not present in page'});
    await expect(navigationList).toBeDisplayed({wait:1000, message:'Navigation List -> is not visible on page'});
  });
  it('should identify <ux-button-group> from page after specific methods', async() => {
    browser.addTestMeta({zephyrStep: "361447"});
    let buttonGroup = await $(buttonGroupPage.buttonGroupFromSectionById('Default').dataE2E);
    await expect(buttonGroup).toBeDisplayed({wait:3000, message:'<Default> section -> is not visible on page'});

    let buttonGroup1 = await $(buttonGroupPage.buttonGroupByIndex(1).dataE2E);
    let buttonGroup2 = await $(buttonGroupPage.buttonGroupByTextContains('button 1').dataE2E);
    let buttonGroup3 = await $(buttonGroupPage.buttonGroupByTextEqualsAndIndex('button 1', 1).dataE2E);

    await expect(buttonGroup1).toBeDisplayed({wait:3000, message:'Button group by index "1" is not visible on page'});
    await expect(buttonGroup2).toBeDisplayed({wait:3000, message:'Button group by text "button 1" is not visible on page'});
    await expect(buttonGroup3).toBeDisplayed({wait:3000, message:'Button group by text "button 1" and index 1 is not visible on page'});
    await chaiExpect(await buttonGroupPage.buttonGroupByIndex(1).defaultComponentsCount()).equal(41, 'There should be 41 <ux-button-group> components on the page.')
  });
  it('should verify the properties buttonContent, buttonIcon, buttonRadio, buttonCheckbox', async() => {
    browser.addTestMeta({zephyrStep: "361448"});
    let sectionId= 'checkbox-buttons';
    let scrollIntoSection = await $(buttonGroupPage.buttonGroupFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    let buttonGroup1 = buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).buttonGroupCheckboxButtonCO;

    await expect(await $(buttonGroup1.currentPath)).toBeDisplayed({wait:3000, message:
      'checkbox button with index 1 from checkbox-buttons section, currentPath is not visible on page'});
    await (await $(buttonGroup1.inputCheckbox)).isExisting({timeout:1000,  timeoutMsg:
      'checkbox button with index 1 from checkbox-buttons section, inputCheckbox property is not existing on page', interval:100});
    await expect(await $(buttonGroup1.buttonIcon)).toBeDisplayed({wait:3000, message:
      'checkbox button with index 1 from checkbox-buttons section, buttonIcon propertyis not visible on page'});

    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).isCheckboxButtons()).toBe(true, 'isCheckboxButtons should be true' );
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).isRadioButtons()).toBe(false, 'isRadioButtons should be false' );
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).hasPairedIcon()).toBe(false, 'hasPairedIcon should be false' );

    sectionId= 'radio-buttons';
    scrollIntoSection = await $(buttonGroupPage.buttonGroupFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    buttonGroup1 = buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).buttonGroupRadioButtonCO;
    await expect(await $(buttonGroup1.currentPath)).toBeDisplayed({wait:3000, message:
      'Radiobutton with index 1 from radio-buttons section, currentPath is not visible on page'});
    await (await $(buttonGroup1.inputRadio)).isExisting({timeout:1000,  timeoutMsg:
      'Radiobutton with index 1 from radio-buttons section, inputRadio property is not existing on page', interval:100});
    await expect(await $(buttonGroup1.buttonIcon)).toBeDisplayed({wait:3000, message:
      'Radiobutton with index 1 from radio-buttons section, buttonIcon propertyis not visible on page'});
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).isRadioButtons()).toBe(true, 'isRadioButtons should be true' );
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).isCheckboxButtons()).toBe(false, 'isCheckboxButtons should be false' );
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).hasPairedIcon()).toBe(false, 'hasPairedIcon should be false' );


    sectionId= 'hasPairedIcon';
    scrollIntoSection = await $(buttonGroupPage.buttonGroupFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    buttonGroup1 = buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).buttonGroupIconButtonCO;

    await expect(await $(buttonGroup1.currentPath)).toBeDisplayed({wait:3000, message:
      'Paired icon with index 1 from hasPairedIcon section, currentPath is not visible on page'});
    await (await $(buttonGroup1.buttonIcon)).isExisting({timeout:1000,  timeoutMsg:
      'Paired icon with index 1 from hasPairedIcon section, buttonIcon property is not existing on page', interval:100});
    await expect(await $(buttonGroup1.buttonIconOnly)).toBeDisplayed({wait:3000, message:
      'Paired icon with index 1 from hasPairedIcon section, buttonIconOnly propertyis not visible on page'});
    await expect(await $(buttonGroup1.buttonContent)).toBeDisplayed({wait:3000, message:
      'Paired icon with index 1 from hasPairedIcon section, buttonContent propertyis not visible on page'});
    await expect(await (await $(buttonGroup1.buttonContent)).getText()).toContain('test.button.label');
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).hasPairedIcon()).toBe(true, 'hasPairedIcon should be true' );
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).isCheckboxButtons()).toBe(false, 'isCheckboxButtons should be false' );
    await expect(await buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1).isRadioButtons()).toBe(false, 'isRadioButtons should be false' );

  });
  it('should verify the "isActive" method ', async() => {
    browser.addTestMeta({zephyrStep: "361449"});
    let sectionId= 'checkbox-buttons';
    let scrollIntoSection = await $(buttonGroupPage.buttonGroupFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    let buttonGroup1 = buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonGroup1.dataE2E)).toBeDisplayed({wait:3000, message:
      'Button group with index 1 from checkbox-buttons section is not visible on page'});

    await expect(await buttonGroup1.buttonGroupCheckboxButtonCO.byIndex(1).isActive()).toBe(true, 'isActive should be true ');
    await expect(await buttonGroup1.buttonGroupCheckboxButtonCO.byIndex(2).isActive()).toBe(false, 'isActive should be false ');

    sectionId= 'radio-buttons-typeClass-outline';
    scrollIntoSection = await $(buttonGroupPage.buttonGroupFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    buttonGroup1 = buttonGroupPage.buttonGroupFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonGroup1.dataE2E)).toBeDisplayed({wait:3000, message:
      'Button group with index 1 from radio-buttons-typeClass-outline section is not visible on page'});
    await expect(await buttonGroup1.buttonGroupRadioButtonCO.byIndex(1).isActive()).toBe(true, 'isActive should be true ');
    await expect(await buttonGroup1.buttonGroupRadioButtonCO.byIndex(2).isActive()).toBe(false, 'isActive should be false ');
  });
});
