-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
1 changed file
with
40 additions
and
32 deletions.
There are no files selected for viewing
72 changes: 40 additions & 32 deletions
72
frontend/infosafe_frontend/src/components/__tests__/CreateDevicePopup.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,47 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { CreateDevicePopup } from '../Create/CreateDevicePopup.js'; | ||
import '@testing-library/jest-dom'; | ||
import {fireEvent, render} from "@testing-library/react"; | ||
import {CreateDevicePopup} from "../Create/CreateDevicePopup"; | ||
import { screen, configure } from '@testing-library/react' | ||
|
||
describe('CreateDevicePopup', () => { | ||
test('should submit the form with the entered data when "Submit" button is clicked', () => { | ||
const popupOpen = true; | ||
const popupClose = jest.fn(); | ||
it('should submit the form with the entered data when "Submit" button is clicked with valid input data', () => { | ||
// Mock data | ||
const popupOpen = true; | ||
const popupClose = jest.fn(); | ||
|
||
render(<CreateDevicePopup popupOpen={popupOpen} popupClose={popupClose} />); | ||
// Render component | ||
render(<CreateDevicePopup popupOpen={popupOpen} popupClose={popupClose} />); | ||
|
||
const assetNameInput = screen.getByLabelText('Device Type'); | ||
const assetDescriptionInput = screen.getByLabelText('Device Description'); | ||
const assignedUserInput = screen.getByLabelText('Assigned User'); | ||
const statusDropdown = screen.getByRole('combobox', { name: 'Status' }); | ||
const submitButton = screen.getByRole('button', { name: 'Submit' }); | ||
// 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'); | ||
|
||
const assetName = 'Test Device'; | ||
const assetDescription = 'This is a test device'; | ||
const assignedUser = 'John Doe'; | ||
const status = 'FULL'; | ||
// Set input values | ||
const assetName = 'Test Device'; | ||
const assetDescription = 'This is a test device'; | ||
//const assignedUser = 'John Doe'; | ||
const status = 'FULL'; | ||
|
||
fireEvent.change(assetNameInput, { target: { value: assetName } }); | ||
fireEvent.change(assetDescriptionInput, { target: { value: assetDescription } }); | ||
fireEvent.change(assignedUserInput, { target: { value: assignedUser } }); | ||
fireEvent.change(statusDropdown, { target: { value: status } }); | ||
fireEvent.click(submitButton); | ||
fireEvent.change(assetNameInput, { target: { value: assetName } }); | ||
fireEvent.change(assetDescriptionInput, { target: { value: assetDescription } }); | ||
//fireEvent.change(assignedUserInput, { target: { value: assignedUser } }); | ||
fireEvent.change(statusDropdown, { target: { value: status } }); | ||
|
||
expect(popupClose).toHaveBeenCalledTimes(1); | ||
expect(console.log).toHaveBeenCalledWith({ | ||
asset_name: assetName, | ||
asset_description: assetDescription, | ||
assignee: assignedUser, | ||
date_acquired: expect.any(String), | ||
status: status | ||
}); | ||
// Submit form | ||
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 | ||
}); | ||
}); | ||
}); |