Skip to content

Commit

Permalink
fix: revert utilites (#7209)
Browse files Browse the repository at this point in the history
* revert utilites

* fix tests

* update hammerhead and add a test
  • Loading branch information
miherlosev authored Aug 4, 2022
1 parent 76e8e9f commit fc08728
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "testcafe",
"description": "Automated browser testing for the modern web development stack.",
"license": "MIT",
"version": "1.20.1-rc.1",
"version": "1.20.1-rc.2",
"author": {
"name": "Developer Express Inc.",
"url": "https://www.devexpress.com/"
Expand Down Expand Up @@ -137,7 +137,7 @@
"source-map-support": "^0.5.16",
"strip-bom": "^2.0.0",
"testcafe-browser-tools": "2.0.23",
"testcafe-hammerhead": "24.6.0",
"testcafe-hammerhead": "24.7.2",
"testcafe-legacy-api": "5.1.4",
"testcafe-reporter-dashboard": "1.0.0-rc.3",
"testcafe-reporter-json": "^2.1.0",
Expand Down
47 changes: 47 additions & 0 deletions src/client/core/utils/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,53 @@ export function containsOffset (el: HTMLElement, offsetX?: number, offsetY?: num
(typeof offsetY === 'undefined' || offsetY >= 0 && maxY >= offsetY);
}

export function getEventAbsoluteCoordinates (ev: MouseEvent): AxisValues<number> {
const el = ev.target || ev.srcElement;
const pageCoordinates = getEventPageCoordinates(ev);
const curDocument = domUtils.findDocument(el);
let xOffset = 0;
let yOffset = 0;

if (domUtils.isElementInIframe(curDocument.documentElement)) {
const currentIframe = domUtils.getIframeByElement(curDocument);

if (currentIframe) {
const iframeOffset = getOffsetPosition(currentIframe);
const iframeBorders = styleUtils.getBordersWidth(currentIframe);

xOffset = iframeOffset.left + iframeBorders.left;
yOffset = iframeOffset.top + iframeBorders.top;
}
}

return new AxisValues(pageCoordinates.x + xOffset, pageCoordinates.y + yOffset);
}

export function getEventPageCoordinates (ev: MouseEvent): AxisValues<number> {
const curCoordObject = /^touch/.test(ev.type) && (ev as unknown as TouchEvent).targetTouches ? (ev as unknown as TouchEvent).targetTouches[0] || (ev as unknown as TouchEvent).changedTouches[0] : ev;

const bothPageCoordinatesAreZero = curCoordObject.pageX === 0 && curCoordObject.pageY === 0;
const notBothClientCoordinatesAreZero = curCoordObject.clientX !== 0 || curCoordObject.clientY !== 0;

if ((curCoordObject.pageX === null || bothPageCoordinatesAreZero && notBothClientCoordinatesAreZero) &&
curCoordObject.clientX !== null) {
const currentDocument = domUtils.findDocument(ev.target || ev.srcElement);
const html = currentDocument.documentElement;
const body = currentDocument.body;

return new AxisValues<number>(
Math.round(curCoordObject.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) -
(html.clientLeft || 0)),
Math.round(curCoordObject.clientY + (html && html.scrollTop || body && body.scrollTop || 0) -
(html.clientTop || 0))
);
}
return new AxisValues<number>(
Math.round(curCoordObject.pageX),
Math.round(curCoordObject.pageY)
);
}

export function getIframePointRelativeToParentFrame (pos: AxisValues<number>, iframeWin: Window): AxisValues<number> {
const iframe = domUtils.findIframeByWindow(iframeWin);
const iframeOffset = getOffsetPosition(iframe);
Expand Down
4 changes: 3 additions & 1 deletion test/client/fixtures/automation/click-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,9 +1161,11 @@ $(document).ready(function () {
.then(function () {
ok($area.data('clicked'), 'area element was clicked');
notOk($img.data('clicked'), 'img element was not clicked');

startNext();
});
}, TEST_RESULT_TIMEOUT);
// This test under Firefox MacOS takes a little more time.
}, TEST_RESULT_TIMEOUT + 200);
});

module('touch devices test');
Expand Down
2 changes: 1 addition & 1 deletion test/client/fixtures/core/page-unload-barrier-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $(document).ready(function () {
const iframeDocument = iframe.contentDocument;
const link = iframeDocument.createElement('a');

link.href = '/xhr-test/750';
link.href = '/xhr-test/650';
link.textContent = 'link';
iframeDocument.body.appendChild(link);

Expand Down
4 changes: 4 additions & 0 deletions test/functional/fixtures/api/es-next/request-hooks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ describe('Request Hooks', () => {
expect(testReport.errs[0]).contains('Error in the "respond" method');
});
});

it('Should not raise an error if response has 500 status code (GH-7213)', () => {
return runTests('./testcafe-fixtures/request-mock/500-status-code.js', null, { only: 'chrome' });
});
});

describe('RequestLogger', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { RequestMock } from 'testcafe';

fixture `Fixture`;

test
.requestHooks(
RequestMock()
.onRequestTo(/d/)
.respond('', 500)
)
('should pass', async t => {
await t.expect(true).ok();
});

0 comments on commit fc08728

Please sign in to comment.