Skip to content

Commit

Permalink
ISPN-14921 Schemas table display
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanshug authored and andyuk1986 committed Aug 10, 2023
1 parent 764cd71 commit 0055051
Show file tree
Hide file tree
Showing 11 changed files with 687 additions and 295 deletions.
40 changes: 23 additions & 17 deletions cypress/e2e/proto-schema.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ describe('Proto Schema CRUD', () => {
//Going to the next page
cy.get('[data-cy=paginationArea]').should('exist');
cy.get('[data-action=previous]').should('be.disabled');
cy.get('[data-action=next]').click();
cy.get('[data-action=next]').first().click();
cy.contains('test-7.proto');
cy.contains('test-6.proto').should('not.exist');
cy.contains('test-10.proto').should('not.exist');

//Going to the previous page
cy.get('[data-cy=paginationArea]').should('exist');
cy.get('[data-action=next]').should('be.disabled');
cy.get('[data-action=previous]').click();
cy.get('[data-action=previous]').first().click();
cy.contains('test-9.proto').should('not.exist');
cy.contains('test-6.proto');
cy.contains('test-10.proto');

//Changing the number of items on the page
cy.get('[id^="pagination-schemas-top-toggle"]').click();
cy.get('[id^="pagination-schemas-top-toggle"]').first().click();
cy.get('[data-action=per-page-10] > div').should('exist'); //Verifying the selected option
cy.get('[data-action=per-page-20] > div').should('not.exist');
cy.get('[data-action=per-page-50] > div').should('not.exist');
Expand All @@ -40,7 +40,7 @@ describe('Proto Schema CRUD', () => {

//Changing the number of items on the page back to 10
cy.get('#primary-app-container').scrollTo('bottom');
cy.get('[id^="pagination-schemas-top-toggle"]').click();
cy.get('[id^="pagination-schemas-top-toggle"]').first().click();
cy.get('[data-action=per-page-10] > div').should('not.exist'); //Verifying the selected option
cy.get('[data-action=per-page-20] > div').should('exist');
cy.get('[data-action=per-page-50] > div').should('not.exist');
Expand All @@ -49,12 +49,13 @@ describe('Proto Schema CRUD', () => {
cy.contains('test-7.proto').should('not.exist');
cy.contains('test-6.proto');
cy.contains('test-10.proto');
cy.get('[data-action=next]').click();
cy.get('[data-action=next]').first().click();
cy.contains('test-9.proto');
});

it('successfully creates, edits and deletes a proto schema', () => {
cy.get('a[aria-label="nav-item-Schemas"]').click();

//Creating new schema
cy.get('button[aria-label="create-schema-button"]').click();
cy.get('#schema-name').click().type('aTestSchema');
Expand All @@ -63,39 +64,44 @@ describe('Proto Schema CRUD', () => {
cy.contains('Schema aTestSchema created.');
cy.get('.pf-c-alert__action > .pf-c-button').click(); //Closing alert popup.
cy.contains('aTestSchema.proto');

//Updating existing schema
cy.contains('Schema aTestSchema.proto has errors');
cy.get('button[aria-label="expand-schema-aTestSchema.proto"]').click({ force: true });
cy.get('[data-cy="actions-aTestSchema.proto"]>div>button').click();
cy.get('[aria-label="editSchemaAction"]').click();
cy.contains('schemaValue');
cy.contains('Edit');
cy.wait(5000);
cy.get('button[aria-label="edit-button-schema-aTestSchema.proto"]').click({ force: true });
cy.contains('Save');
cy.get('[data-cy=schemaEditArea]', { timeout: 10000 }).contains('schemaValue');
cy.get('[data-cy=schemaEditArea]').type('{selectall}', { timeout: 10000 });
cy.get('[data-cy=schemaEditArea]').type('schemaNewValue');
cy.get('button[aria-label="edit-button-schema-aTestSchema.proto"]').click({ force: true });
cy.get('button[aria-label="confirm-edit-schema-button"]').click();
cy.contains('Schema aTestSchema.proto updated.');
cy.get('.pf-c-alert__action > .pf-c-button').click(); //Closing alert popup.
cy.contains('schemaNewValue');

//Updating existing schema with correct value
cy.contains('Schema aTestSchema.proto has errors');
cy.get('button[aria-label="edit-button-schema-aTestSchema.proto"]').click({ force: true });
cy.get('[data-cy="actions-aTestSchema.proto"]>div>button').click();
cy.get('[aria-label="editSchemaAction"]').click();
cy.get('[data-cy=schemaEditArea]').contains('schemaNewValue');
cy.get('[data-cy=schemaEditArea]').type('{selectall}', { timeout: 10000 });
cy.get('[data-cy=schemaEditArea]').type(
'package org.infinispan; message ExampleProto { optional int32 other_id = 1; }',
{ parseSpecialCharSequences: false }
);
cy.get('button[aria-label="edit-button-schema-aTestSchema.proto"]').click({ force: true });
cy.get('button[aria-label="confirm-edit-schema-button"]').click();
cy.contains('Schema aTestSchema.proto updated.');
cy.get('.pf-c-alert__action > .pf-c-button').click(); //Closing alert popup.
cy.get('[data-cy="aTestSchema.protoConfig"]').click();
cy.wait(1000)
cy.contains('schemaNewValue').should('not.exist');
cy.contains('ExampleProto');
cy.contains('Schema aTestSchema.proto has errors').should('not.exist');

//Deleting schema
cy.get('button[aria-label="delete-button-schema-aTestSchema.proto"]').click({ force: true });
cy.contains('Permanently delete schema?');
cy.get('[data-cy="actions-aTestSchema.proto"]>div>button').click();
cy.get('[aria-label="deleteSchemaAction"]').click();
cy.contains('Delete schema?');
cy.get('button[aria-label="confirm-delete-schema-button"]').click();
cy.contains('Schema aTestSchema.proto has been deleted.');
cy.get('.pf-c-alert__action > .pf-c-button').click(); //Closing alert popup.
Expand Down Expand Up @@ -124,9 +130,9 @@ describe('Proto Schema CRUD', () => {
cy.contains('*/name!@#$with%^&*special()_+symbols{}|":isnot?');
cy.contains('><saved>.proto')
//Deleting schema
cy.get('button[id^="1234567890+-"]').click({ force: true});
cy.get('button[id^="delete-button-schema-1234567890"]').click({ force: true });
cy.contains('Permanently delete schema?');
cy.get('[data-cy^="actions-1234567890+-"]>div>button').click();
cy.get('[aria-label="deleteSchemaAction"]').click();
cy.contains('Delete schema?');
cy.get('button[aria-label="confirm-delete-schema-button"]').click();
cy.contains('has been deleted.');
});
Expand Down
12 changes: 7 additions & 5 deletions cypress/e2e/rbac_func.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,18 @@ describe('RBAC Functionlity Tests', () => {
cy.get('a[aria-label="nav-item-Schemas"]').click();
cy.contains('people');
cy.contains('test-6.proto');
cy.get('button[aria-label="expand-schema-people.proto"]').click({ force: true });
cy.get('[data-cy="people.protoConfig"]').click();
cy.contains('message Person');
if (isAdmin) {
cy.get('button[aria-label="create-schema-button"]').should('exist');
cy.get('button[aria-label="edit-button-schema-people.proto"]').should('exist');
cy.get('button[aria-label="delete-button-schema-people.proto"]').should('exist');
cy.get('[data-cy="actions-people.proto"]>div>button').click();
cy.get('[aria-label="editSchemaAction"]').should('exist');
cy.get('[aria-label="deleteSchemaAction"]').should('exist');
} else {
cy.get('button[aria-label="create-schema-button"]').should('not.exist');
cy.get('button[aria-label="edit-button-schema-people.proto"]').should('not.exist');
cy.get('button[aria-label="delete-button-schema-people.proto"]').should('not.exist');
cy.get('[data-cy="actions-people.proto"]>div>button').click();
cy.get('[aria-label="editSchemaAction"]').should('exist');
cy.get('[aria-label="deleteSchemaAction"]').should('exist');
}
}

Expand Down
52 changes: 52 additions & 0 deletions src/__tests__/views/schemas/DeleteSchema.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { DeleteSchema } from '@app/ProtoSchema/DeleteSchema';
import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import * as DeleteSchemaHook from '@app/services/protobufHooks';
import { renderWithRouter } from '../../../test-utils';

jest.mock('@app/services/protobufHooks');
const mockedSchemaHook = DeleteSchemaHook as jest.Mocked<typeof DeleteSchemaHook>;

let closeModalCalls;
let onDeleteCalls;

beforeEach(() => {
closeModalCalls = 0;
onDeleteCalls = 0;
});

mockedSchemaHook.useDeleteProtobufSchema.mockImplementation(() => {
return {
onDeleteSchema: () => onDeleteCalls++
};
});

describe('Delete schema', () => {
test('not render the dialog if the modal is closed', () => {
renderWithRouter(<DeleteSchema schemaName={'schema-1'} isModalOpen={false} closeModal={() => closeModalCalls++} />);
expect(screen.queryByRole('modal')).toBeNull();
expect(closeModalCalls).toBe(0);
expect(onDeleteCalls).toBe(0);
});

test('render the dialog and buttons work', () => {
renderWithRouter(<DeleteSchema schemaName={'schema-1'} isModalOpen={true} closeModal={() => closeModalCalls++} />);

expect(mockedSchemaHook.useDeleteProtobufSchema).toHaveBeenCalledWith('schema-1');

expect(screen.queryByRole('modal')).toBeDefined();
expect(screen.queryAllByRole('button')).toHaveLength(3);

const closeButton = screen.getByRole('button', { name: 'Close' });
fireEvent.click(closeButton);
expect(closeModalCalls).toBe(1);

const cancelButton = screen.getByRole('button', { name: 'cancel-delete-schema-button' });
fireEvent.click(cancelButton);
expect(closeModalCalls).toBe(2);

const confirmButton = screen.getByRole('button', { name: 'confirm-delete-schema-button' });
fireEvent.click(confirmButton);
expect(onDeleteCalls).toBe(1);
});
});
115 changes: 115 additions & 0 deletions src/__tests__/views/schemas/EditSchema.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import { EditSchema } from '@app/ProtoSchema/EditSchema';
import * as EditSchemaHook from '@app/services/protobufHooks';
import { renderWithRouter } from '../../../test-utils';

jest.mock('@app/services/protobufHooks');
const mockedSchemaHook = EditSchemaHook as jest.Mocked<typeof EditSchemaHook>;

let closeModalCalls;
let submitModalCalls;
let onEditSchemaCalls;

beforeEach(() => {
closeModalCalls = 0;
submitModalCalls = 0;
onEditSchemaCalls = 0;
});

mockedSchemaHook.useEditProtobufSchema.mockImplementation(() => {
return {
onEditSchema: () => onEditSchemaCalls++
};
});

describe('Edit schema', () => {
test('not render the dialog if the modal is closed', () => {
mockedSchemaHook.useFetchProtobufSchemaContent.mockImplementation(() => {
return {
schemaContent: '',
loading: true,
error: '',
setLoading: () => {}
};
});

renderWithRouter(
<EditSchema
schemaName={'schema-1'}
isModalOpen={false}
closeModal={() => closeModalCalls++}
submitModal={() => submitModalCalls++}
/>
);

expect(screen.queryByRole('modal')).toBeNull();
expect(closeModalCalls).toBe(0);
expect(submitModalCalls).toBe(0);
expect(onEditSchemaCalls).toBe(0);
});

test('render the dialog with no schema content ', () => {
mockedSchemaHook.useFetchProtobufSchemaContent.mockImplementation(() => {
return {
schemaContent: '',
loading: true,
error: '',
setLoading: () => {}
};
});

renderWithRouter(
<EditSchema
schemaName={'schema-1'}
isModalOpen={true}
closeModal={() => closeModalCalls++}
submitModal={() => submitModalCalls++}
/>
);

expect(screen.queryByRole('modal')).toBeDefined();
expect(screen.queryAllByRole('button')).toHaveLength(3);
expect(screen.getByText('schemas.save-button').closest('button')).toBeDisabled();

expect(closeModalCalls).toBe(0);
expect(submitModalCalls).toBe(0);
expect(onEditSchemaCalls).toBe(0);
});

test('render the dialog and buttons work', () => {
mockedSchemaHook.useFetchProtobufSchemaContent.mockImplementation(() => {
return {
schemaContent: 'schema-content',
loading: true,
error: '',
setLoading: () => {}
};
});

renderWithRouter(
<EditSchema
schemaName={'schema-1'}
isModalOpen={true}
closeModal={() => closeModalCalls++}
submitModal={() => submitModalCalls++}
/>
);

expect(screen.queryByRole('modal')).toBeDefined();
expect(screen.queryAllByRole('button')).toHaveLength(3);

const closeButton = screen.getByRole('button', { name: 'Close' });
fireEvent.click(closeButton);
expect(closeModalCalls).toBe(1);

const cancelButton = screen.getByRole('button', { name: 'cancel-edit-schema-button' });
fireEvent.click(cancelButton);
expect(closeModalCalls).toBe(2);

const submitButton = screen.getByRole('button', { name: 'confirm-edit-schema-button' });
fireEvent.click(submitButton);
expect(onEditSchemaCalls).toBe(1);
expect(submitModalCalls).toBe(1);
});
});
33 changes: 17 additions & 16 deletions src/app/ProtoSchema/CreateProtoSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import { ConsoleServices } from '@services/ConsoleServices';
import { AddCircleOIcon } from '@patternfly/react-icons';
import { PopoverHelp } from '@app/Common/PopoverHelp';

const schemaNameInitialState: IField = {
value: '',
isValid: true,
invalidText: 'Schema name is required',
helperText: 'The schema name must not exist',
validated: 'default'
};

const schemaInitialState: IField = {
value: '',
isValid: true,
invalidText: 'Schema is required',
helperText: 'Protobuf schema',
validated: 'default'
};

const CreateProtoSchema = (props: { isModalOpen: boolean; closeModal: (boolean) => void }) => {
const { t } = useTranslation();
const { addAlert } = useApiAlert();
const [error, setError] = useState<string | undefined>(undefined);

const schemaNameInitialState: IField = {
value: '',
isValid: true,
invalidText: 'Schema name is required',
helperText: 'The schema name must not exist',
validated: 'default'
};
const [schemaName, setSchemaName] = useState<IField>(schemaNameInitialState);

const schemaInitialState: IField = {
value: '',
isValid: true,
invalidText: 'Schema is required',
helperText: 'Protobuf schema',
validated: 'default'
};
const [schema, setSchema] = useState<IField>(schemaInitialState);

const clearCreateProtoSchema = (createDone: boolean) => {
Expand Down Expand Up @@ -84,6 +84,7 @@ const CreateProtoSchema = (props: { isModalOpen: boolean; closeModal: (boolean)
value={schemaName.value}
id="schema-name"
name="schema-name"
aria-label="schema-name"
aria-describedby="schema-name-helper"
onChange={(v) =>
setSchemaName((prevState) => {
Expand Down
Loading

0 comments on commit 0055051

Please sign in to comment.