Skip to content

Commit

Permalink
New create device test
Browse files Browse the repository at this point in the history
  • Loading branch information
P3TROOS committed Sep 14, 2023
1 parent 1bf7bc9 commit 1c74786
Showing 1 changed file with 40 additions and 32 deletions.
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
});
});
});

0 comments on commit 1c74786

Please sign in to comment.