import { storagePage } from '../../views/storagePage';
import { commonActions } from '../../views/common';
import { hostsTableSection } from '../../views/hostsTableSection';

const masterDisks = [
  {
    id: '/dev/sda-10',
    size: '17.80 GB',
    type: 'HDD',
    hostId: 'bb566d48-9b73-4047-9d4c-ae08618a5ed1',
  },
  {
    id: '/dev/sr-11',
    size: '1.05 GB',
    type: 'ODD',
    hostId: 'bb566d48-9b73-4047-9d4c-ae08618a5ed1',
  },
];

const workerDisks = [
  {
    id: '/dev/sda-40',
    size: '10.48 GB',
    type: 'HDD',
    hostId: 'cf2f3477-896f-40be-876a-b2ac3f2a838c',
  },
  {
    id: '/dev/sr-41',
    size: '1.05 GB',
    type: 'ODD',
    hostId: 'cf2f3477-896f-40be-876a-b2ac3f2a838c',
  },
];

describe(`Assisted Installer Storage Step`, () => {
  const setTestStartSignal = (activeSignal: string) => {
    cy.setTestEnvironment({
      activeSignal,
      activeScenario: 'AI_STORAGE_CLUSTER',
    });
  };

  before(() => setTestStartSignal('READY_TO_INSTALL'));

  describe(`Host storage table`, () => {
    beforeEach(() => {
      setTestStartSignal('READY_TO_INSTALL');
      commonActions.visitClusterDetailsPage();
      commonActions.startAtWizardStep('Storage');
    });

    it('Should display the existing hosts storage details', () => {
      hostsTableSection.waitForHardwareStatus('Ready');
      hostsTableSection.validateHostRoles();
      hostsTableSection.validateHostDiskSize(35.59, 20.95);
      storagePage.validateNumberOfDisks();
    });

    it('Should display the ODF usage column', () => {
      storagePage.validateODFUsage();
    });

    it('Should show the disks details', () => {
      const hosts = [
        {
          hostId: 0,
          disks: masterDisks,
        },
        {
          hostId: 3,
          disks: workerDisks,
        },
      ];

      hosts.forEach((host, index) => {
        hostsTableSection.getHostDisksExpander(host.hostId).click();
        hostsTableSection.getHostDetailsTitle(host.hostId).should('have.text', '3 Disks');
        hostsTableSection.validateHostDisksDetails(host.disks);
        hostsTableSection.getHostDisksExpander(host.hostId).click();
      });
    });

    it('Should display the skip formatting disk column, warning alert and warning icon', () => {
      const hosts = [
        {
          hostId: 3,
          realHostId: 'cf2f3477-896f-40be-876a-b2ac3f2a838c',
          disks: workerDisks,
        },
      ];

      hosts.forEach((host) => {
        hostsTableSection.getHostDisksExpander(host.hostId).click();
        storagePage.validateSkipFormattingDisks(host.realHostId, 3);
        storagePage.validateSkipFormattingWarning();
        storagePage.validateSkipFormattingIcon(workerDisks[0].id, workerDisks[0].hostId);
        hostsTableSection.getHostDisksExpander(host.hostId).click();
      });
    });
  });
});
