Skip to content
Draft
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
403 changes: 58 additions & 345 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"private": true,
"dependencies": {
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^30.0.0",
"@types/node": "^24.10.1",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.126",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-scripts": "5.0.1",
"typescript": "^5.9.3",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand All @@ -38,9 +40,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0"
}
}
14 changes: 14 additions & 0 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "@testing-library/jest-dom";
import { title_test_title } from "./components/Title/Title.testFunctions";
import {
form_test_placeholder,
form_test_artist_label,
form_test_input,
form_test_submit
} from "./components/Form/Form.testFunctions";

test("Displays the title 'Harmonise'", title_test_title);
test("Displays field with placeholder text 'Dawn of the Squid'", form_test_placeholder);
test("Displays 'Artist Name' field label", form_test_artist_label);
test("Accepts user input", form_test_input);
test("Calls handleSubmit with input data", form_test_submit);
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import './App.css';
import Title from './components/Title/Title';
import Form from './components/Form/Form';


function App() {
return (
<div className="App">
<Title />
<Form />
</div>
);
}
Expand Down
12 changes: 12 additions & 0 deletions src/components/Form/Form.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "@testing-library/jest-dom";
import {
form_test_placeholder,
form_test_artist_label,
form_test_input,
form_test_submit
} from "./Form.testFunctions";

test("Displays field with placeholder text 'Dawn of the Squid'", form_test_placeholder);
test("Displays 'Artist Name' field label", form_test_artist_label);
test("Accepts user input", form_test_input);
test("Calls handleSubmit with input data", form_test_submit);
52 changes: 52 additions & 0 deletions src/components/Form/Form.testFunctions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { render, screen } from "@testing-library/react";
import Form from "./Form";
import userEvent from "@testing-library/user-event";
import { handleSubmit } from "../../functions/handleSubmit";

jest.mock("../../functions/handleSubmit", () => ({

handleSubmit: jest.fn()

}));


export const form_test_placeholder = () => {

render(<Form />);
const text = screen.getByPlaceholderText('Dawn of the Squid')

expect(text).toBeInTheDocument();

};

export const form_test_artist_label = () => {

render(<Form />);
const text = screen.getByLabelText('Artist Name')

expect(text).toBeInTheDocument();

};

export const form_test_input: () => Promise<void> = async () => {

render(<Form />);
const artistNameField = screen.getByLabelText("Artist Name");

await userEvent.type(artistNameField, "Music Research Unit");

expect(artistNameField).toHaveValue("Music Research Unit");

};

export const form_test_submit: () => Promise<void> = async () => {

render(<Form />);
const artistNameField = screen.getByLabelText("Artist Name");
const button = screen.getByRole("button", { name: /submit/i });

await userEvent.type(artistNameField, 'Music Research Unit')
await userEvent.click(button);

expect(handleSubmit).toHaveBeenCalledWith({ artistName: 'Music Research Unit'});
};
39 changes: 39 additions & 0 deletions src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useState } from "react";
import { handleSubmit } from "../../functions/handleSubmit"

export default function Form() {

const [artistName, setArtistName] = useState("");

const metadata = {
inputId : 'artist-name',
fieldLabel : 'Artist Name',
type : 'text',
placeholder : 'Dawn of the Squid',
buttonText : 'Submit'
}

return (
<form>

<label htmlFor={metadata.inputId}>
{metadata.fieldLabel}
</label>

<input
type ={metadata.type}
placeholder ={metadata.placeholder}
id ={metadata.inputId}
onChange ={e => setArtistName(e.target.value)}
/>

<button
type ="button"
onClick ={() => handleSubmit({artistName})}
>
{metadata.buttonText}
</button>

</form>
);
}
9 changes: 2 additions & 7 deletions src/components/Title/Title.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import Title from "./Title";
import "@testing-library/jest-dom";
import { title_test_title } from "./Title.testFunctions";

test("increments the count on click", async () => {
render(<Title />);
expect(screen.getByText('Harmonise')).toBeInTheDocument();
});
test("Displays the title 'Harmonise'", title_test_title);
11 changes: 11 additions & 0 deletions src/components/Title/Title.testFunctions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render, screen } from "@testing-library/react";
import Title from "./Title";

export const title_test_title: () => Promise<void> = async () => {

render(<Title />);
const text = screen.getByText('Harmonise')

expect(text).toBeInTheDocument();

};
16 changes: 7 additions & 9 deletions src/components/Title/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useState } from "react";

export default function Title() {

return (
<div>
Harmonise
</div>
);
}

const title = 'Harmonise'

return (

<>
{title}
</>

);
}
3 changes: 3 additions & 0 deletions src/functions/handleSubmit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function handleSubmit(formData: {}) {
// Data will be sent to the server here, thence to the database
}
1 change: 1 addition & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}