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

[7.16] Make fixture app wait until network is idle before running authentication tests. (#119715) #119909

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,34 @@
import type { CoreSetup, Plugin } from 'src/core/public';
import ReactDOM from 'react-dom';
import React from 'react';
import { debounce, filter, first } from 'rxjs/operators';
import { timer } from 'rxjs';

export class TestEndpointsPlugin implements Plugin {
public setup(core: CoreSetup) {
// Prevent auto-logout on server `401` errors.
core.http.anonymousPaths.register('/authentication/app');

const networkIdle$ = core.http.getLoadingCount$().pipe(
debounce(() => timer(3000)),
filter((count) => count === 0),
first()
);

core.application.register({
id: 'authentication_app',
title: 'Authentication app',
appRoute: '/authentication/app',
chromeless: true,
async mount({ element }) {
ReactDOM.render(
<div data-test-subj="testEndpointsAuthenticationApp">Authenticated!</div>,
element
);
// Promise is resolved as soon there are no requests has been made in the last 3 seconds. We need this to make
// sure none of the unrelated requests interferes with the test logic.
networkIdle$.toPromise().then(() => {
ReactDOM.render(
<div data-test-subj="testEndpointsAuthenticationApp">Authenticated!</div>,
element
);
});
return () => ReactDOM.unmountComponentAtNode(element);
},
});
Expand Down