Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 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
7a20734
Include json test command here
acbart Aug 24, 2024
c2e556d
First stab at questions
acbart Feb 2, 2022
406ffb2
Move Question interface to separate file
acbart Feb 6, 2022
9b9adb6
Fix formatting
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
5247639
Merge branch 'main' into task-components
greglnelson Sep 8, 2024
67edb6d
Merge branch 'main' into task-nested
greglnelson Sep 8, 2024
5a7921b
Merge branch 'main' into task-objects
greglnelson Sep 8, 2024
974fb09
Merge so 2024 works
greglnelson Oct 17, 2024
ae19e0f
reduced workload by half
greglnelson Oct 17, 2024
f2cd1ef
remove cycleholiday and startattempt
greglnelson Oct 26, 2024
f9ec33b
Merge branch 'task-nested' into task-state
greglnelson Oct 26, 2024
f4e8bec
Add missing function that was in a removed problem
greglnelson Oct 26, 2024
a179ca9
Remove removed problems from App.tsx
greglnelson Oct 26, 2024
e40378e
remove shovebox
greglnelson Oct 26, 2024
d9e6d0f
Merge so students dont have to, merge branch 'task-state' into task-c…
greglnelson Oct 26, 2024
0c840d7
fix a potential bug with toBeCalled, investigate more next year
greglnelson Oct 27, 2024
ff703b5
Update TwoDice.test.tsx
greglnelson Oct 31, 2024
73ef19c
remove old file that got in there accidentally and causes linting pro…
greglnelson Nov 4, 2024
111807e
Merge branch 'gh-task-state' into task-components
greglnelson Nov 4, 2024
6e31832
Update deploy.yml
TSchotter Feb 11, 2025
41b9e93
Update deploy.yml
TSchotter Feb 11, 2025
566436c
revert changes
TSchotter Feb 11, 2025
2ee502d
Update deploy.yml
TSchotter Feb 11, 2025
26b9f36
Update deploy.yml
TSchotter Feb 11, 2025
b1583a1
Merge pull request #55 from TSchotter/TSchotter-patch-1
TSchotter Feb 11, 2025
94c95d1
Merge remote-tracking branch 'upstream/task-nested' into solved-nested
MoodyMakai Mar 11, 2025
c37d7f6
commit
MoodyMakai Mar 11, 2025
8e0858d
Nested Chapter complete
MoodyMakai Mar 12, 2025
b2ec4fa
Add back in files to match interactive textbook
TSchotter Mar 30, 2025
42058d9
Merge remote-tracking branch 'upstream/task-state' into solved-state
MoodyMakai Apr 1, 2025
2666403
Feat(State): SolvedState Commit
MoodyMakai Apr 2, 2025
c893bcd
Merge remote-tracking branch 'upstream/task-components' into solved-c…
MoodyMakai Apr 13, 2025
ecd5890
fix(inf): bad components fixed
MoodyMakai Apr 13, 2025
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
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- id: get-repo-values
Expand All @@ -39,7 +39,7 @@ jobs:
url=https://$(echo "${{github.repository}}" | sed "s/\//.github.io\//")
echo "url=$url" >> $GITHUB_OUTPUT
- name: Update package.json homepage
uses: jossef/action-set-json-field@v1
uses: jossef/action-set-json-field@v2.1
with:
file: package.json
field: homepage
Expand Down Expand Up @@ -134,14 +134,14 @@ jobs:
# echo "</body></html>" >> ./dist/index.html
# Deploy
- name: Setup Pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v5
if: ${{ !cancelled() }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
if: ${{ !cancelled() }}
with:
path: "dist/"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
if: ${{ !cancelled() }}
123 changes: 57 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

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.
25 changes: 21 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import React from "react";
import "./App.css";
import { ChangeType } from "./components/ChangeType";
import { RevealAnswer } from "./components/RevealAnswer";
import { TwoDice } from "./components/TwoDice";
import { Counter } from "./components/Counter";
import { DoubleHalf } from "./bad-components/DoubleHalf";
import { ColoredBox } from "./bad-components/ColoredBox";
import { ChooseTeam } from "./bad-components/ChooseTeam";

function App(): React.JSX.Element {
return (
<div className="App">
<header className="App-header">
UM COS420 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>
<ChooseTeam></ChooseTeam>
<hr></hr>
<ColoredBox></ColoredBox>
<hr></hr>
<Counter></Counter>
<hr />
<RevealAnswer></RevealAnswer>
<hr />
<TwoDice></TwoDice>
<hr />
<ChangeType></ChangeType>
</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>
<ul>
{team.map((member: string) => (
<li key={member}>{member}</li>
))}
</ul>
<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: (index: number) => void;
}): React.JSX.Element {
return (
<Button
onClick={() => {
setColorIndex((colorIndex + 1) % 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}
/>
<ColorPreview colorIndex={colorIndex} />
</div>
</div>
);
}
Loading