import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import DiscussionThreadPage from '../../../../pages/eui/10x/ux/ux-discussion-thread-10x.po.js'

describe('eUI - <ux-discussion-thread> Component Object', async () => {
  let disThreadPage = new DiscussionThreadPage();
  it('should navigate to <ux-discussion-thread> component', async () => {
   browser.addTestMeta({uuid:"87a31474-bd65-11eb-8529-0242ac130003", zephyrKey: "CCQA-1055", zephyrStep: "398099", reportGroups: ["eUI.10x.ux"]});
   await disThreadPage.open(Routing.getUxComponentUrl('ux-discussion-thread'));
   await CookieBannerActions.cookieBanner(true);
   let pgTitle = await $(disThreadPage.pageTitle);
   let appDocPageId = await $(disThreadPage.appDocPageById('ux-discussion-thread'));
   let navigationList = await $(disThreadPage.navigationList);

   await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-discussion-thread> page title is not visible on page'});
   await expect(pgTitle).toHaveText('ux-discussion-thread', {wait: 1000, message: '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 and number of component objects <ux-discussion-thread> on page ', async () => {
   browser.addTestMeta({zephyrStep: "398100"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(disThreadPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let threadItem = disThreadPage.threadByIndex(1);
   await expect(await $(disThreadPage.sectionById(sectionId))).
      toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
   await expect(await $(threadItem.dataE2E)).
      toBeDisplayedInViewport({message:'Discussion thread by index "1" is not visible on page'});
   await expect(await $(disThreadPage.threadByTextContains('Name Firstname').dataE2E)).
      toBeDisplayedInViewport({message:'Discussion thread by text "Name Firstname" is not visible on page'});
   await expect(await $(disThreadPage.threadByTextEqualsAndIndex('Name Firstname', 1).dataE2E)).
      toBeDisplayedInViewport({message:'Discussion thread by text "Name Firstname" and index 1 is not visible on page'});
   await expect(await threadItem.defaultComponentsCount()).toBe(4,
      'There should be 4 <ux-discussion-thread> components on the page.');
  });
  it('should verify the presence and number of component objects <ux-discussion-thread-item> on page ', async () => {
   browser.addTestMeta({zephyrStep: "398101"});
   let sectionId = 'Default';
   let scrollIntoSection = await $(disThreadPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let threadItem = disThreadPage.threadItemByIndex(1);
   await expect(await $(disThreadPage.sectionById(sectionId))).toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
   await expect(await $(threadItem.dataE2E)).toBeDisplayedInViewport({message:'Discussion thread item by index "1" is not visible on page'});
   await expect(await $(disThreadPage.threadItemByTextContains('Name Firstname').dataE2E)).
      toBeDisplayedInViewport({message:'Discussion thread item by text "Name Firstname" is not visible on page'});
   await expect(await $(disThreadPage.threadItemByTextEqualsAndIndex('Name Firstname', 1).dataE2E)).
      toBeDisplayedInViewport({message:'Discussion thread item by text "Name Firstname" and index 1 is not visible on page'});
   await expect(await threadItem.defaultComponentsCount()).toBe(12,
      'There should be 12 <ux-discussion-thread-item> components on the page.');
  });
  it('should verify the ux-discussion-thread CO methods: title, subtitle, list, discussionThreadItemCO ', async () => {
   browser.addTestMeta({zephyrStep: "398102"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(disThreadPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let thread = disThreadPage.threadByIndex(1);
   await expect(await $(thread.title)).toBeDisplayedInViewport({message:'title is not visible on page'});
   await expect(await $(thread.subtitle)).toBeDisplayedInViewport({message:'subtitle is not visible on page'});
   await expect(await $(thread.list)).toBeDisplayedInViewport({message:'list is not visible on page'});
   await expect(await $(thread.discussionThreadItemCO.currentPath)).
      toBeDisplayedInViewport({message:'discussionThreadItemCO.currentPath is not visible on page'});
   threadItem = thread.discussionThreadItemCO.byIndex(1);
   await expect(await $(threadItem.currentPath)).toHaveTextContaining('Name Firstname');

  });
  it('should verify the ux-discussion-thread-item CO method: badge, icon, panel, header, heading, title ', async () => {
   browser.addTestMeta({zephyrStep: "398103"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(disThreadPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let threadItem= disThreadPage.threadItemByIndex(1);
   await expect(await $(threadItem.badge)).toBeDisplayedInViewport({message:'badge is not visible on page'});
   await expect(await $(threadItem.icon)).toBeDisplayedInViewport({message:'badgeSpan is not visible on page'});
   await expect(await $(threadItem.panel)).toBeDisplayedInViewport({message:'panel is not visible on page'});
   await expect(await $(threadItem.header)).toBeDisplayedInViewport({message:'header is not visible on page'});
   await expect(await $(threadItem.heading)).toBeDisplayedInViewport({message:'heading is not visible on page'});
   await expect(await $(threadItem.title)).toBeDisplayedInViewport({message:'title is not visible on page'});
  });

  it('should verify discussion thread in modal content ', async () => {
   browser.addTestMeta({zephyrStep: "398117"});
   let sectionId= 'content-modal';
   let scrollIntoSection = await $(disThreadPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   await (await $(disThreadPage.buttonComponentByTextContains('Open modal').currentPath)).click();
   await expect(await $(disThreadPage.modalThreadCO.currentPath)).toBeDisplayedInViewport({message:'Discussion thread is not visible in modal'});
   await expect(await $(disThreadPage.modalThreadCO.discussionThreadItemCO.currentPath)).
     toBeDisplayedInViewport({message:'Discussion thread item is not visible in modal'});
  })
  it('should verify iconClass, styleClass', async () => {
   browser.addTestMeta({zephyrStep: "398137"});
   let sectionId = 'Default';
   let scrollIntoSection = await $(disThreadPage.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let thread = disThreadPage.threadByIndex(1);
   await expect(await $(thread.discussionThreadItemByIndex(1).icon)).toHaveAttrContaining('class', 'ux-icon-more-horizontal');
   await expect(await $(thread.discussionThreadItemByIndex(2).icon)).toHaveAttrContaining('class', 'ux-icon-more-horizontal');
   await expect(await $(thread.discussionThreadItemByIndex(3).icon)).toHaveAttrContaining('class', 'ux-icon-info');
   await expect(await $(thread.discussionThreadItemByIndex(4).icon)).toHaveAttrContaining('class', 'ux-icon-check');
   await expect(await $(thread.discussionThreadItemByIndex(5).icon)).toHaveAttrContaining('class', 'ux-icon-exclamation');
   await expect(await $(thread.discussionThreadItemByIndex(6).icon)).toHaveAttrContaining('class', 'ux-icon-times');
   await expect(await $(thread.discussionThreadItemByIndex(7).icon)).toHaveAttrContaining('class', 'ux-icon-more-horizontal');

   await expect(await $(thread.discussionThreadItemByIndex(1).badge)).toHaveAttrContaining('class', 'secondary');
   await expect(await $(thread.discussionThreadItemByIndex(2).badge)).toHaveAttrContaining('class', 'primary');
   await expect(await $(thread.discussionThreadItemByIndex(3).badge)).toHaveAttrContaining('class', 'info');
   await expect(await $(thread.discussionThreadItemByIndex(4).badge)).toHaveAttrContaining('class', 'success');
   await expect(await $(thread.discussionThreadItemByIndex(5).badge)).toHaveAttrContaining('class', 'warning');
   await expect(await $(thread.discussionThreadItemByIndex(6).badge)).toHaveAttrContaining('class', 'danger');
   await expect(await $(thread.discussionThreadItemByIndex(7).badge)).toHaveAttrContaining('class', 'accent');
  });


});
