"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const experimental_ct_react_1 = require("@playwright/experimental-ct-react");
const exam_engine_mastering_1 = require("@digabi/exam-engine-mastering");
const Exam_story_1 = require("../stories/exam/Exam.story");
const AudioPlayer_page_1 = require("../pages/AudioPlayer.page"); // Import the Page Object
const path_1 = __importDefault(require("path"));
const AUDIO_FILE_NAME = 'audio-5s.mp3';
// Renamed for clarity
const AUDIO_PLAYER_EXAM_XML = `<e:exam xmlns:e="http://ylioppilastutkinto.fi/exam.xsd" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ylioppilastutkinto.fi/exam.xsd https://abitti.dev/schema/exam.xsd" exam-schema-version="0.5">
    <e:exam-versions>
        <e:exam-version lang="fi-FI"/>
    </e:exam-versions>
    <e:exam-title>Uusi koe</e:exam-title>
    <e:exam-instruction/>
    <e:table-of-contents/>
    <e:section>
        <e:section-title/>
        <e:section-instruction/>
        <e:question>
            <e:question-title/>
            <e:question-instruction/>
            <e:audio src="${AUDIO_FILE_NAME}"/>
        </e:question>
    </e:section>
</e:exam>`;
const test = experimental_ct_react_1.test.extend({
    audioPlayerPage: async ({ page, mount }, use) => {
        const resolveAttachment = (filename) => path_1.default.resolve(__dirname, '../data', filename);
        const results = await (0, exam_engine_mastering_1.masterExam)(AUDIO_PLAYER_EXAM_XML, () => '', (0, exam_engine_mastering_1.getMediaMetadataFromLocalFile)(resolveAttachment));
        const masteredExamXml = results[0];
        await page.route(`**/attachments/${AUDIO_FILE_NAME}`, async (route) => {
            await route.fulfill({
                status: 200,
                contentType: 'audio/mpeg',
                path: path_1.default.resolve(__dirname, `../data/${AUDIO_FILE_NAME}`)
            });
        });
        const mountResult = await mount(react_1.default.createElement(Exam_story_1.ExamStory, { masteredExam: masteredExamXml }));
        const audioPlayerPageInstance = new AudioPlayer_page_1.AudioPlayerPage(mountResult);
        await use(audioPlayerPageInstance);
    }
});
test('all UI elements are visible and in correct state', async ({ audioPlayerPage }) => {
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.playButton).toBeVisible();
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toBeVisible();
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveAttribute('aria-label', 'Aikajana');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveAttribute('aria-valuetext', '00:00/00:05');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveAttribute('style', /--range-progress: 0%/);
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.currentTimeDisplay).toHaveText('00:00');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.durationDisplay).toHaveText('00:05');
});
test('player is in correct state after playing whole audio', async ({ page, audioPlayerPage }) => {
    await audioPlayerPage.playButton.click();
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.pauseButton).toBeVisible();
    await page.waitForTimeout(6000);
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.currentTimeDisplay).toHaveText('00:05');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.durationDisplay).toHaveText('00:05');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.playButton).toBeVisible();
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveValue(/5\.\d*/);
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveAttribute('aria-label', 'Aikajana');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveAttribute('aria-valuetext', '00:05/00:05');
    await (0, experimental_ct_react_1.expect)(audioPlayerPage.progressBar).toHaveAttribute('style', /--range-progress: 100%/);
});
//# sourceMappingURL=AudioPlayer.test.js.map