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

describe('eUI - <ux-button> Component Object @CCQA-723', async() => {
  let buttonPage = new ButtonPage();
  it('should navigate to <ux-button> component @361436', async() => {
    await buttonPage.open(Routing.getUxComponentUrl('ux-button'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(buttonPage.pageTitle);
    let appDocPageId = await $(buttonPage.appDocPageById('ux-button'));
    let navigationList = await $(buttonPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-button> page title is not displayed on page'});
    await expect(await pgTitle.getText()).toBe('ux-button', '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 displayed on page'});
  });
  it('should identify <ux-button> from page after specific methods @361437 ', async() => {
    let button1 = await $(buttonPage.buttonFromSectionById('Default').button);
    let button2 = await $(buttonPage.buttonByIndex(1).button);
    let button3 = await $(buttonPage.buttonByTextContains('awesome').button);
    let button4 = await $(buttonPage.buttonByTextEqualsAndIndex('awesome', 1).button);

    await expect(button1).toBeDisplayed({wait: 3000, message:'<Default> section -> is not displayed on page'});
    await expect(button2).toBeDisplayed({wait: 3000, message:'Button by index "1" is not displayed on page'});
    await expect(button3).toBeDisplayed({wait: 3000, message:'Button by text "awesome" is not displayed on page'});
    await expect(button4).toBeDisplayed({wait: 3000, message:'Button by text "small" and index 1 is not displayed on page'});

    await expect(await buttonPage.buttonByIndex(1).defaultComponentsCount()).toBe(107,
        'There should be 107 <ux-button> components on the page.');
  });
  it('should verify the button CO methods: buttonContent, butttonIcon, buttonByText @@361438 ', async() => {
    let sectionId= 'type';
    let scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();

    let buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,4);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:'Button with index 4 from type section is not displayed on page'});
    await expect(await (await $(buttonPage1.buttonContent)).getText()).toContain('Submit');

    sectionId= 'isFlat-iconClass';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    let buttonIcon = await $(buttonPage.buttonFromSectionWithIdByIndex(sectionId,1).buttonIcon);
    await expect(buttonIcon).toBeDisplayed({wait: 3000, message:'Button with index 1 from buttonIcon section is not displayed on page'});

    sectionId= 'isBlock';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    let blockLevelButton = await $(buttonPage.buttonByTextContains('block level button').button);
    await expect(blockLevelButton).toBeDisplayed({wait: 3000, message: 'Button by text "block level button" - is not present in page'});
  });
  it('should verify the button CO properties: isSecondary, type, typeClass, isFlat, isFlatIcon $361439 ', async() => {
    let sectionId= 'isSecondary';
    let scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    let buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isSecondary section is not displayed on page'});
    await expect(await buttonPage1.isSecondary()).toBe(true, 'isSecondary should be true ');

    sectionId= 'type';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from type section is not displayed on page'});
    await expect(await buttonPage1.type()).toContain('button');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,3).type()).toContain('reset');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,4).type()).toContain('submit');

    sectionId= 'typeClass';
    scrollIntoSection = await $(buttonPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,1).typeClass()).toContain('primary');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,2).typeClass()).toContain('secondary');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,3).typeClass()).toContain('info');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,4).typeClass()).toContain('success');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,5).typeClass()).toContain('warning');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,6).typeClass()).toContain('danger');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,7).typeClass()).toContain('accent');

    sectionId= 'isFlat';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isFlat section is not displayed on page'});
    await expect(await buttonPage1.isFlat()).toBe(true, 'isFlat should be true ');

    sectionId= 'isFlat-iconClass';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.buttonIcon)).toBeDisplayed({wait: 3000, message:
      'Button icon with index 1 from isFlat-iconClass section is not displayed on page'});
    await expect(await buttonPage1.isFlat()).toBe(true, 'isFlat should be true ');
  });
  it('should verify the button CO properties: isOutline, isSmall, isLarge, isBlock, isDisabled @361440  ', async() => {
    let sectionId= 'isOutline';
    let scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    let buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isOutline section is not displayed on page'});
    await expect(await buttonPage1.isOutline()).toBe(true, 'isOutline should be true ');

    sectionId= 'isSmall-isLarge';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isSmall-isLarge section is not displayed on page'});
    await expect(await buttonPage1.isSmall()).toBe(true, 'isSmall should be true ');
    await expect(await buttonPage.buttonFromSectionWithIdByIndex(sectionId,3).isLarge()).toBe(true, 'isLarge should be true ');

    sectionId= 'isBlock';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isBlock section is not displayed on page'});
    await expect(await buttonPage1.isBlock()).toBe(true, 'isBlock should be true ');

    sectionId= 'isDisabled';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isDisabled section is not displayed on page'});
    await expect(await buttonPage1.isDisabled()).toBe(true, 'isDisabled should be true ');
    browser.execute("arguments[0].click();", await $(buttonPage.buttonByTextContains('toggle disabled/enabled').buttonContent));
    await expect(await buttonPage1.isDisabled()).toBe(false, 'isDisabled should be false ');
  });
  it('should verify the button CO properties: iconClass, isLineWrap, styleClass @361441 ', async() => {
    let sectionId= 'iconClass';
    let scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    let buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from iconClass section is not displayed on page'});
    await expect(await buttonPage1.iconClass()).toBe('eui-icon eui-icon-dashboard', 'iconClass should be "eui-icon eui-icon-dashboard" ');

    sectionId= 'isLineWrap';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    buttonPage1 = buttonPage.buttonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(buttonPage1.button)).toBeDisplayed({wait: 3000, message:
      'Button with index 1 from isLineWrap section is not displayed on page'});
    await expect(await buttonPage1.isLineWrap()).toBe(true, 'isLineWrap should be true ');
    await expect(await buttonPage1.styleClass()).toBe('ux-u-width-10', 'styleClass should be "ux-u-width-10" ');

    sectionId= 'Dynamic-state';
    scrollIntoSection = await $(buttonPage.buttonFromSectionById(sectionId).button);
    await scrollIntoSection.scrollIntoView();
    let editButton = await $(buttonPage.buttonFromSectionById(sectionId).byTextContains('edit').button);
    let cancelButton = await $(buttonPage.buttonByTextContains('cancel').button);
    let saveButton = await $(buttonPage.buttonByTextContains('save').button);
    await expect(editButton).toBeDisplayed({wait: 3000, message:'Button with text edit is not displayed on page'});
    browser.execute("arguments[0].click();", await $(buttonPage.buttonByTextContains('Toggle edit mode').buttonContent));
    await expect(cancelButton).toBeDisplayed({wait: 3000, message:'Button with text cancel is not displayed on page'});
    await expect(saveButton).toBeDisplayed({wait: 3000, message:'Button with text save is not displayed on page'});

    sectionId= 'api';
    scrollIntoSection = await $("//docpageinteractive");
    await scrollIntoSection.scrollIntoView();
    buttonPage1 =  buttonPage.buttonByTextContains('Button label').currentPath;

    await expect(await $(buttonPage1)).toBeDisplayed({wait: 3000, message:'Button with text button label is not displayed on page'});
    await expect(await (await $(buttonPage1)).getAttribute('class')).toContain("tooltip");
  });
});
