-
Notifications
You must be signed in to change notification settings - Fork 42
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
a7cb855
commit 7088a29
Showing
5 changed files
with
233 additions
and
33 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
77 changes: 77 additions & 0 deletions
77
src/components/Accounts/ChargeFeeFine/ChargeFeeFine.test.js
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,77 @@ | ||
import { | ||
screen, | ||
render, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import ChargeFeeFine from './ChargeFeeFine'; | ||
import ChargeForm from './ChargeForm'; | ||
|
||
const basicProps = { | ||
resources: { | ||
activeRecord: { | ||
isBarcodeValidated: true, | ||
}, | ||
}, | ||
mutator: { | ||
activeRecord: { | ||
update: jest.fn(), | ||
}, | ||
}, | ||
user: {}, | ||
stripes: {}, | ||
location: {}, | ||
history: {}, | ||
intl: {}, | ||
match: { | ||
params: {}, | ||
}, | ||
okapi: { | ||
currentUser: {}, | ||
}, | ||
}; | ||
const testIds = { | ||
selectItem: 'selectItem', | ||
}; | ||
const itemBarcode = 'itemBarcode'; | ||
|
||
jest.mock('./ChargeForm', () => jest.fn(({ | ||
onClickSelectItem, | ||
}) => ( | ||
<> | ||
<button | ||
type="button" | ||
data-testid={testIds.selectItem} | ||
onClick={() => onClickSelectItem(itemBarcode)} | ||
> | ||
Enter | ||
</button> | ||
</> | ||
))); | ||
jest.mock('./ItemLookup', () => jest.fn(() => <div />)); | ||
jest.mock('../Actions/ActionModal', () => jest.fn(() => <div />)); | ||
|
||
describe('ChargeFeeFine', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
render(<ChargeFeeFine {...basicProps} />); | ||
}); | ||
|
||
it('should trigger ChargeForm', () => { | ||
expect(ChargeForm).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should update activeRecord', async () => { | ||
const selectItemButton = screen.getByTestId(testIds.selectItem); | ||
|
||
await userEvent.click(selectItemButton); | ||
|
||
expect(basicProps.mutator.activeRecord.update).toHaveBeenCalledWith({ | ||
barcode: itemBarcode, | ||
isBarcodeValidated: true, | ||
}); | ||
}); | ||
}); |
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
149 changes: 129 additions & 20 deletions
149
src/components/Accounts/ChargeFeeFine/ItemInfo.test.js
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 |
---|---|---|
@@ -1,39 +1,148 @@ | ||
import { screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { | ||
screen, | ||
render, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import renderWithRouter from 'helpers/renderWithRouter'; | ||
import ItemInfo from './ItemInfo'; | ||
import { NEW_FEE_FINE_FIELD_NAMES } from '../../../constants'; | ||
|
||
import '__mock__/stripesCore.mock'; | ||
import '__mock__/stripesSmartComponent.mock'; | ||
|
||
jest.unmock('@folio/stripes/components'); | ||
|
||
const renderItemInfo = (props) => renderWithRouter( | ||
const renderItemInfo = (props) => render( | ||
<ItemInfo {...props} /> | ||
); | ||
|
||
const selectMock = jest.fn(); | ||
|
||
const props = { | ||
onClickSelectItem: selectMock, | ||
const basicProps = { | ||
onClickSelectItem: jest.fn(), | ||
item: {}, | ||
editable: true | ||
editable: true, | ||
resources: { | ||
items: { | ||
records: [], | ||
}, | ||
activeRecord: { | ||
barcode: 'itemBarcode', | ||
}, | ||
}, | ||
mutator: { | ||
activeRecord: { | ||
replace: jest.fn(), | ||
}, | ||
}, | ||
form: { | ||
change: jest.fn(), | ||
}, | ||
values: {}, | ||
}; | ||
const labelIds = { | ||
itemTitle: 'ui-users.charge.item.title', | ||
chargeButton: 'ui-users.charge.item.button', | ||
}; | ||
const testIds = { | ||
itemBarcodeField: 'itemBarcodeField', | ||
}; | ||
|
||
describe('Item Info component', () => { | ||
it('if it renders', () => { | ||
renderItemInfo(props); | ||
expect(screen.getByText('ui-users.charge.item.title')).toBeInTheDocument(); | ||
jest.mock('react-final-form', () => ({ | ||
Field: jest.fn(({ | ||
children, | ||
'data-testid': testId, | ||
validate, | ||
}) => { | ||
return children({ | ||
meta: {}, | ||
input: { | ||
validate, | ||
'data-testid': testId, | ||
value: '', | ||
}, | ||
}); | ||
}), | ||
})); | ||
jest.mock('react-router-dom', () => ({ | ||
Link: jest.fn(() => <div />), | ||
})); | ||
|
||
describe('ItemInfo', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('Charge Item Button', async () => { | ||
renderItemInfo(props); | ||
await userEvent.click(screen.getByText('ui-users.charge.item.button')); | ||
expect(selectMock).toHaveBeenCalled(); | ||
|
||
describe('Initial render', () => { | ||
beforeEach(() => { | ||
renderItemInfo(basicProps); | ||
}); | ||
|
||
it('should render item title', () => { | ||
const itemTitle = screen.getByText(labelIds.itemTitle); | ||
|
||
expect(itemTitle).toBeInTheDocument(); | ||
}); | ||
|
||
it('should get item information', async () => { | ||
const chargeButton = screen.getByText(labelIds.chargeButton); | ||
|
||
await userEvent.click(chargeButton); | ||
|
||
expect(basicProps.onClickSelectItem).toHaveBeenCalled(); | ||
}); | ||
}); | ||
it('charge item text field', async () => { | ||
renderItemInfo(props); | ||
await userEvent.type(document.querySelector('[placeholder="ui-users.charge.item.placeholder"]'), 'Test'); | ||
expect(document.querySelector('[placeholder="ui-users.charge.item.placeholder"]').value).toBe('Test'); | ||
|
||
describe('Component updating', () => { | ||
const itemBarcode = 'newItemBarcode'; | ||
const newProps = { | ||
...basicProps, | ||
resources: { | ||
...basicProps.resources, | ||
items: { | ||
records: [ | ||
{ | ||
id: 'itemId', | ||
} | ||
] | ||
} | ||
}, | ||
}; | ||
|
||
beforeEach(async () => { | ||
const { rerender } = renderItemInfo(basicProps); | ||
|
||
const itemBarcodeField = screen.getByTestId(testIds.itemBarcodeField); | ||
|
||
await userEvent.type(itemBarcodeField, itemBarcode); | ||
|
||
rerender(<ItemInfo {...newProps} />); | ||
}); | ||
|
||
it('should change "key" value of barcode field', () => { | ||
expect(basicProps.form.change).toHaveBeenCalledWith(NEW_FEE_FINE_FIELD_NAMES.KEY_OF_ITEM_BARCODE, basicProps.values[NEW_FEE_FINE_FIELD_NAMES.KEY_OF_ITEM_BARCODE] ? 0 : 1); | ||
}); | ||
}); | ||
|
||
describe('Item barcode changing', () => { | ||
const itemBarcode = 'newItemBarcode'; | ||
|
||
beforeEach(async () => { | ||
renderItemInfo(basicProps); | ||
|
||
const itemBarcodeField = screen.getByTestId(testIds.itemBarcodeField); | ||
|
||
await userEvent.type(itemBarcodeField, itemBarcode); | ||
}); | ||
|
||
it('should replace activeRecord', () => { | ||
expect(basicProps.mutator.activeRecord.replace).toHaveBeenCalledWith({ | ||
...basicProps.resources.activeRecord, | ||
isBarcodeValidated: false, | ||
barcode: '', | ||
}); | ||
}); | ||
|
||
it('should change item barcode field', () => { | ||
expect(basicProps.form.change).toHaveBeenCalledWith(NEW_FEE_FINE_FIELD_NAMES.ITEM_BARCODE, itemBarcode); | ||
}); | ||
}); | ||
}); |