Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion __tests__/components/__snapshots__/modal.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ exports[`Modal Component renders whole form after header clicked 1`] = `
className="flex items-center justify-center"
>
<button
className=" rounded px-4 py-2 text-white bg-green-700"
className="rounded px-4 py-2 text-white bg-green-700 disabled:cursor-not-allowed disabled:opacity-50"
disabled={true}
title="Please select a certification."
type="submit"
>
Create
Expand Down
15 changes: 15 additions & 0 deletions __tests__/components/modal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ describe('Modal Component', () => {
const tree = testRenderer.toJSON();
expect(tree).toMatchSnapshot();
});
it('disables the create button until a certification is selected', () => {
const testRenderer = renderer.create(
<Modal userId={sampleUser} certificationNames={sampleData} />
);
const testInstance = testRenderer.root;
const header = testInstance.findByProps({ className });

act(() => {
header.props.onClick();
});

const createButton = testInstance.findAllByType('button')[0];
expect(createButton.props.disabled).toBe(true);
expect(createButton.props.title).toBe('Please select a certification.');
});
});
8 changes: 7 additions & 1 deletion components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ export default function Modal({
<div className='flex items-center justify-center'>
<button
type='submit'
className=' rounded px-4 py-2 text-white bg-green-700'
className='rounded px-4 py-2 text-white bg-green-700 disabled:cursor-not-allowed disabled:opacity-50'
disabled={selected.length === 0}
title={
selected.length === 0
? 'Please select a certification.'
: undefined
}
>
Create
</button>
Expand Down