Skip to content

Commit

Permalink
Fix some state issues and try to use electron browser
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Apr 16, 2024
1 parent 5f0f592 commit 8f5ef2d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ jobs:
uses: ./.github/actions/run-cypress-tests
with:
dashboards_config_file: opensearch_dashboards_multidatasources.yml
yarn_command: 'yarn cypress:run --browser chrome --headless --env LOGIN_AS_ADMIN=true --spec "test/cypress/e2e/multi-datasources/multi_datasources_enabled.spec.js"'
yarn_command: 'yarn cypress:run --browser electron --headless --env LOGIN_AS_ADMIN=true --spec "test/cypress/e2e/multi-datasources/multi_datasources_enabled.spec.js"'
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
EuiSuperSelect,
EuiTextArea,
} from '@elastic/eui';
import React, { Dispatch, Fragment, SetStateAction } from 'react';
import React, { Dispatch, Fragment, SetStateAction, useEffect } from 'react';
import { isEmpty } from 'lodash';
import { RoleIndexPermission } from '../../types';
import { ResourceType } from '../../../../../common';
Expand Down Expand Up @@ -320,9 +320,11 @@ export function IndexPermissionPanel(props: {
}) {
const { state, optionUniverse, setState } = props;
// Show one empty row if there is no data.
if (isEmpty(state)) {
setState([getEmptyIndexPermission()]);
}
useEffect(() => {
if (isEmpty(state)) {
setState([getEmptyIndexPermission()]);
}
}, [state, setState]);
return (
<PanelWithHeader
headerText="Index permissions"
Expand Down
11 changes: 7 additions & 4 deletions public/apps/configuration/panels/role-edit/tenant-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { EuiButton, EuiComboBox, EuiFlexGroup, EuiFlexItem, EuiSuperSelect } from '@elastic/eui';
import React, { Dispatch, Fragment, SetStateAction } from 'react';
import React, { Dispatch, Fragment, SetStateAction, useEffect } from 'react';
import { isEmpty } from 'lodash';
import { RoleTenantPermission, TenantPermissionType, ComboBoxOptions } from '../../types';
import {
Expand Down Expand Up @@ -129,9 +129,12 @@ export function TenantPanel(props: {
}) {
const { state, optionUniverse, setState } = props;
// Show one empty row if there is no data.
if (isEmpty(state)) {
setState([getEmptyTenantPermission()]);
}

useEffect(() => {
if (isEmpty(state)) {
setState([getEmptyTenantPermission()]);
}
}, [state, setState]);
return (
<PanelWithHeader
headerText="Tenant permissions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { shallow } from 'enzyme';
import { render } from '@testing-library/react';
import React from 'react';
import { RoleIndexPermission, ComboBoxOptions, FieldLevelSecurityMethod } from '../../../types';
import { stringToComboBoxOption } from '../../../utils/combo-box-utils';
Expand Down Expand Up @@ -180,7 +181,7 @@ describe('Role edit - index permission panel', () => {
const state: RoleIndexPermissionStateClass[] = [];
const optionUniverse: ComboBoxOptions = [];

shallow(<IndexPermissionPanel {...{ state, optionUniverse, setState }} />);
render(<IndexPermissionPanel {...{ state, optionUniverse, setState }} />);

expect(setState).toHaveBeenCalledTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { shallow } from 'enzyme';
import React from 'react';
import { EuiComboBox, EuiButton, EuiSuperSelect } from '@elastic/eui';
import { render } from '@testing-library/react';

jest.mock('../../../utils/array-state-utils');
// eslint-disable-next-line
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('Role edit - tenant panel', () => {
const setState = jest.fn();

it('render an empty row if data is empty', () => {
shallow(<TenantPanel state={[]} optionUniverse={optionUniverse} setState={setState} />);
render(<TenantPanel state={[]} optionUniverse={optionUniverse} setState={setState} />);

expect(setState).toHaveBeenCalledWith([
{
Expand Down

0 comments on commit 8f5ef2d

Please sign in to comment.