forked from infinispan/infinispan-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
764cd71
commit 0055051
Showing
11 changed files
with
687 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.