forked from UD-CISC275-S22/tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from mattnadar/solved-state
Solved state
- Loading branch information
Showing
15 changed files
with
712 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { ChangeType } from "./ChangeType"; | ||
|
||
describe("ChangeType Component tests", () => { | ||
beforeEach(() => { | ||
render(<ChangeType />); | ||
}); | ||
test("The initial type is Short Answer", () => { | ||
// We use `getByText` because the text MUST be there | ||
const typeText = screen.getByText(/Short Answer/i); | ||
expect(typeText).toBeInTheDocument(); | ||
}); | ||
test("The initial type is not Multiple Choice", () => { | ||
// We use `queryByText` because the text might not be there | ||
const typeText = screen.queryByText(/Multiple Choice/i); | ||
expect(typeText).toBeNull(); | ||
}); | ||
|
||
test("There is a button labeled Change Type", () => { | ||
const changeTypeButton = screen.getByRole("button", { | ||
name: /Change Type/i | ||
}); | ||
expect(changeTypeButton).toBeInTheDocument(); | ||
}); | ||
|
||
test("Clicking the button changes the type.", () => { | ||
const changeTypeButton = screen.getByRole("button", { | ||
name: /Change Type/i | ||
}); | ||
changeTypeButton.click(); | ||
// Should be Multiple Choice | ||
const typeTextMC = screen.getByText(/Multiple Choice/i); | ||
expect(typeTextMC).toBeInTheDocument(); | ||
// Should NOT be Short Answer | ||
const typeTextSA = screen.queryByText(/Short Answer/i); | ||
expect(typeTextSA).toBeNull(); | ||
}); | ||
|
||
test("Clicking the button twice keeps the type the same.", () => { | ||
const changeTypeButton = screen.getByRole("button", { | ||
name: /Change Type/i | ||
}); | ||
changeTypeButton.click(); | ||
changeTypeButton.click(); | ||
// Should be Short Answer | ||
const typeTextSA = screen.getByText(/Short Answer/i); | ||
expect(typeTextSA).toBeInTheDocument(); | ||
// Should NOT be Multiple Choice | ||
const typeTextMC = screen.queryByText(/Multiple Choice/i); | ||
expect(typeTextMC).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { useState } from "react"; | ||
import { Button } from "react-bootstrap"; | ||
import { QuestionType } from "../interfaces/question"; | ||
|
||
export function ChangeType(): JSX.Element { | ||
const [questionType, setQuestionType] = useState<QuestionType>( | ||
"short_answer_question" | ||
); | ||
const changeType = () => { | ||
setQuestionType((oldType) => | ||
oldType === "multiple_choice_question" | ||
? "short_answer_question" | ||
: "multiple_choice_question" | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Button onClick={changeType}>Change Type</Button> | ||
{questionType === "multiple_choice_question" && ( | ||
<p>Multiple Choice</p> | ||
)} | ||
{questionType === "short_answer_question" && <p>Short Answer</p>} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.