Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-run on 67807bf #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
54 changes: 47 additions & 7 deletions src/AddItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
import { render, screen } from "@testing-library/react";
import AddItem from "../src/AddItem";

const empty = () => "";
import { render, screen, fireEvent } from "@testing-library/react";
import AddItem from "./AddItem";

test("Renders Input Form", () => {
render(<AddItem addItem={empty} />);
render(<AddItem addItem={() => {}} />);

const taskElement = screen.getByText("Task:");
const taskElement = screen.getByPlaceholderText("Enter task here");
expect(taskElement).toBeInTheDocument();

const priorityElement = screen.getByText("Priority:");
const priorityElement = screen.getByPlaceholderText("Enter priority here");
expect(priorityElement).toBeInTheDocument();

const submitButton = screen.getByRole('button', { name: /submit/i });
expect(submitButton).toBeInTheDocument();
});

test("Updates task state on input change", () => {
render(<AddItem addItem={() => {}} />);
const taskInput = screen.getByPlaceholderText("Enter task here");
fireEvent.change(taskInput, { target: { value: 'New Task' } });
expect(taskInput.value).toBe('New Task');
});

test("Updates priority state on input change", () => {
render(<AddItem addItem={() => {}} />);
const priorityInput = screen.getByPlaceholderText("Enter priority here");
fireEvent.change(priorityInput, { target: { value: '1' } });
expect(priorityInput.value).toBe('1');
});

test("Calls addItem on submit with valid input", () => {
const addItemMock = jest.fn();
render(<AddItem addItem={addItemMock} />);

const taskInput = screen.getByPlaceholderText("Enter task here");
const priorityInput = screen.getByPlaceholderText("Enter priority here");
const submitButton = screen.getByRole('button', { name: /submit/i });

fireEvent.change(taskInput, { target: { value: 'New Task' } });
fireEvent.change(priorityInput, { target: { value: '1' } });
fireEvent.click(submitButton);

expect(addItemMock).toHaveBeenCalledWith({ task: 'New Task', priority: 1 });
});

test("Does not call addItem on submit with invalid input", () => {
const addItemMock = jest.fn();
render(<AddItem addItem={addItemMock} />);

const submitButton = screen.getByRole('button', { name: /submit/i });
fireEvent.click(submitButton);

expect(addItemMock).not.toHaveBeenCalled();
});
25 changes: 0 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2885,13 +2885,6 @@ binary-extensions@^2.0.0:
resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz"
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==

bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
dependencies:
file-uri-to-path "1.0.0"

bluebird@^3.5.5:
version "3.7.2"
resolved "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz"
Expand Down Expand Up @@ -5387,19 +5380,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

fsevents@^1.2.7:
version "1.2.13"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz"
integrity sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==
dependencies:
bindings "^1.5.0"
nan "^2.12.1"

fsevents@^2.1.2, fsevents@^2.1.3, fsevents@~2.3.1:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
Expand Down Expand Up @@ -7618,11 +7598,6 @@ multicast-dns@^6.0.1:
dns-packet "^1.3.1"
thunky "^1.0.2"

nan@^2.12.1:
version "2.18.0"
resolved "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz"
integrity sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==

nanoid@^3.1.23:
version "3.1.23"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz"
Expand Down