import Routing from '../../../../pages/eui/10x/routing-10x.js';
import DisableContentPage from '../../../../pages/eui/10x/ux/ux-disable-content-10x.po.js';
import CookieBannerActions from '../../../../actions/cookieBanner.js';

describe('should navigate to  <ux-disable-content> Component Object @CCQA-752', async () => {
  let disableContentPage = new DisableContentPage();
  it('should navigate to <ux-disable-content> component @365095', async () => {
    await disableContentPage.open(Routing.getUxComponentUrl('ux-disable-content'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(disableContentPage.pageTitle);
    let appDocPageId = await $(disableContentPage.appDocPageById('ux-disable-content'));
    let navigationList = await $(disableContentPage.navigationList);

    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-disable-content> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-disable-content', '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 verify the presence of component object in page @365096', async () => {
    let sectionTitle = await $(disableContentPage.sectionById('Default'));
    let co1 = await (await disableContentPage.disableContentByIndex(1).element());
    let coList = await (await $$(disableContentPage.disableContentByIndex(1).byDefault().disableContentDataDiv)).length;
    await expect(sectionTitle).toBeDisplayed({wait:1000, message:'<Default> section -> is not visible on page'});
    await expect(co1).toBeDisplayed({wait:1000, message:'Disable-content by index "1" is not visible on page'});
    await expect(coList).toBe(2);
  });
  it('should verify the Disable Content CO functionality @365097', async () => {
    let sectionId= 'Default';
    let scrollIntoSection = await $(disableContentPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await disableContentPage.disableContentFromSectionWithIdByIndex(sectionId,1).isDisabled()).toBe(false, 'The isDisabled should be false');
    await (await $(disableContentPage.buttonCO.byTextContains('Disable Content').currentPath)).click();
    await expect(await disableContentPage.disableContentFromSectionWithIdByIndex(sectionId,1).isDisabled()).toBe(true, 'The isDisabled should be true');
    await (await $(disableContentPage.buttonCO.byTextContains('Un-disable Content').currentPath)).click();
  });
  it('should verify the Disable Content CO with growl confirmation @365098', async () => {
    let sectionId= 'disabledText';
    let scrollIntoSection = await $(disableContentPage.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await disableContentPage.disableContentFromSectionWithIdByIndex(sectionId,1).isDisabled()).toBe(false,
      'The isDisabled should be false');
    await (await $(disableContentPage.buttonCO.byTextContainsAndIndex('Disable Content',2).currentPath)).click();
    await expect(await disableContentPage.disableContentFromSectionWithIdByIndex(sectionId,1).isDisabled()).toBe(true,
      'The isDisabled should be true');
    await (await $(disableContentPage.panelCO.byTextEqualsAndIndex('Panel',2).currentPath)).scrollIntoView();
    browser.execute("arguments[0].click();", await $(disableContentPage.panelCO.byTextEqualsAndIndex('Panel',2).currentPath));
    await (await $(disableContentPage.growlCO.growlItem)).waitForDisplayed({ timeout: 10000, timeoutMsg:
        'Growl is not visible on page', interval: 100 });
    await expect(await (await $(disableContentPage.growlCO.byIndex('1').growlItemContainer)).getAttribute('class')).toContain('info');
  })
});
