import Routing from '../../../../pages/eui/10x/routing-10x.js'
import MFileUploadPage from '../../../../pages/eui/10x/ux/ux-m-file-upload-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <ux-m-file-upload> Component Object', async () => {
  let page = new MFileUploadPage();
  it('should navigate to <ux-file-upload> demo page', async () => {
    browser.addTestMeta({uuid:"4ec64846-c9c8-11eb-b8bc-0242ac130003", zephyrKey: "CCQA-1088", zephyrStep: "407715", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-file-upload'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let navigationList = await $(page.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-file-upload> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-file-upload', 'Page title text is not as expected')
    await expect(await $(page.appDocPageById('ux-file-upload'))).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-m-file-upload> on page ', async () => {
    browser.addTestMeta({zephyrStep: "407716"});
    let sectionId= 'reactiveForms';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let fileUpload = page.fileUploadByIndex(1);
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'<reactiveForms> section -> is not visible on page'});
    await (await $(fileUpload.currentPath)).scrollIntoView();
    await expect(await $(fileUpload.currentPath)).toBeDisplayedInViewport({message:'FileUpload by index "1" is not visible on page'});
    await expect(await $(page.fileUploadByTextContains('test.pdf').currentPath)).toBeDisplayedInViewport({message:'FileUpload by text "test.pdf" is not visible on page'});
    await expect(await fileUpload.defaultComponentsCount()).toBe(6,'There should be 6 <ux-m-file-upload> components on the page.');
  });
  it('should verify the ux-m-file-upload CO methods ', async () => {
    browser.addTestMeta({zephyrStep: "407717"});
    let sectionId= 'reactiveForms';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let fileUpload = page.fileUploadByIndex(1);
    await (await $(fileUpload.currentPath)).scrollIntoView();
    await expect(await $(fileUpload.currentPath)).toBeDisplayedInViewport({message:'currentPath is not visible on page'});
    await expect(await $(fileUpload.matCardCO.currentPath)).toBeDisplayedInViewport({message:'matCardCO currentPath is not visible on page'});
    await expect(await $(fileUpload.fileInfo)).toBeDisplayedInViewport({message:'fileInfoName is not visible on page'})
    await expect(await $(fileUpload.section)).toBeDisplayedInViewport({message:'section is not visible on page'});
    await expect(await $(fileUpload.matProgressBarCO.currentPath)).
      toBeDisplayedInViewport({message:'matProgressBarCO currentPath is not visible on page'});
    await expect(await $(fileUpload.uxMFileUploadQueueDiv)).
      toBeDisplayedInViewport({message:'div is not visible on page'});
    await expect(await $(fileUpload.uploadFileIcon)).
      toBeDisplayedInViewport({message:'uploadFileIcon is not visible on page'});
    await expect(await $(fileUpload.removeFileIcon)).
      toBeDisplayedInViewport({message:'removeFileIcon is not visible on page'});
    await expect(await $(fileUpload.fileInfoProgressPerc)).
      toBeDisplayedInViewport({message:'fileInfoProgressPerc is not visible on page'});
     });
  it('should verify remove file with removeFileIcon ', async () => {
    browser.addTestMeta({zephyrStep: "407718"});
    let sectionId= 'reactiveForms';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let fileUpload = page.fileUploadFromSectionById(sectionId);
    await (await $(fileUpload.currentPath)).scrollIntoView();
    let removeIcon = await $(fileUpload.removeFileIcon);
    await expect(removeIcon).toBeDisplayedInViewport({message:'removeFileIcon is not visible on page'});
    let countBefore =  await (await $$(fileUpload.removeFileIcon)).length;
    await browser.execute("arguments[0].click();" , removeIcon);
    let countAfter =  await (await $$(fileUpload.removeFileIcon)).length;
    await expect(countBefore).toBe(countAfter+1);
  });
  it('should verify progress in % ', async () => {
    browser.addTestMeta({zephyrStep: "409826"});
    let sectionId= 'reactiveForms';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let fileUpload = page.fileUploadFromSectionById(sectionId);
    let progressBar = fileUpload.matProgressBarCO;
    await expect(await $(progressBar.primary)). toExist({message:'progressBar.primary is not existing on page'});
    await expect(await progressBar.progressPercentage()).toBe(0);
  });
});
