Merge pull request #29739 from backstage/renderintestapp-act-warnings
Fix: renderInTestApp act warnings
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-app-api': patch
|
||||
---
|
||||
|
||||
Fixed an issue causing `OAuthRequestDialog` to re-render on mount.
|
||||
@@ -17,11 +17,19 @@
|
||||
import {
|
||||
OAuthRequestApi,
|
||||
OAuthRequesterOptions,
|
||||
PendingOAuthRequest,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { OAuthRequestManager } from './OAuthRequestManager';
|
||||
|
||||
export default class MockOAuthApi implements OAuthRequestApi {
|
||||
private readonly real = new OAuthRequestManager();
|
||||
private requests: PendingOAuthRequest[] = [];
|
||||
|
||||
constructor() {
|
||||
this.authRequest$().subscribe(requests => {
|
||||
this.requests = requests;
|
||||
});
|
||||
}
|
||||
|
||||
createAuthRequester<T>(options: OAuthRequesterOptions<T>) {
|
||||
return this.real.createAuthRequester(options);
|
||||
@@ -34,25 +42,12 @@ export default class MockOAuthApi implements OAuthRequestApi {
|
||||
async triggerAll() {
|
||||
await Promise.resolve(); // Wait a tick to allow new requests to get forwarded
|
||||
|
||||
return new Promise<void>(resolve => {
|
||||
const subscription = this.authRequest$().subscribe(requests => {
|
||||
subscription.unsubscribe();
|
||||
Promise.all(requests.map(request => request.trigger())).then(() =>
|
||||
resolve(),
|
||||
);
|
||||
});
|
||||
});
|
||||
return Promise.all(this.requests.map(request => request.trigger()));
|
||||
}
|
||||
|
||||
async rejectAll() {
|
||||
await Promise.resolve(); // Wait a tick to allow new requests to get forwarded
|
||||
|
||||
return new Promise<void>(resolve => {
|
||||
const subscription = this.authRequest$().subscribe(requests => {
|
||||
subscription.unsubscribe();
|
||||
requests.map(request => request.reject());
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
this.requests.forEach(request => request.reject());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,12 +34,12 @@ describe('OAuthRequestManager', () => {
|
||||
|
||||
expect(reqSpy).toHaveBeenCalledTimes(0);
|
||||
await 'a tick';
|
||||
expect(reqSpy).toHaveBeenCalledTimes(2);
|
||||
expect(reqSpy).toHaveBeenCalledTimes(1);
|
||||
expect(reqSpy).toHaveBeenLastCalledWith([]);
|
||||
|
||||
const req = requester(new Set(['my-scope']));
|
||||
|
||||
expect(reqSpy).toHaveBeenCalledTimes(3);
|
||||
expect(reqSpy).toHaveBeenCalledTimes(2);
|
||||
expect(reqSpy).toHaveBeenLastCalledWith([
|
||||
expect.objectContaining({
|
||||
reject: expect.any(Function),
|
||||
@@ -51,7 +51,7 @@ describe('OAuthRequestManager', () => {
|
||||
'not yet',
|
||||
);
|
||||
|
||||
const [request] = reqSpy.mock.calls[2][0];
|
||||
const [request] = reqSpy.mock.calls[1][0];
|
||||
request.trigger();
|
||||
|
||||
await expect(req).resolves.toBe('hello');
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import {
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { Observable } from '@backstage/types';
|
||||
import { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests';
|
||||
import { BehaviorSubject } from '../../../lib/subjects';
|
||||
import { PublishSubject } from '../../../lib/subjects';
|
||||
|
||||
/**
|
||||
* The OAuthRequestManager is an implementation of the OAuthRequestApi.
|
||||
@@ -34,7 +34,7 @@ import { BehaviorSubject } from '../../../lib/subjects';
|
||||
* @public
|
||||
*/
|
||||
export class OAuthRequestManager implements OAuthRequestApi {
|
||||
private readonly subject = new BehaviorSubject<PendingOAuthRequest[]>([]);
|
||||
private readonly subject = new PublishSubject<PendingOAuthRequest[]>();
|
||||
private currentRequests: PendingOAuthRequest[] = [];
|
||||
private handlerCount = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user