Scopes: Don't use redirect if you're on an active scope navigation (#115149)
* Don't use redirectUrl if we are on an active scope navigation * Remove superflous test
This commit is contained in:
@@ -156,13 +156,18 @@ export async function applyScopes(page: Page, scopes?: TestScope[]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url: string =
|
||||
const dashboardBindingsUrl: string =
|
||||
'**/apis/scope.grafana.app/v0alpha1/namespaces/*/find/scope_dashboard_bindings?' +
|
||||
scopes.map((scope) => `scope=scope-${scope.name}`).join('&');
|
||||
|
||||
const scopeNavigationsUrl: string =
|
||||
'**/apis/scope.grafana.app/v0alpha1/namespaces/*/find/scope_navigations?' +
|
||||
scopes.map((scope) => `scope=scope-${scope.name}`).join('&');
|
||||
|
||||
const groups: string[] = ['Most relevant', 'Dashboards', 'Something else', ''];
|
||||
|
||||
await page.route(url, async (route) => {
|
||||
// Mock scope_dashboard_bindings endpoint
|
||||
await page.route(dashboardBindingsUrl, async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
@@ -215,7 +220,52 @@ export async function applyScopes(page: Page, scopes?: TestScope[]) {
|
||||
});
|
||||
});
|
||||
|
||||
const responsePromise = page.waitForResponse((response) => response.url().includes(`/find/scope_dashboard_bindings`));
|
||||
// Mock scope_navigations endpoint
|
||||
await page.route(scopeNavigationsUrl, async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
apiVersion: 'scope.grafana.app/v0alpha1',
|
||||
items: scopes.flatMap((scope) => {
|
||||
const navigations: Array<{
|
||||
kind: string;
|
||||
apiVersion: string;
|
||||
metadata: { name: string; resourceVersion: string; creationTimestamp: string };
|
||||
spec: { url: string; scope: string };
|
||||
status: { title: string };
|
||||
}> = [];
|
||||
|
||||
// Create a scope navigation if dashboardUid is provided
|
||||
if (scope.dashboardUid && scope.addLinks) {
|
||||
navigations.push({
|
||||
kind: 'ScopeNavigation',
|
||||
apiVersion: 'scope.grafana.app/v0alpha1',
|
||||
metadata: {
|
||||
name: `scope-${scope.name}-nav`,
|
||||
resourceVersion: '1',
|
||||
creationTimestamp: 'stamp',
|
||||
},
|
||||
spec: {
|
||||
url: `/d/${scope.dashboardUid}`,
|
||||
scope: `scope-${scope.name}`,
|
||||
},
|
||||
status: {
|
||||
title: scope.dashboardTitle ?? scope.title,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return navigations;
|
||||
}),
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
const responsePromise = page.waitForResponse(
|
||||
(response) =>
|
||||
response.url().includes(`/find/scope_dashboard_bindings`) || response.url().includes(`/find/scope_navigations`)
|
||||
);
|
||||
const scopeRequestPromises: Array<Promise<Response>> = [];
|
||||
|
||||
for (const scope of scopes) {
|
||||
|
||||
@@ -124,5 +124,23 @@ export const testScopesWithRedirect = (): TestScope[] => {
|
||||
dashboardTitle: 'CUJ Dashboard 2',
|
||||
addLinks: true,
|
||||
},
|
||||
{
|
||||
name: 'sn-redirect-setup',
|
||||
title: 'Setup Navigation',
|
||||
// No redirectPath - used to set up scope navigation to dashboard-1
|
||||
filters: [{ key: 'namespace', operator: 'equals', value: 'setup-nav' }],
|
||||
dashboardUid: 'cuj-dashboard-1', // Creates scope navigation to this dashboard
|
||||
dashboardTitle: 'CUJ Dashboard 1',
|
||||
addLinks: true,
|
||||
},
|
||||
{
|
||||
name: 'sn-redirect-with-navigation',
|
||||
title: 'Redirect With Navigation',
|
||||
redirectPath: '/d/cuj-dashboard-3', // Redirect target
|
||||
filters: [{ key: 'namespace', operator: 'equals', value: 'redirect-with-nav' }],
|
||||
dashboardUid: 'cuj-dashboard-1', // Creates scope navigation to this dashboard
|
||||
dashboardTitle: 'CUJ Dashboard 1',
|
||||
addLinks: true,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user