Skip to content

Commit

Permalink
Unit test additions
Browse files Browse the repository at this point in the history
  • Loading branch information
P3TROOS committed Sep 17, 2023
1 parent 1c74786 commit 2c5c68a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const CreateDevicePopup = ({ popupOpen, popupClose }) => {
<p className="deviceNameLabel">Device Name</p>
<input className="deviceNameInput"
value={asset_name} onChange={(e)=>setAsset_name(e.target.value)}
inputprops={{ "data-testid": "asset_name" }}
/>
<p className="deviceTypeLabel">Device Type</p>
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,17 @@ it('should submit the form with the entered data when "Submit" button is clicked
// Render component
render(<CreateDevicePopup popupOpen={popupOpen} popupClose={popupClose} />);

// Get form elements
const assetNameInput = screen.getByText('Device Name');
const assetTypeInput = screen.getByText('Device Type');
const assetDescriptionInput = screen.getByText('Device Description');
//const usedDropdown = screen.getByRole('combobox', { name: 'New' });
//const availableDropdown = screen.getByRole('combobox', { name: 'Available' });
//const statusDropdown = screen.getByRole('combobox', { name: 'Status' });
//const submitButton = screen.getByRole('button', { name: 'Submit' });
const currentCustodianInput = screen.getByText('Current Custodian');
const previousCustodianInput = screen.getByText('Previous Custodian');
// Simulate input changes
const deviceNameInput = screen.getByTestId("asset_name");
fireEvent.change(deviceNameInput, { target: { value: 'New Device Name' } });

// Set input values
const assetName = 'Test Device';
const assetDescription = 'This is a test device';
//const assignedUser = 'John Doe';
const status = 'FULL';
// Verify that the input value has changed
expect(deviceNameInput.value).toBe('New Device Name');

fireEvent.change(assetNameInput, { target: { value: assetName } });
fireEvent.change(assetDescriptionInput, { target: { value: assetDescription } });
//fireEvent.change(assignedUserInput, { target: { value: assignedUser } });
fireEvent.change(statusDropdown, { target: { value: status } });

// Submit form
// You can also simulate other interactions and make assertions as needed
// For example, clicking the Submit button:
const submitButton = screen.getByText('Submit');
fireEvent.click(submitButton);

// Verify form submission
expect(popupClose).toHaveBeenCalledTimes(1);
expect(console.log).toHaveBeenCalledWith({
asset_name: assetName,
asset_description: assetDescription,
//assignee: assignedUser,
date_acquired: expect.any(String),
status: status
});

});

0 comments on commit 2c5c68a

Please sign in to comment.