Skip to content

Commit

Permalink
Add fix for data source disabled plugin should work (#1916)
Browse files Browse the repository at this point in the history
* Add fix for data source disabled plugin should work

Signed-off-by: Derek Ho <[email protected]>

* Remove unused function

Signed-off-by: Derek Ho <[email protected]>

* Update snapshot

Signed-off-by: Derek Ho <[email protected]>

* Update the name of the disabled test

Signed-off-by: Derek Ho <[email protected]>

* Udpate codecov to v4

Signed-off-by: Derek Ho <[email protected]>

* Update the check and the tests

Signed-off-by: Derek Ho <[email protected]>

* Add test to ensure it is not called when MDS is disabled

Signed-off-by: Derek Ho <[email protected]>

---------

Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho authored Apr 30, 2024
1 parent 67397ec commit 1a261d9
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
working-directory: ${{ steps.install-dashboards.outputs.plugin-directory }}

- name: Uploads coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ export const LocalCluster = { label: 'Local cluster', id: '' };
export const DataSourceContext = createContext<DataSourceContextType | null>(null);

export function AppRouter(props: AppDependencies) {
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const setGlobalBreadcrumbs = flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs);
const dataSourceFromUrl = getDataSourceFromUrl();
const dataSourceFromUrl = dataSourceEnabled ? getDataSourceFromUrl() : LocalCluster;

const [dataSource, setDataSource] = useState<DataSourceOption>(dataSourceFromUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
<ContextProvider
value={
Object {
"dataSource": Object {},
"dataSource": Object {
"id": "",
"label": "Local cluster",
},
"setDataSource": [Function],
}
}
Expand Down
45 changes: 44 additions & 1 deletion public/apps/configuration/test/app-router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import { AppRouter } from '../app-router';
import { getDataSourceFromUrl } from '../../../utils/datasource-utils';

jest.mock('../../../utils/datasource-utils', () => ({
getDataSourceFromUrl: jest.fn(),
}));

describe('SecurityPluginTopNavMenu', () => {
const coreStartMock = {
Expand Down Expand Up @@ -43,8 +48,46 @@ describe('SecurityPluginTopNavMenu', () => {
},
};

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

expect(wrapper).toMatchSnapshot();
});

it('getDataSourceFromUrl not called when MDS is disabled', () => {
const securityPluginStartDepsMock = {
dataSource: {
dataSourceEnabled: false,
},
};

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

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

it('getDataSourceFromUrl called when MDS is enabled', () => {
const securityPluginStartDepsMock = {
dataSource: {
dataSourceEnabled: true,
},
};

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

expect(getDataSourceFromUrl).toHaveBeenCalled();
});
});
4 changes: 0 additions & 4 deletions public/utils/datasource-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

import { DataSourceOption } from 'src/plugins/data_source_management/public/components/data_source_menu/types';

export function createDataSourceQuery(dataSourceId: string) {
return { dataSourceId };
}

const DATASOURCEURLKEY = 'dataSource';

export function getClusterInfo(dataSourceEnabled: boolean, cluster: DataSourceOption) {
Expand Down
11 changes: 1 addition & 10 deletions public/utils/test/datasource-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
* permissions and limitations under the License.
*/

import {
createDataSourceQuery,
getClusterInfo,
getDataSourceFromUrl,
setDataSourceInUrl,
} from '../datasource-utils';
import { getClusterInfo, getDataSourceFromUrl, setDataSourceInUrl } from '../datasource-utils';

describe('Tests datasource utils', () => {
it('Tests the GetClusterDescription helper function', () => {
Expand All @@ -27,10 +22,6 @@ describe('Tests datasource utils', () => {
expect(getClusterInfo(true, { id: 'test', label: 'test' })).toBe('for test');
});

it('Tests the create DataSource query helper function', () => {
expect(createDataSourceQuery('test')).toStrictEqual({ dataSourceId: 'test' });
});

it('Tests getting the datasource from the url', () => {
const mockSearchNoDataSourceId = '?foo=bar&baz=qux';
Object.defineProperty(window, 'location', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,28 @@
* permissions and limitations under the License.
*/

describe('Multi-datasources enabled', () => {
it('Sanity checks the cluster selector is not visible when multi datasources is disabled', () => {
describe('Multi-datasources disabled', () => {
beforeEach(() => {
localStorage.setItem('opendistro::security::tenant::saved', '""');
localStorage.setItem('home:newThemeModal:show', 'false');
});

afterEach(() => {
cy.clearCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
});

it('Checks Get Started Tab', () => {
// Remote cluster purge cache
cy.visit(`http://localhost:5601/app/security-dashboards-plugin#/getstarted`);

cy.visit('http://localhost:5601/app/security-dashboards-plugin#/getstarted', {
failOnStatusCode: false,
});
cy.contains('h1', 'Get started');
cy.get('[data-test-subj="dataSourceSelectableButton"]').should('not.exist');

cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').should('not.exist');
cy.get('[data-test-subj="purge-cache"]').click();
cy.get('[class="euiToast euiToast--success euiGlobalToastListItem"]')
.get('.euiToastHeader__title')
.should('contain', 'Cache purge successful');
});
});

0 comments on commit 1a261d9

Please sign in to comment.