import { getInsuranceCreateData } from '@/manager/modules/insurance/insurance-factories';
import { test } from '@/manager/modules/insurance/insurance-fixtures';
import { applyInsuranceEditBookingPortal } from '@/manager/modules/insurance/insurance-mappers';
import { insuranceEditBookingPortalHappyTestCases } from '@/manager/modules/insurance/test-cases/insurance-edit-booking-portal-happy-test-cases';
import { expectSingleLocatorToHaveText } from '@/manager/shared/utils/expect-utils';

for (const tc of insuranceEditBookingPortalHappyTestCases) {
  test(tc.description, async ({ createInsurance, insuranceDetailsPage }) => {
    const insurance = await createInsurance(getInsuranceCreateData(tc.initialOptions));
    const newInsurance = applyInsuranceEditBookingPortal(insurance, tc.changes);
    const shortDescription = newInsurance.shortDescription?.[newInsurance.location.customerDefaultLanguage.id];

    await insuranceDetailsPage.goto(insurance.id);

    const newDetailsPage = await test.step('edit insurance booking portal', async () => {
      const dialog = await insuranceDetailsPage.openInsuranceEditBookingPortalDialog();
      return dialog.edit(tc.changes);
    });

    await test.step('verify new insurance booking portal on details page', async () => {
      await expectSingleLocatorToHaveText(newDetailsPage.bookingPortalCard.shortDescription, shortDescription);
    });
  });
}
