Skip to content

Commit

Permalink
Fix test and add test verifying behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed May 15, 2024
1 parent 6086dea commit 748638c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -107,10 +103,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -157,10 +149,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -207,10 +195,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -257,10 +241,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -307,10 +287,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -357,10 +333,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -407,60 +379,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
</EuiPageSideBar>
</Route>
<Route
exact={true}
key="/tenantsConfigureTab"
path="/tenantsConfigureTab"
>
<EuiPageSideBar>
<NavPanel
items={
Array [
Object {
"href": "/getstarted",
"name": "Get Started",
},
Object {
"href": "/auth",
"name": "Authentication",
},
Object {
"href": "/roles",
"name": "Roles",
},
Object {
"href": "/users",
"name": "Internal users",
},
Object {
"href": "/serviceAccounts",
"name": "Service Accounts",
},
Object {
"href": "/permissions",
"name": "Permissions",
},
Object {
"href": "/tenants",
"name": "Tenants",
},
Object {
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -507,10 +425,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -557,10 +471,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
"href": "/auditLogging",
"name": "Audit logs",
},
Object {
"href": "/tenantsConfigureTab",
"name": "",
},
]
}
/>
Expand Down Expand Up @@ -620,10 +530,6 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
path="/tenants"
render={[Function]}
/>
<Route
path="/tenantsConfigureTab"
render={[Function]}
/>
<Route
path="/getstarted"
render={[Function]}
Expand Down
75 changes: 64 additions & 11 deletions public/apps/configuration/test/app-router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import { AppRouter } from '../app-router';
import { getDataSourceFromUrl } from '../../../utils/datasource-utils';
import { render } from '@testing-library/react';

jest.mock('../../../utils/datasource-utils', () => ({
getDataSourceFromUrl: jest.fn(),
Expand All @@ -33,23 +34,28 @@ describe('SecurityPluginTopNavMenu', () => {
},
};

const dataSourceMenuMock = jest.fn(() => <div>Mock DataSourceMenu</div>);
const securityPluginConfigMock = {
multitenancy: {
enabled: true,
},
ui: {},
};

const dataSourceManagementMock = {
ui: {
DataSourceMenu: dataSourceMenuMock,
const securityPluginConfigMockMultitenancyDisabled = {
multitenancy: {
enabled: false,
},
ui: {},
};

it('renders DataSourceMenu when dataSource is enabled', () => {
const securityPluginStartDepsMock = {
dataSource: {
dataSourceEnabled: true,
},
};

const wrapper = shallow(
<AppRouter coreStart={coreStartMock} depsStart={{}} params={{ appBasePath: '' }} />
<AppRouter
coreStart={coreStartMock}
depsStart={{}}
params={{ appBasePath: '' }}
config={securityPluginConfigMock}
/>
);

expect(wrapper).toMatchSnapshot();
Expand All @@ -67,6 +73,7 @@ describe('SecurityPluginTopNavMenu', () => {
coreStart={coreStartMock}
depsStart={securityPluginStartDepsMock}
params={{ appBasePath: '' }}
config={securityPluginConfigMock}
/>
);

Expand All @@ -85,9 +92,55 @@ describe('SecurityPluginTopNavMenu', () => {
coreStart={coreStartMock}
depsStart={securityPluginStartDepsMock}
params={{ appBasePath: '' }}
config={securityPluginConfigMock}
/>
);

expect(getDataSourceFromUrl).toHaveBeenCalled();
});

it('Tenant tab does not show up when ', () => {
const securityPluginStartDepsMock = {
dataSource: {
dataSourceEnabled: true,
},
};

shallow(
<AppRouter
coreStart={coreStartMock}
depsStart={securityPluginStartDepsMock}
params={{ appBasePath: '' }}
config={securityPluginConfigMock}
/>
);

expect(getDataSourceFromUrl).toHaveBeenCalled();
});

it('renders Tenant tab when multitenancy enabled', () => {
const { container } = render(
<AppRouter
coreStart={coreStartMock}
depsStart={{}}
params={{ appBasePath: '' }}
config={securityPluginConfigMock}
/>
);

expect(container.querySelector('[title="Tenants"]')).not.toBeNull();
});

it('does not render Tenant tab when multitenancy disabled', () => {
const { container } = render(
<AppRouter
coreStart={coreStartMock}
depsStart={{}}
params={{ appBasePath: '' }}
config={securityPluginConfigMockMultitenancyDisabled}
/>
);

expect(container.querySelector('[title="Tenants"]')).toBeNull();
});
});

0 comments on commit 748638c

Please sign in to comment.