Skip to content

Commit 46cb114

Browse files
kibanamachinenreeseelasticmachine
authored
[8.19] fix Failing test: Jest Tests.src/platform/plugins/shared/dashboard/public/dashboard_api - initializeUnifiedSearchManager startComparing$ timeRange Should not return timeRanage change when timeRestore resets to false (elastic#240715) (elastic#240895)
# Backport This will backport the following commits from `main` to `8.19`: - [fix Failing test: Jest Tests.src/platform/plugins/shared/dashboard/public/dashboard_api - initializeUnifiedSearchManager startComparing$ timeRange Should not return timeRanage change when timeRestore resets to false (elastic#240715)](elastic#240715) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Nathan Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-27T20:28:11Z","message":"fix Failing test: Jest Tests.src/platform/plugins/shared/dashboard/public/dashboard_api - initializeUnifiedSearchManager startComparing$ timeRange Should not return timeRanage change when timeRestore resets to false (elastic#240715)\n\nFixes https://github.com/elastic/kibana/issues/240273\n\nPR removes timing issues by removing awaits and moves all expect logic\ninto subscription.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"2076cc6c32282a2ee72b1e05f09badedfc2fddb5","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","release_note:skip","backport:version","v9.1.0","v8.19.0","v9.2.0","v9.3.0"],"title":"fix Failing test: Jest Tests.src/platform/plugins/shared/dashboard/public/dashboard_api - initializeUnifiedSearchManager startComparing$ timeRange Should not return timeRanage change when timeRestore resets to false","number":240715,"url":"https://github.com/elastic/kibana/pull/240715","mergeCommit":{"message":"fix Failing test: Jest Tests.src/platform/plugins/shared/dashboard/public/dashboard_api - initializeUnifiedSearchManager startComparing$ timeRange Should not return timeRanage change when timeRestore resets to false (elastic#240715)\n\nFixes https://github.com/elastic/kibana/issues/240273\n\nPR removes timing issues by removing awaits and moves all expect logic\ninto subscription.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"2076cc6c32282a2ee72b1e05f09badedfc2fddb5"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.2"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240715","number":240715,"mergeCommit":{"message":"fix Failing test: Jest Tests.src/platform/plugins/shared/dashboard/public/dashboard_api - initializeUnifiedSearchManager startComparing$ timeRange Should not return timeRanage change when timeRestore resets to false (elastic#240715)\n\nFixes https://github.com/elastic/kibana/issues/240273\n\nPR removes timing issues by removing awaits and moves all expect logic\ninto subscription.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"2076cc6c32282a2ee72b1e05f09badedfc2fddb5"}}]}] BACKPORT--> Co-authored-by: Nathan Reese <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 587efdd commit 46cb114

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/platform/plugins/shared/dashboard/public/dashboard_api/unified_search_manager.test.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { BehaviorSubject, Subject } from 'rxjs';
10+
import { BehaviorSubject, Subject, take } from 'rxjs';
1111
import { getSampleDashboardState } from '../mocks';
1212
import type { DashboardState } from '../../common';
13-
import { COMPARE_DEBOUNCE, initializeUnifiedSearchManager } from './unified_search_manager';
13+
import { initializeUnifiedSearchManager } from './unified_search_manager';
1414
import type { ControlGroupApi } from '@kbn/controls-plugin/public';
1515

1616
describe('initializeUnifiedSearchManager', () => {
@@ -90,7 +90,7 @@ describe('initializeUnifiedSearchManager', () => {
9090
});
9191
});
9292

93-
test('Should not return timeRanage change when timeRestore resets to false', async () => {
93+
test('Should not return timeRanage change when timeRestore resets to false', (done) => {
9494
const lastSavedState$ = new BehaviorSubject<DashboardState>(getSampleDashboardState());
9595
const timeRestore$ = new BehaviorSubject<boolean | undefined>(false);
9696
const unifiedSearchManager = initializeUnifiedSearchManager(
@@ -103,34 +103,37 @@ describe('initializeUnifiedSearchManager', () => {
103103
useUnifiedSearchIntegration: false,
104104
}
105105
);
106-
let unsavedChanges: object | undefined;
107-
unifiedSearchManager.internalApi.startComparing$(lastSavedState$).subscribe((changes) => {
108-
unsavedChanges = changes;
109-
});
106+
let emitCount = 0;
107+
unifiedSearchManager.internalApi
108+
.startComparing$(lastSavedState$)
109+
.pipe(take(2))
110+
.subscribe((changes) => {
111+
emitCount++;
112+
113+
if (emitCount === 1) {
114+
expect(changes).toMatchInlineSnapshot(`
115+
Object {
116+
"timeRange": Object {
117+
"from": "now-30m",
118+
"to": "now",
119+
},
120+
}
121+
`);
122+
// reset timeRestore to false
123+
timeRestore$.next(false);
124+
}
125+
126+
if (emitCount === 2) {
127+
expect(changes).toMatchInlineSnapshot(`Object {}`);
128+
done();
129+
}
130+
});
110131

111132
timeRestore$.next(true);
112133
unifiedSearchManager.api.setTimeRange({
113134
to: 'now',
114135
from: 'now-30m',
115136
});
116-
117-
await new Promise((resolve) => setTimeout(resolve, COMPARE_DEBOUNCE + 1));
118-
119-
expect(unsavedChanges).toMatchInlineSnapshot(`
120-
Object {
121-
"timeRange": Object {
122-
"from": "now-30m",
123-
"to": "now",
124-
},
125-
}
126-
`);
127-
128-
// reset timeRestore to false
129-
timeRestore$.next(false);
130-
131-
await new Promise((resolve) => setTimeout(resolve, COMPARE_DEBOUNCE + 1));
132-
133-
expect(unsavedChanges).toMatchInlineSnapshot(`Object {}`);
134137
});
135138
});
136139
});

0 commit comments

Comments
 (0)