Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
986b28a
First stab at questions
acbart Feb 2, 2022
2c852d6
Move Question interface to separate file
acbart Feb 6, 2022
dc3662a
Create answer interface
acbart Feb 8, 2022
51221ee
First stab at nested tasks
acbart Feb 8, 2022
3a793cc
Document Question interface
acbart Feb 9, 2022
5c39a97
Expand questions test data
acbart Feb 9, 2022
6ae0b6f
Add a little hint for a tough one
acbart Feb 9, 2022
b1bbbc8
Nested tests (phew)
acbart Feb 9, 2022
ab9bfb5
Basic starter files for components
acbart Feb 9, 2022
9765863
Another extra paren error
acbart Feb 9, 2022
d6c10cd
Merge branch 'main' of https://github.com/UD-CISC275-S22/react-typesc…
acbart Feb 13, 2022
c0bbc39
Updated, complete tests for all state components
acbart Feb 13, 2022
eb40f3e
Forgot task record for state
acbart Feb 19, 2022
6669ffa
First draft of components subtasks
acbart Feb 19, 2022
562f306
Another subtask, ChooseTeam
acbart Feb 24, 2022
4a34f5f
Oops order out of operations
acbart Feb 24, 2022
7327f4c
Add headers to each subtask
acbart Feb 24, 2022
cf7c212
Make testing easier for these components
acbart Feb 24, 2022
08feee1
Ugh this component is stupid, let's just forget about it for now
acbart Feb 24, 2022
89053a4
Provide the tests for the bad components
acbart Feb 24, 2022
41387d3
First stab at form task components
acbart Feb 25, 2022
1b03faf
Provide tests, change addQuestion to changeColor
acbart Feb 27, 2022
43b41ec
Fix entering blank text for GiveAttempts
acbart Mar 10, 2022
7a20734
Include json test command here
acbart Aug 24, 2024
3660252
First stab at questions
acbart Feb 2, 2022
09d3d4f
Move Question interface to separate file
acbart Feb 6, 2022
9a24024
Create answer interface
acbart Feb 8, 2022
879fe17
First stab at nested tasks
acbart Feb 8, 2022
4d29d21
Document Question interface
acbart Feb 9, 2022
d71d9fc
Expand questions test data
acbart Feb 9, 2022
c955718
Add a little hint for a tough one
acbart Feb 9, 2022
c574699
Nested tests (phew)
acbart Feb 9, 2022
a368ad0
Forgot the task record!
acbart Feb 19, 2022
304184e
Fix typo in editOption test, and missing return type for editOption
acbart Mar 1, 2022
1b76b80
Fix formatting
acbart Aug 24, 2024
23314f3
update point values for tests
acbart Aug 24, 2024
82faacc
Fix react return value
acbart Aug 24, 2024
cc7d4db
Update react tests to use async
acbart Aug 24, 2024
c419dc9
Fix linting
acbart Aug 24, 2024
444b03b
Merge branch 'task-state' into task-components
acbart Aug 24, 2024
c1aab28
Merge branch 'update-branches' into task-components
acbart Aug 24, 2024
50a9c85
Update for new react
acbart Aug 24, 2024
28ee8d2
Merge branch 'task-components' into task-forms
acbart Aug 24, 2024
084abb4
Update the code for new version of react
acbart Aug 24, 2024
c95dc0f
This one too
acbart Aug 24, 2024
3119c0f
Add in points
acbart Aug 24, 2024
8f02b0a
Merge remote-tracking branch 'upstream/task-nested'
ariudel Mar 3, 2026
ffc6a37
Working on nested task
ariudel Mar 3, 2026
392e5c2
fixed the rest of nested
ariudel Mar 3, 2026
14024e0
Fix objects.ts
ariudel Mar 3, 2026
3cf1e36
Merge task-state
ariudel Mar 5, 2026
0493838
Restore nested/objects solutions from solved-nested
ariudel Mar 5, 2026
cfa3960
Completed State task
ariudel Mar 6, 2026
ff27aa8
Fixed lint error
ariudel Mar 6, 2026
fd9008e
Merging
ariudel Mar 7, 2026
85eddc2
Finished for now
ariudel Mar 7, 2026
afae0c1
Completed components
ariudel Mar 7, 2026
df22276
resolved merge conflict
ariudel Mar 16, 2026
06f29b5
Finished components
ariudel Mar 16, 2026
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
50 changes: 50 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"settings": {
"react": {
"version": "detect"
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"no-extra-parens": [
"warn",
"all",
{
"nestedBinaryExpressions": false,
"returnAssign": false,
"enforceForArrowConditionals": false,
"ignoreJSX": "all"
}
],
"brace-style": ["error", "1tbs"],
"indent": ["error", 4],
"quotes": ["error", "double"],
"semi": ["error", "always"]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"test:cov": "react-scripts test --coverage --watchAll",
"test:json": "react-scripts test --json --watchAll=false --outputFile jest-output.json --coverage",
"eject": "react-scripts eject",
"lint": "eslint ./src --ext .tsx --ext .ts --max-warnings 0",
"eslint-output": "eslint-output ./src --ext .tsx --ext .ts --max-warnings 0",
Expand Down
5 changes: 5 additions & 0 deletions public/tasks/task-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - Components

Version: 0.0.1

Fix some components that are using state incorrectly.
5 changes: 5 additions & 0 deletions public/tasks/task-nested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - Nested

Version: 0.0.1

Implement functions that work with nested arrays and objects immutably.
5 changes: 5 additions & 0 deletions public/tasks/task-objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - Objects

Version: 0.0.1

Implement functions that work with objects immutably.
5 changes: 5 additions & 0 deletions public/tasks/task-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - State

Version: 0.0.1

Create some new components that have React State.
52 changes: 48 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,60 @@
import React from "react";
import "./App.css";
import { ChangeType } from "./components/ChangeType";
import { RevealAnswer } from "./components/RevealAnswer";
import { StartAttempt } from "./components/StartAttempt";
import { TwoDice } from "./components/TwoDice";
import { CycleHoliday } from "./components/CycleHoliday";
import { Counter } from "./components/Counter";
import { DoubleHalf } from "./bad-components/DoubleHalf";
import { ColoredBox } from "./bad-components/ColoredBox";
import { ShoveBox } from "./bad-components/ShoveBox";
import { ChooseTeam } from "./bad-components/ChooseTeam";
import { CheckAnswer } from "./form-components/CheckAnswer";
import { GiveAttempts } from "./form-components/GiveAttempts";
import { EditMode } from "./form-components/EditMode";
import { MultipleChoiceQuestion } from "./form-components/MultipleChoiceQuestion";
import { ChangeColor } from "./form-components/ChangeColor";

function App(): React.JSX.Element {
return (
<div className="App">
<header className="App-header">
UD CISC275 with React Hooks and TypeScript
</header>
<p>
Edit <code>src/App.tsx</code> and save. This page will
automatically reload.
</p>
<hr></hr>
<DoubleHalf></DoubleHalf>
<hr></hr>
<CheckAnswer expectedAnswer="42"></CheckAnswer>
<hr></hr>
<GiveAttempts></GiveAttempts>
<hr></hr>
<EditMode></EditMode>
<hr></hr>
<ChangeColor></ChangeColor>
<hr></hr>
<MultipleChoiceQuestion
options={["a", "b", "c"]}
expectedAnswer="b"
></MultipleChoiceQuestion>
<hr></hr>
<ChooseTeam></ChooseTeam>
<hr></hr>
<ColoredBox></ColoredBox>
<hr></hr>
<ShoveBox></ShoveBox>
<hr></hr>
<Counter></Counter>
<hr />
<RevealAnswer></RevealAnswer>
<hr />
<StartAttempt></StartAttempt>
<hr />
<TwoDice></TwoDice>
<hr />
<ChangeType></ChangeType>
<hr />
<CycleHoliday></CycleHoliday>
</div>
);
}
Expand Down
81 changes: 81 additions & 0 deletions src/bad-components/ChooseTeam.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { act } from "react";
import { render, screen } from "@testing-library/react";
import { ChooseTeam } from "./ChooseTeam";

describe("ChooseTeam Component tests", () => {
beforeEach(() => {
render(<ChooseTeam />);
});
test("(2 pts) The initial team is empty", () => {
const currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(0);
});
test("(2 pts) There are 7 buttons.", () => {
const adders = screen.queryAllByRole("button");
expect(adders).toHaveLength(7);
});
test("(2 pts) Clicking first team member works", async () => {
const first = screen.queryAllByRole("button")[0];
await act(async () => {
first.click();
});
const currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(1);
expect(currentTeam[0].textContent).toEqual(first.textContent);
});
test("(2 pts) Clicking the third team member works", async () => {
const third = screen.queryAllByRole("button")[2];
await act(async () => {
third.click();
});
const currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(1);
expect(currentTeam[0].textContent).toEqual(third.textContent);
});
test("(2 pts) Clicking three team members works", async () => {
const [, second, third, , fifth] = screen.queryAllByRole("button");
await act(async () => {
third.click();
});
await act(async () => {
second.click();
});
await act(async () => {
fifth.click();
});
const currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(3);
expect(currentTeam[0].textContent).toEqual(third.textContent);
expect(currentTeam[1].textContent).toEqual(second.textContent);
expect(currentTeam[2].textContent).toEqual(fifth.textContent);
});
test("(2 pts) Clearing the team works", async () => {
const [, second, third, fourth, fifth, , clear] =
screen.queryAllByRole("button");
await act(async () => {
third.click();
});
await act(async () => {
second.click();
});
await act(async () => {
fifth.click();
});
let currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(3);
expect(currentTeam[0].textContent).toEqual(third.textContent);
expect(currentTeam[1].textContent).toEqual(second.textContent);
expect(currentTeam[2].textContent).toEqual(fifth.textContent);
await act(async () => {
clear.click();
});
currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(0);
await act(async () => {
fourth.click();
});
currentTeam = screen.queryAllByRole("listitem");
expect(currentTeam).toHaveLength(1);
expect(currentTeam[0].textContent).toEqual(fourth.textContent);
});
});
56 changes: 56 additions & 0 deletions src/bad-components/ChooseTeam.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useState } from "react";
import { Button, Row, Col } from "react-bootstrap";

const PEOPLE = [
"Alan Turing",
"Grace Hopper",
"Ada Lovelace",
"Charles Babbage",
"Barbara Liskov",
"Margaret Hamilton",
];

export function ChooseTeam(): React.JSX.Element {
const [allOptions] = useState<string[]>(PEOPLE);
const [team, setTeam] = useState<string[]>([]);

function chooseMember(newMember: string) {
if (!team.includes(newMember)) {
setTeam([...team, newMember]);
}
}

function clearTeam() {
setTeam([]);
}

return (
<div>
<h3>Choose Team</h3>
<Row>
<Col>
{allOptions.map((option: string) => (
<div key={option} style={{ marginBottom: "4px" }}>
Add{" "}
<Button
onClick={() => {
chooseMember(option);
}}
size="sm"
>
{option}
</Button>
</div>
))}
</Col>
<Col>
<strong>Team:</strong>
{team.map((member: string) => (
<li key={member}>{member}</li>
))}
<Button onClick={clearTeam}>Clear Team</Button>
</Col>
</Row>
</div>
);
}
37 changes: 37 additions & 0 deletions src/bad-components/ColoredBox.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { act } from "react";
import { render, screen } from "@testing-library/react";
import { ColoredBox } from "./ColoredBox";

describe("ColoredBox Component tests", () => {
beforeEach(() => {
render(<ColoredBox />);
});
test("(2 pts) The ColoredBox is initially red.", () => {
const box = screen.getByTestId("colored-box");
expect(box).toHaveStyle({ backgroundColor: "red" });
});
test("(2 pts) There is a button", () => {
expect(screen.getByRole("button")).toBeInTheDocument();
});
test("(2 pts) Clicking the button advances the color.", async () => {
const nextColor = screen.getByRole("button");
await act(async () => {
nextColor.click();
});
expect(screen.getByTestId("colored-box")).toHaveStyle({
backgroundColor: "blue",
});
await act(async () => {
nextColor.click();
});
expect(screen.getByTestId("colored-box")).toHaveStyle({
backgroundColor: "green",
});
await act(async () => {
nextColor.click();
});
expect(screen.getByTestId("colored-box")).toHaveStyle({
backgroundColor: "red",
});
});
});
61 changes: 61 additions & 0 deletions src/bad-components/ColoredBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useState } from "react";
import { Button } from "react-bootstrap";

export const COLORS = ["red", "blue", "green"];
const DEFAULT_COLOR_INDEX = 0;

function ChangeColor({
colorIndex,
setColorIndex,
}: {
colorIndex: number;
setColorIndex: (n: number) => void;
}): React.JSX.Element {
return (
<Button
onClick={() => {
setColorIndex((1 + colorIndex) % COLORS.length);
}}
>
Next Color
</Button>
);
}

function ColorPreview({
colorIndex,
}: {
colorIndex: number;
}): React.JSX.Element {
return (
<div
data-testid="colored-box"
style={{
width: "50px",
height: "50px",
backgroundColor: COLORS[colorIndex],
display: "inline-block",
verticalAlign: "bottom",
marginLeft: "5px",
}}
></div>
);
}

export function ColoredBox(): React.JSX.Element {
const [colorIndex, setColorIndex] = useState<number>(DEFAULT_COLOR_INDEX);

return (
<div>
<h3>Colored Box</h3>
<span>The current color is: {COLORS[colorIndex]}</span>
<div>
<ChangeColor
colorIndex={colorIndex}
setColorIndex={setColorIndex}
></ChangeColor>
<ColorPreview colorIndex={colorIndex}></ColorPreview>
</div>
</div>
);
}
Loading