"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fixtures_1 = require("./fixtures");
fixtures_1.test.describe('MouseClickEventHandler', () => {
    fixtures_1.test.describe('handleMouseDownEvent - snapshot', () => {
        (0, fixtures_1.test)('should send snapshot message when click occurs', async ({ contentJs, }) => {
            await contentJs.setContentAndInject(`
        <html>
          <body>
            <button id="test-button">Click me</button>
          </body>
        </html>
      `);
            const initialCount = contentJs.receivedMessages.length;
            await contentJs.page.click('#test-button');
            const newMessages = contentJs.receivedMessages.slice(initialCount);
            const snapshotMessages = newMessages.filter((msg) => msg.action === 'snapshot' && msg.listener === 'snapshot');
            (0, fixtures_1.expect)(snapshotMessages.length).toBeGreaterThanOrEqual(1);
            (0, fixtures_1.expect)(snapshotMessages[0]).toMatchObject({
                action: 'snapshot',
                listener: 'snapshot',
                xPath: '',
            });
            (0, fixtures_1.expect)(snapshotMessages[0]).toHaveProperty('sourceEventTimeStamp');
            (0, fixtures_1.expect)(snapshotMessages[0]).toHaveProperty('frameInfo');
        });
    });
    fixtures_1.test.describe('click event recording', () => {
        (0, fixtures_1.test)('should record click event on button click', async ({ contentJs }) => {
            await contentJs.setContentAndInject(`
        <html>
          <body>
            <button id="test-button">Click me</button>
          </body>
        </html>
      `);
            const initialCount = contentJs.receivedMessages.length;
            await contentJs.page.click('#test-button');
            const newMessages = contentJs.receivedMessages.slice(initialCount);
            const clickMessage = newMessages.find((msg) => msg.action === 'record' && msg.listener === 'click');
            (0, fixtures_1.expect)(clickMessage).toBeDefined();
            (0, fixtures_1.expect)(clickMessage).toMatchObject({
                action: 'record',
                listener: 'click',
            });
        });
        (0, fixtures_1.test)('should record right-click event', async ({ contentJs }) => {
            await contentJs.setContentAndInject(`
        <html>
          <body>
            <div id="right-clickable" style="width: 100px; height: 100px;">Right click me</div>
          </body>
        </html>
      `);
            const initialCount = contentJs.receivedMessages.length;
            await contentJs.page.click('#right-clickable', { button: 'right' });
            const newMessages = contentJs.receivedMessages.slice(initialCount);
            const rightClickMessage = newMessages.find((msg) => msg.action === 'record' && msg.listener === 'right-click');
            (0, fixtures_1.expect)(rightClickMessage).toBeDefined();
            (0, fixtures_1.expect)(rightClickMessage).toMatchObject({
                action: 'record',
                listener: 'right-click',
            });
        });
        (0, fixtures_1.test)('should not record click on file input element', async ({ contentJs, }) => {
            await contentJs.setContentAndInject(`
        <html>
          <body>
            <input type="file" id="file-input" />
          </body>
        </html>
      `);
            const initialCount = contentJs.receivedMessages.length;
            await contentJs.page.evaluate(() => {
                const fileInput = document.getElementById('file-input');
                fileInput?.dispatchEvent(new PointerEvent('pointerdown', {
                    bubbles: true,
                    pointerType: 'mouse',
                }));
                fileInput?.dispatchEvent(new PointerEvent('pointerup', { bubbles: true, pointerType: 'mouse' }));
            });
            const newMessages = contentJs.receivedMessages.slice(initialCount);
            const clickMessage = newMessages.find((msg) => msg.action === 'record' && msg.listener === 'click');
            (0, fixtures_1.expect)(clickMessage).toBeUndefined();
        });
    });
});
