Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate the status bar reactively (closes #7384) #7407

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/client/ui/status-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default class StatusBar extends serviceUtils.EventEmitter {
this.showingTimeout = null;

this.windowHeight = document.documentElement ? styleUtils.getHeight(window) : window.innerHeight;
this.maxHeight = 0;

this.state = {
created: false,
Expand All @@ -102,6 +103,12 @@ export default class StatusBar extends serviceUtils.EventEmitter {
this._initChildListening();
}

get visibleHeight () {
this.maxHeight = Math.max(this.maxHeight, styleUtils.getHeight(this.statusBar));

return this.maxHeight;
}

_createButton (text, className) {
const button = document.createElement('div');
const icon = document.createElement('div');
Expand Down Expand Up @@ -300,13 +307,11 @@ export default class StatusBar extends serviceUtils.EventEmitter {
this.windowHeight = window.innerHeight;
});

const statusBarHeight = styleUtils.getHeight(this.statusBar);

listeners.addFirstInternalEventBeforeListener(window, ['mousemove', 'mouseout', 'touchmove'], e => {
if (e.type === 'mouseout' && !e.relatedTarget)
this._fadeIn(e);
else if (e.type === 'mousemove' || e.type === 'touchmove') {
if (e.clientY > this.windowHeight - statusBarHeight)
if (e.clientY > this.windowHeight - this.visibleHeight)
this._fadeOut(e);
else if (this.state.hidden)
this._fadeIn(e);
Expand Down
12 changes: 12 additions & 0 deletions test/functional/fixtures/ui/pages/hiding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head></head>
<body style="display: none;">
Test
<script>
setTimeout(() => {
document.body.style.display = 'initial';
}, 500);
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions test/functional/fixtures/ui/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const config = require('../../config');


describe('TestCafe UI', () => {
it('Should display correct status', () => {
return runTests('./testcafe-fixtures/status-bar-test.js', 'Show status prefix', { assertionTimeout: 3000 });
Expand All @@ -6,4 +9,12 @@ describe('TestCafe UI', () => {
it('Hide elements when resizing the window', () => {
return runTests('./testcafe-fixtures/status-bar-test.js', 'Hide elements when resizing the window', { skip: ['android', 'ipad', 'iphone', 'edge', 'safari'] });
});

it('Should hide the status bar even if document was hidden during initialization (GH-7384)', function () {
// NOTE: the test needs direct access to the CDP client through the test controller
if (config.experimentalDebug)
this.skip();

return runTests('./testcafe-fixtures/status-bar-test.js', 'Hide status bar after mouse move', { only: ['chrome'] });
});
});
41 changes: 41 additions & 0 deletions test/functional/fixtures/ui/testcafe-fixtures/status-bar-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Selector, ClientFunction } from 'testcafe';
import assert from 'assert';
import OS from 'os-family';
import { saveWindowState, restoreWindowState } from '../../../window-helpers';

Expand Down Expand Up @@ -115,3 +116,43 @@ test('Hide elements when resizing the window', async t => {
.expect(itemsVisibility.iconVisible).notOk()
.expect(statusBarDiv.clientHeight).eql(82);
});

const TOTAL_DELAY = 5000;
const START_DELAY = 1000;
const AFTER_DELAY = 2000;

const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

async function evaluateOnRemote (client, func) {
const { result } = await client.Runtime.evaluate({ expression: `(${func.toString()})()`, returnByValue: true });

return result.value;
}

async function simulateMoveAndCheckStatusBar (t) {
await delay(START_DELAY);

const browserConnection = t.testRun.browserConnection;
const providerPlugin = browserConnection.provider.plugin;
const browserClient = providerPlugin._getBrowserProtocolClient(providerPlugin.openedBrowsers[browserConnection.id]);
const remoteInterface = await browserClient.getActiveClient();

const windowSize = await evaluateOnRemote(remoteInterface, () => ({ width: innerWidth, height: innerHeight }));

await remoteInterface.Input.dispatchMouseEvent({ type: 'mouseMoved', x: windowSize.width / 2, y: windowSize.height - 1 });

await delay(AFTER_DELAY);

const statusBarState = await evaluateOnRemote(remoteInterface, () => window['%testCafeDriverInstance%'].statusBar.state);

assert.ok(statusBarState.hidden);
}

test
.page('../pages/hiding.html')
('Hide status bar after mouse move', async t => {
await Promise.all([
t.wait(TOTAL_DELAY),
simulateMoveAndCheckStatusBar(t),
]);
});