Skip to content

Commit

Permalink
[APM] Fix inventory plugin link (elastic#201122)
Browse files Browse the repository at this point in the history
closes elastic#201116

- Fix Inventory locator removing `observability` from the url.
- ~~Unify service inventory E2E tests to run it faster avoiding Kibana
loading page on every test.~~
- Add test to navigate to the inventory plugin.
  • Loading branch information
cauemarcondes authored Nov 26, 2024
1 parent 1e488c8 commit 4bc9a59
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
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));
},
}),
[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: `/`,
state: {},
};
};
Expand Down

0 comments on commit 4bc9a59

Please sign in to comment.