import euiLandingPage from '../../pages/eui/10x/ux/ux/landing-10x.po.js';
import EuiBasePage from '../../pages/eui/10x/eui-base.po.js';
import CookieBannerActions from '../../actions/cookieBanner.js';
import LangSelector from '../../actions/langSelector.js';

describe('Navigate to eUI Showcase page @CCQA-875', () => {
  let landingPage = new euiLandingPage();
  let euiBasePage = new EuiBasePage();

  it('should navigate to eUI Main page', async () => {
    browser.addTestMeta({uuid:"79a5c6ec-faa1-43a3-9dbb-4bab971ea4c5", zephyrKey: "CCQA-875", zephyrStep: "375458", reportGroups: ["eUI.10x.ux"]});
    await landingPage.open();
  });
  it('should accept cookies', async () => {
    browser.addTestMeta({zephyrStep: "375459"});
    await CookieBannerActions.cookieBanner(true);
  });
  it('should verify the landing page and navigate to showcase-ux-10.x section and button', async () => {
    browser.addTestMeta({zephyrStep: "375460"});
    let landingPage = new euiLandingPage();
    // let wt = await $(landingPage.welcomeText);
    let gsLink = await $(landingPage.getlinkByText('Get Started'));
    let container = await $(landingPage.getEuiShowcaseContainerByText('Components, patterns and services'));

    // wt.waitForDisplayed({timeout:3000, timeoutMsg:'Welcome text is not present in main page', interval:100});

    // gsLink.waitForDisplayed({timeout:3000, timeoutMsg:'<Get Started> button is not visible', interval:100});
    if (await gsLink.isExisting()){
      await gsLink.click();
    }
    await container.waitForDisplayed({timeout:3000, timeoutMsg:'<Components, patterns and services> section is not visible on page', interval:100});
  });
  it('should click on the 10.x version button and verify the opened page', async () => {
    browser.addTestMeta({zephyrStep: "375461"});
    let versionButton = await $(landingPage.getEuiLastVersionButtonFromContainerWithText('Components, patterns and services'))

    await versionButton.waitForDisplayed({timeout:3000, timeoutMsg:'Version 10.x button is not visible on page', interval:100});

    await versionButton.click();

    // header.waitForDisplayed({timeout:10000, timeoutMsg:'Welcome text is not present in main page', interval:100});

    let header = await $(euiBasePage.pageHeader);
    await global.chaiExpect(await header.getText()).to.contain('Welcome to eUI');

  });
  it('should verify the page language and change it to EN if it\'s needed', async () => {
    browser.addTestMeta({zephyrStep: "375462"});
    await LangSelector.languageSelector('EN');

  });
});
