Skip to content

Commit

Permalink
UIIN-2497 After creating a fast add instance record, only an empty de…
Browse files Browse the repository at this point in the history
…tail view is displayed (third column) (#2331)

* UIIN-2497 Show Instance record after creating with Fast add option

* UIIN-2497 Added tests for fast add record redirect
  • Loading branch information
BogdanDenis authored Nov 8, 2023
1 parent 3e59803 commit 846085d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Make Inventory search and browse query boxes expandable. Refs UIIN-2493.
* Added support for `containsAny` match option in Advanced search. Refs UIIN-2486.
* Inventory search/browse: Do not retain checkbox selections when toggling search segment. Refs UIIN-2477.
* Show Instance record after creating with Fast add option. Refs UIIN-2497.

## [10.0.3] IN PROGRESS

Expand Down
14 changes: 13 additions & 1 deletion src/components/InstancesList/InstancesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,19 @@ class InstancesList extends React.Component {
}
}

toggleNewFastAddModal = () => {
toggleNewFastAddModal = ({ instanceRecord }) => {
const {
history,
location,
} = this.props;

if (instanceRecord?.id) {
history.push({
pathname: `/inventory/view/${instanceRecord.id}`,
search: location.search,
});
}

this.setState((state) => {
return { showNewFastAddModal: !state.showNewFastAddModal };
});
Expand Down
37 changes: 37 additions & 0 deletions src/components/InstancesList/InstancesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ jest.mock('../../hooks', () => ({
}),
}));

jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
Pluggable: ({ renderTrigger, onClose }) => (
<>
{renderTrigger()}
<button type="button" onClick={() => onClose({ instanceRecord: { id: 'fast-add-record-id' } })}>Save & close</button>
</>
),
}));

const data = {
contributorTypes: [],
contributorNameTypes: [],
Expand Down Expand Up @@ -331,6 +341,33 @@ describe('InstancesList', () => {
});
});

describe('"New Fast Add record" button', () => {
it('should render', () => {
renderInstancesList({ segment: 'instances' });
openActionMenu();

expect(screen.getByRole('button', { name: 'New Fast Add Record' })).toBeInTheDocument();
});

describe('when saving the record', () => {
it('should redirect to new Instance record', async () => {
jest.spyOn(history, 'push');
renderInstancesList({ segment: 'instances' });
openActionMenu();

const button = screen.getByRole('button', { name: 'New Fast Add Record' });

fireEvent.click(button);
fireEvent.click(screen.getByText('Save & close'));

expect(history.push).toHaveBeenCalledWith({
pathname: '/inventory/view/fast-add-record-id',
search: '',
});
});
});
});

describe('"New MARC Bib Record" button', () => {
it('should render', () => {
renderInstancesList({ segment: 'instances' });
Expand Down

0 comments on commit 846085d

Please sign in to comment.