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

[APM] Fix inventory plugin link #201122

Merged
merged 15 commits into from
Nov 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ const serviceInventoryHref = url.format({

const mainApiRequestsToIntercept = [
{
method: 'GET',
endpoint: '/internal/apm/services?*',
aliasName: 'servicesRequest',
},
{
method: 'POST',
endpoint: '/internal/apm/services/detailed_statistics?*',
aliasName: 'detailedStatisticsRequest',
},
Expand All @@ -50,8 +52,13 @@ describe('Service inventory', () => {

describe('When navigating to the service inventory', () => {
beforeEach(() => {
mainApiRequestsToIntercept.forEach(({ aliasName, endpoint, method }) =>
cy.intercept(method, endpoint).as(aliasName)
);
cy.loginAsViewerUser();
cy.visitKibana(serviceInventoryHref);
cy.visitKibana(serviceInventoryHref, {
localStorageOptions: [['apm.dismissedEntitiesInventoryCallout', 'false']],
});
});

it('has no detectable a11y violations on load', () => {
Expand Down Expand Up @@ -79,9 +86,8 @@ describe('Service inventory', () => {

describe('Calls APIs', () => {
beforeEach(() => {
cy.intercept('GET', '/internal/apm/services?*').as('servicesRequest');
cy.intercept('POST', '/internal/apm/services/detailed_statistics?*').as(
'detailedStatisticsRequest'
mainApiRequestsToIntercept.forEach(({ aliasName, endpoint, method }) =>
cy.intercept(method, endpoint).as(aliasName)
);

cy.loginAsViewerUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,32 @@ Cypress.Commands.add('loginAsApmReadPrivilegesWithWriteSettingsUser', () => {
Cypress.Commands.add(
'loginAs',
({ username, password }: { username: string; password: string }) => {
// cy.session(username, () => {
const kibanaUrl = Cypress.env('KIBANA_URL');
cy.log(`Logging in as ${username} on ${kibanaUrl}`);
cy.visit('/');
cy.request({
log: true,
method: 'POST',
url: `${kibanaUrl}/internal/security/login`,
body: {
providerType: 'basic',
providerName: 'basic',
currentURL: `${kibanaUrl}/login`,
params: { username, password },
},
headers: {
'kbn-xsrf': 'e2e_test',
cy.session(
username,
() => {
const kibanaUrl = Cypress.env('KIBANA_URL');
cy.log(`Logging in as ${username} on ${kibanaUrl}`);
cy.visit('/');
cy.request({
log: true,
method: 'POST',
url: `${kibanaUrl}/internal/security/login`,
body: {
providerType: 'basic',
providerName: 'basic',
currentURL: `${kibanaUrl}/login`,
params: { username, password },
},
headers: {
'kbn-xsrf': 'e2e_test',
},
});
cy.visit('/');
},
// });
});
cy.visit('/');
{
cacheAcrossSpecs: true,
}
);
}
);

Expand All @@ -87,8 +93,14 @@ Cypress.Commands.add('changeTimeRange', (value: string) => {
cy.contains(value).click();
});

Cypress.Commands.add('visitKibana', (url: string) => {
cy.visit(url);
Cypress.Commands.add('visitKibana', (url, options) => {
cy.visit(url, {
onBeforeLoad(win) {
if (options?.localStorageOptions && options.localStorageOptions.length > 0) {
options.localStorageOptions.forEach(([key, value]) => win.localStorage.setItem(key, value));
}
},
});
cy.getByTestSubj('kbnLoadingMessage').should('exist');
cy.getByTestSubj('kbnLoadingMessage').should('not.exist', {
timeout: 50000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare namespace Cypress {
password: string;
}): Cypress.Chainable<Cypress.Response<any>>;
changeTimeRange(value: string): void;
visitKibana(url: string): void;
visitKibana(url: string, options?: { localStorageOptions?: Array<[string, string]> }): void;
selectAbsoluteTimeRange(start: string, end: string): void;
expectAPIsToHaveBeenCalledWith(params: { apisIntercepted: string[]; value: string }): void;
updateAdvancedSettings(settings: Record<string, unknown>): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function useInventoryRouter(): StatefulInventoryRouter {
navigateToApp('inventory', { path: next, replace: true });
},
link: (path, ...args) => {
return http.basePath.prepend('/app/observability/inventory' + link(path, ...args));
return http.basePath.prepend('/app/inventory' + link(path, ...args));
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
},
}),
[navigateToApp, http.basePath]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class EntitiesInventoryLocatorDefinition implements LocatorDefinition<Ser

public readonly getLocation = async () => {
return {
app: 'observability',
path: `/inventory`,
app: 'inventory',
path: `/`,
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
state: {},
};
};
Expand Down