Skip to content

Commit 8a82faf

Browse files
author
Kishore Kumaar Natarajan
committed
adding local datasource logic
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
1 parent 1fa9528 commit 8a82faf

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

cypress/e2e/5_live_queries.cy.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,23 @@ describe('Inflight Queries Dashboard', () => {
351351

352352
describe('Inflight Queries Dashboard - WLM Enabled', () => {
353353
beforeEach(() => {
354-
cy.fixture('stub_live_queries.json').then((stubResponse) => {
355-
cy.intercept('GET', '**/api/live_queries', {
354+
// Stub ONLY the initial NO-QUERY snapshot: /api/live_queries (no '?')
355+
cy.fixture('stub_live_queries.json').then((stubLive) => {
356+
cy.intercept('GET', /\/api\/live_queries$/, {
356357
statusCode: 200,
357-
body: stubResponse,
358-
}).as('getLiveQueries');
358+
body: stubLive,
359+
}).as('liveQueriesNoGroup');
359360
});
360361

361-
cy.fixture('stub_wlm_stats.json').then((wlmStatsResponse) => {
362+
// WLM stats
363+
cy.fixture('stub_wlm_stats.json').then((wlmStats) => {
362364
cy.intercept('GET', '**/api/_wlm/stats', {
363365
statusCode: 200,
364-
body: wlmStatsResponse,
366+
body: wlmStats,
365367
}).as('getWlmStats');
366368
});
367369

370+
// WLM enabled + workload groups
368371
cy.intercept('GET', '**/api/cat_plugins', {
369372
statusCode: 200,
370373
body: { hasWlm: true },
@@ -375,17 +378,14 @@ describe('Inflight Queries Dashboard - WLM Enabled', () => {
375378
body: {
376379
workload_groups: [
377380
{ _id: 'ANALYTICS_WORKLOAD_GROUP', name: 'ANALYTICS_WORKLOAD_GROUP' },
378-
{ _id: 'DEFAULT_QUERY_GROUP', name: 'DEFAULT_QUERY_GROUP' },
381+
{ _id: 'DEFAULT_WORKLOAD_GROUP', name: 'DEFAULT_WORKLOAD_GROUP' },
379382
],
380383
},
381384
}).as('getWorkloadGroups');
382-
cy.intercept('GET', '**/api/cat_plugins', {
383-
statusCode: 200,
384-
body: { hasWlm: true },
385-
}).as('getPluginsEnabled');
386385

386+
// Navigate AFTER all intercepts are ready, then wait initial snapshot
387387
cy.navigateToLiveQueries();
388-
cy.wait('@getLiveQueries');
388+
cy.wait('@liveQueriesNoGroup');
389389
});
390390

391391
it('displays WLM group links when WLM is enabled', () => {
@@ -395,34 +395,46 @@ describe('Inflight Queries Dashboard - WLM Enabled', () => {
395395
cy.get('tbody tr')
396396
.first()
397397
.within(() => {
398-
cy.get('td').contains('ANALYTICS_WORKLOAD_GROUP').click({ force: true });
398+
cy.contains('td', 'ANALYTICS_WORKLOAD_GROUP').click({ force: true });
399399
});
400400
});
401401

402402
it('calls different API when WLM group selection changes', () => {
403-
// Intercept all live_queries calls
404-
cy.intercept('GET', '**/api/live_queries*').as('liveQueries');
403+
// Robust spies that tolerate extra query params & any order
404+
cy.intercept('GET', /\/api\/live_queries\?(?=.*\bwlmGroupId=ANALYTICS_WORKLOAD_GROUP\b).*/).as(
405+
'liveQueriesAnalytics'
406+
);
405407

406-
// 1) Select ANALYTICS first
407-
cy.get('#wlm-group-select').should('exist').select('ANALYTICS_WORKLOAD_GROUP');
408+
cy.intercept('GET', /\/api\/live_queries\?(?=.*\bwlmGroupId=DEFAULT_WORKLOAD_GROUP\b).*/).as(
409+
'liveQueriesDefault'
410+
);
408411

409-
cy.wait('@liveQueries')
412+
cy.get('#wlm-group-select').should('exist');
413+
414+
// 1) Select ANALYTICS
415+
cy.get('#wlm-group-select').select('ANALYTICS_WORKLOAD_GROUP');
416+
cy.wait('@liveQueriesAnalytics')
410417
.its('request.url')
411-
.should('include', 'wlmGroupId=ANALYTICS_WORKLOAD_GROUP');
418+
.should((urlStr) => {
419+
const url = new URL(urlStr);
420+
expect(url.searchParams.get('wlmGroupId')).to.eq('ANALYTICS_WORKLOAD_GROUP');
421+
});
412422

413-
// Component re-fetches workload groups after selection — wait for that
423+
// Component re-fetches groups after selection
414424
cy.wait('@getWorkloadGroups');
415425

416-
// 2) Select DEFAULT_WORKLOAD_GROUP explicitly
426+
// 2) Select DEFAULT
417427
cy.get('#wlm-group-select').select('DEFAULT_WORKLOAD_GROUP');
418428

419-
cy.wait('@liveQueries')
429+
cy.wait('@liveQueriesDefault')
420430
.its('request.url')
421-
.should('include', 'wlmGroupId=DEFAULT_WORKLOAD_GROUP');
431+
.should((urlStr) => {
432+
const url = new URL(urlStr);
433+
expect(url.searchParams.get('wlmGroupId')).to.eq('DEFAULT_WORKLOAD_GROUP');
434+
});
422435
});
423436

424437
it('displays total completion, cancellation, and rejection metrics correctly', () => {
425-
// Trigger a refresh to ensure WLM stats are loaded
426438
cy.get('[data-test-subj="live-queries-refresh-button"]').click();
427439
cy.wait('@getWlmStats');
428440

public/pages/InflightQueries/InflightQueries.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,19 @@ export const InflightQueries = ({
141141
const checkWlmSupport = async () => {
142142
try {
143143
const version = await getVersionOnce(dataSource?.id || '');
144-
if (isVersion33OrHigher(version)) {
144+
const versionSupported = isVersion33OrHigher(version);
145+
setWlmGroupsSupported(versionSupported);
146+
147+
if (versionSupported) {
145148
const hasWlm = await detectWlm();
146149
setWlmAvailable(hasWlm);
147-
setWlmGroupsSupported(true);
150+
} else {
151+
setWlmAvailable(false);
148152
}
149153
} catch (e) {
150154
console.warn('Failed to check version for WLM groups support', e);
155+
setWlmGroupsSupported(false);
156+
setWlmAvailable(false);
151157
}
152158
};
153159

@@ -161,7 +167,7 @@ export const InflightQueries = ({
161167
}>({ total_completions: 0, total_cancellations: 0, total_rejections: 0 });
162168

163169
const fetchActiveWlmGroups = useCallback(async () => {
164-
if (!wlmAvailable || !wlmGroupsSupported) {
170+
if (!wlmGroupsSupported) {
165171
setWorkloadGroupStats({ total_completions: 0, total_cancellations: 0, total_rejections: 0 });
166172
setWlmGroupOptions([]);
167173
return {};

0 commit comments

Comments
 (0)