Skip to content

Commit

Permalink
Completes cypress test for Permissions tab, fixes cypress test for Us…
Browse files Browse the repository at this point in the history
…ers tab and fixes a spelling error

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
  • Loading branch information
DarshitChanpura committed Mar 29, 2024
1 parent d8f2ff1 commit a04c5b8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function toggleRowDetails(
});
}

export function renderRowExpanstionArrow(
export function renderRowExpansionArrow(
itemIdToExpandedRowMap: ExpandedRowMapInterface,
actionGroupDict: DataObject<ActionGroupItem>,
setItemIdToExpandedRowMap: Dispatch<SetStateAction<ExpandedRowMapInterface>>
Expand Down Expand Up @@ -139,7 +139,7 @@ function getColumns(
align: RIGHT_ALIGNMENT,
width: '40px',
isExpander: true,
render: renderRowExpanstionArrow(
render: renderRowExpansionArrow(
itemIdToExpandedRowMap,
actionGroupDict,
setItemIdToExpandedRowMap
Expand Down Expand Up @@ -323,7 +323,11 @@ export function PermissionList(props: AppDependencies) {
};

const createActionGroupMenuItems = [
<EuiButtonEmpty key="create-from-blank" onClick={() => showEditModal('', Action.create, [])}>
<EuiButtonEmpty
key="create-from-blank"
id="create-from-blank"
onClick={() => showEditModal('', Action.create, [])}
>
Create from blank
</EuiButtonEmpty>,
<EuiButtonEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
PermissionList,
renderBooleanToCheckMark,
toggleRowDetails,
renderRowExpanstionArrow,
renderRowExpansionArrow,
} from '../permission-list';
import { EuiInMemoryTable, EuiButtonIcon } from '@elastic/eui';
import {
Expand Down Expand Up @@ -78,15 +78,15 @@ describe('Permission list page ', () => {

describe('renderRowExpanstionArrow', () => {
it('should render down arrow when collapsed', () => {
const renderFunc = renderRowExpanstionArrow({}, {}, jest.fn());
const renderFunc = renderRowExpansionArrow({}, {}, jest.fn());
const Wrapper = () => <>{renderFunc(sampleActionGroup)}</>;
const component = shallow(<Wrapper />);

expect(component.find(EuiButtonIcon).prop('iconType')).toBe('arrowDown');
});

it('should render up arrow when expanded', () => {
const renderFunc = renderRowExpanstionArrow(
const renderFunc = renderRowExpansionArrow(
{ [sampleActionGroup.name]: sampleActionGroup },
{},
jest.fn()
Expand Down
103 changes: 61 additions & 42 deletions test/cypress/e2e/multi-datasources/multi_datasources_enabled.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const createDataSource = () => {
},
body: {
attributes: {
title: `9202`,
endpoint: `https://localhost:9202`,
title: '9202',
endpoint: 'https://localhost:9202',
auth: {
type: 'username_password',
credentials: {
Expand All @@ -36,28 +36,27 @@ const createDataSource = () => {
});
};

const deleteAllDataSources = () => {
cy.request(
'GET',
`${Cypress.config(
'baseUrl'
)}/api/saved_objects/_find?fields=id&fields=description&fields=title&per_page=10000&type=data-source`
).then((resp) => {
if (resp && resp.body && resp.body.saved_objects) {
resp.body.saved_objects.map(({ id }) => {
cy.request({
method: 'DELETE',
url: `${Cypress.config('baseUrl')}/api/saved_objects/data-source/${id}`,
body: { force: false },
headers: {
'osd-xsrf': true,
},
});
});
const closeToast = () => {
// remove browser incompatibiltiy toast causing flakyness (cause it has higher z-index than Create button making it invisible)
cy.get('body').then((body) => {
if (body.find('[data-test-subj="toastCloseButton"]').length > 0) {
cy.get('[data-test-subj="toastCloseButton"]').click();
}
});
};

const deleteAllDataSources = () => {
cy.visit('http://localhost:5601/app/management/opensearch-dashboards/dataSources');

closeToast();

cy.get('[data-test-subj="checkboxSelectAll"]').should('exist');
cy.get('[data-test-subj="checkboxSelectAll"]').click();
cy.get('[data-test-subj="checkboxSelectAll"]').should('be.checked');
cy.get('[data-test-subj="deleteDataSourceConnections"]').click();
cy.get('[data-test-subj="confirmModalConfirmButton"]').click();
};

describe('Multi-datasources enabled', () => {
before(() => {
localStorage.setItem('opendistro::security::tenant::saved', '""');
Expand All @@ -77,7 +76,7 @@ describe('Multi-datasources enabled', () => {
cy.get('.euiToastHeader__title').should('contain', 'successful for Local cluster');
// Remote cluster purge cache
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', '9202').click();
cy.get('[title="9202"]').click();
cy.get('[data-test-subj="purge-cache"]').click();
cy.get('.euiToastHeader__title').should('contain', 'successful for 9202');
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/auth');
Expand All @@ -91,63 +90,83 @@ describe('Multi-datasources enabled', () => {
cy.get('.panel-header-count').first().invoke('text').should('contain', '(6)');
// Remote cluster auth
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', '9202').click();
cy.get('[title="9202"]').click();
cy.get('.panel-header-count').first().invoke('text').should('contain', '(2)');
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/users');
// Data source persisted across tabs
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').contains('9202');
});

it.skip('Checks Users Tab', () => {
it('Checks Users Tab', () => {
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/users');
// Create an internal user in the remote cluster
cy.contains('h3', 'Internal users');
cy.contains('a', 'admin');
// TODO replace these with navigating to urls that get read to determine datasource, since these are flaky

closeToast();

// select remote data source
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', '9202').click();
cy.get('[title="9202"]').click();

// create a user on remote data source
cy.get('[data-test-subj="create-user"]').click();
cy.get('[data-test-subj="name-text"]').focus().type('9202-user');
cy.get('[data-test-subj="password"]').focus().type('myStrongPassword123!');
cy.get('[data-test-subj="re-enter-password"]').focus().type('myStrongPassword123!');
cy.get('[data-test-subj="submit-save-user"]').click();

// Internal user exists on the remote
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/users');
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', '9202').click();
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').should(
'contain',
'9202'
);
cy.get('[data-test-subj="checkboxSelectRow-9202-user"]').should('exist');

// Internal user doesn't exist on local cluster
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', 'Local cluster').click();
cy.get('[title="Local cluster"]').click();
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').should(
'contain',
'Local cluster'
);
cy.get('[data-test-subj="checkboxSelectRow-9202-user"]').should('not.exist');
});

it('Checks Permissions Tab', () => {
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/permissions');
// Create a permission in the remote cluster
cy.contains('h3', 'Permissions');
// Select 9202 cluster

closeToast();

// Select remote cluster
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', '9202').click();
cy.get('[title="9202"]').click();
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').should(
'contain',
'9202'
);

// Create an action group
cy.get('[id="Create action group"]').click();
cy.contains('li.euiFlexItem', 'Create from blank').click();
cy.get('[data-test-subj="name-text"]').focus().type('test-permission-ag');
cy.contains('div.euiFlexItem > button', 'Create from blank').click();
cy.get('[data-test-subj="name-text"]')

Check warning on line 151 in test/cypress/e2e/multi-datasources/multi_datasources_enabled.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Do not use force on click and type calls

Check warning on line 151 in test/cypress/e2e/multi-datasources/multi_datasources_enabled.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Do not use force on click and type calls

Check warning on line 151 in test/cypress/e2e/multi-datasources/multi_datasources_enabled.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Do not use force on click and type calls
.focus()
.type('test_permission_ag', { force: true })
.should('have.value', 'test_permission_ag');
cy.get('[data-test-subj="comboBoxInput"]').focus().type('some_permission');
cy.get('[id="submit"]').click();

// Permission exists on the remote data source
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/permissions');
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', '9202').click();
cy.get('[data-test-subj="checkboxSelectRow-test-permission-ag"]').should('exist');
cy.get('[data-text="Customization"]').click();
cy.contains('div.euiFilterSelect__items > button', 'Custom').click();
cy.get('[data-test-subj="checkboxSelectRow-test_permission_ag"]').should('exist');

// Permission doesn't exist on local cluster
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
cy.contains('li.euiSelectableListItem', 'Local cluster').click();
cy.get('[data-test-subj="checkboxSelectRow-test-permission-ag"]').should('not.exist');
cy.get('[title="Local cluster"]').click();
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').should(
'contain',
'Local cluster'
);
cy.get('[data-test-subj="checkboxSelectRow-test_permission_ag"]').should('not.exist');
});
});

0 comments on commit a04c5b8

Please sign in to comment.