"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const checkoutHelpers_1 = require("./helpers/checkoutHelpers");
const checkoutTestData_1 = require("./data/checkoutTestData");
// This test just runs on the Frontend Demo, as it needs to actually be able to check out with fake payment details.
const url = 'http://localhost:9000/';
(0, test_1.test)(`can checkout on ${url}, and then go back and checkout again.`, (_a) => __awaiter(void 0, [_a], void 0, function* ({ page }) {
    // This test can take a while to complete if we need to check various different date ranges to find
    // an available check-in and check-out date, so we need to increase the timeout.
    test_1.test.setTimeout(60000); // 1 minute.
    yield page.goto(url);
    yield test_1.test.step('Select available dates', () => __awaiter(void 0, void 0, void 0, function* () {
        const foundAvailableDates = yield (0, checkoutHelpers_1.selectAvailableDates)(page);
        if (!foundAvailableDates) {
            console.error('Unable to find available dates after maximum retries.');
            test_1.test.fail();
            return;
        }
    }));
    yield test_1.test.step('Proceed to confirmation step', () => __awaiter(void 0, void 0, void 0, function* () {
        yield (0, checkoutHelpers_1.proceedToConfirmationStep)(page);
    }));
    yield test_1.test.step('Fill contact and payment information', () => __awaiter(void 0, void 0, void 0, function* () {
        yield (0, checkoutHelpers_1.fillContactInfo)(page, checkoutTestData_1.checkoutTestDataDefault);
        yield (0, checkoutHelpers_1.fillPaymentInformation)(page, checkoutTestData_1.checkoutTestDataDefault);
    }));
    yield test_1.test.step('Submit the reservation', () => __awaiter(void 0, void 0, void 0, function* () {
        yield (0, checkoutHelpers_1.submitBookingReservation)(page);
    }));
    yield test_1.test.step('Verify booking confirmation', () => __awaiter(void 0, void 0, void 0, function* () {
        yield (0, checkoutHelpers_1.verifyBookingConfirmation)(page, checkoutTestData_1.checkoutTestDataDefault);
    }));
    // Now that we've checked out, we want to test that we can navigate back to a previous step
    yield test_1.test.step('Go back to Choose Accommodation step.', () => __awaiter(void 0, void 0, void 0, function* () {
        // Clicking any step after 'Choose Accommodation' should take us back to 'Choose Accommodation'.
        // Let's click on the Confirmation step.
        const confirmationStepLink = page.locator('.step-selector__item p.text-body:has-text("Confirmation")');
        yield (0, test_1.expect)(confirmationStepLink).toBeVisible();
        yield confirmationStepLink.click({ force: true }); // Force because of the <a> element which intercepts the click.
        // We should now be on the 'Choose Accommodation step'.
        const currentStep = page.locator('.step-selector__item.is-current');
        yield (0, test_1.expect)(currentStep).toContainText('Choose Accommodation');
    }));
    yield test_1.test.step('Try to click back to the Thanks step (this should be prevented).', () => __awaiter(void 0, void 0, void 0, function* () {
        const thanksStepContainer = page.locator('.step-selector__item:has(p.text-body:has-text("Thanks"))');
        const thanksStepAnchor = thanksStepContainer.locator('a');
        // The step container should have the 'not-allowed' cursor.
        const cursorStyle = yield thanksStepContainer.evaluate((element) => {
            return window.getComputedStyle(element).cursor;
        });
        (0, test_1.expect)(cursorStyle).toBe('not-allowed');
        // This link shouldn't be clickable.
        yield (0, test_1.expect)(thanksStepAnchor).not.toBeVisible();
    }));
    yield test_1.test.step('Check out again, using the same dates but with different contact information.', () => __awaiter(void 0, void 0, void 0, function* () {
        yield (0, checkoutHelpers_1.proceedToConfirmationStep)(page);
        yield (0, checkoutHelpers_1.fillContactInfo)(page, checkoutTestData_1.checkoutTestDataSecondary);
        yield (0, checkoutHelpers_1.fillPaymentInformation)(page, checkoutTestData_1.checkoutTestDataSecondary);
        yield (0, checkoutHelpers_1.submitBookingReservation)(page);
        yield (0, checkoutHelpers_1.verifyBookingConfirmation)(page, checkoutTestData_1.checkoutTestDataSecondary);
    }));
}));
//# sourceMappingURL=goBackAndCheckoutAgain.spec.js.map