-
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 leung018/mc-12-edit-mc-set-page
- Loading branch information
Showing
13 changed files
with
243 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fireEvent, render } from '@testing-library/react' | ||
import { QuestionSetRepoFactory } from '../../../repo/question_set' | ||
import { QuestionSetEditorUIService } from './editor' | ||
|
||
describe('QuestionSetEditor', () => { | ||
it('should save question set', () => { | ||
const editorRepo = QuestionSetRepoFactory.createTestInstance() | ||
const { getByLabelText, getByText } = render( | ||
QuestionSetEditorUIService.createTestInstance({ | ||
editorRepo, | ||
}).getElement(), | ||
) | ||
const questionSetNameInput = getByLabelText('Question Set Name:') | ||
const questionInput = getByLabelText('Question 1:') | ||
|
||
const choice1Input = getByLabelText('Choice 1:') | ||
const isChoice1CorrectInput = getByLabelText('Choice 1 is correct answer') | ||
const isChoice1FixedPositionInput = getByLabelText( | ||
'Choice 1 is fixed position', | ||
) | ||
|
||
const choice2Input = getByLabelText('Choice 2:') | ||
|
||
fireEvent.change(questionSetNameInput, { target: { value: 'Test name' } }) | ||
fireEvent.change(questionInput, { target: { value: 'Am I handsome?' } }) | ||
fireEvent.change(choice1Input, { target: { value: 'True' } }) | ||
fireEvent.change(isChoice1CorrectInput, { target: { value: 'true' } }) | ||
fireEvent.change(isChoice1FixedPositionInput, { | ||
target: { value: 'true' }, | ||
}) | ||
|
||
fireEvent.change(choice2Input, { target: { value: 'False' } }) | ||
|
||
fireEvent.click(getByText('Save')) | ||
|
||
const actualQuestionSet = editorRepo.getQuestionSetByName('Test name') | ||
|
||
// TODO: Assert the question set is saved with expected values | ||
}) | ||
}) |
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,134 @@ | ||
import { | ||
QuestionSetRepo, | ||
QuestionSetRepoFactory, | ||
} from '../../../repo/question_set' | ||
|
||
export class QuestionSetEditorUIService { | ||
static create() { | ||
return new QuestionSetEditorUIService({ | ||
editorRepo: QuestionSetRepoFactory.createTestInstance(), // TODO: replace with real repo | ||
}) | ||
} | ||
|
||
static createTestInstance({ | ||
editorRepo = QuestionSetRepoFactory.createTestInstance(), | ||
}) { | ||
return new QuestionSetEditorUIService({ editorRepo }) | ||
} | ||
|
||
private editorRepo: QuestionSetRepo | ||
|
||
private constructor({ editorRepo }: { editorRepo: QuestionSetRepo }) { | ||
this.editorRepo = editorRepo | ||
} | ||
|
||
getElement() { | ||
return <QuestionSetEditor /> | ||
} | ||
} | ||
|
||
function QuestionSetEditor() { | ||
return ( | ||
<div className="container mx-auto p-4"> | ||
<div className="form-group"> | ||
<label htmlFor="question-set-name"> | ||
<h1 className="text-lg font-bold mb-2">Question Set Name:</h1> | ||
</label> | ||
<input | ||
type="text" | ||
id="question-set-name" | ||
className="border border-gray-300 px-2 py-1 w-full" | ||
/> | ||
</div> | ||
|
||
<div className="mb-8"> | ||
<label> | ||
<h2 className="text-lg font-bold mb-2">Question 1:</h2> | ||
<input | ||
type="text" | ||
className="border border-gray-300 px-2 py-1 w-full" | ||
/> | ||
</label> | ||
<div className="form-group"> | ||
<div className="grid grid-cols-5 gap-4"> | ||
<div className="col-span-3"></div> | ||
<div className="col-span-1 text-center">Correct Answer</div> | ||
<div className="col-span-1 text-center">Fixed Position</div> | ||
|
||
<div className="col-span-3"> | ||
<label> | ||
Choice 1: | ||
<input | ||
type="text" | ||
className="border border-gray-300 px-2 py-1 ml-2" | ||
/> | ||
</label> | ||
</div> | ||
<div className="col-span-1 flex items-center justify-center"> | ||
<input | ||
type="checkbox" | ||
className="mr-1" | ||
aria-label="Choice 1 is correct answer" | ||
/> | ||
</div> | ||
<div className="col-span-1 flex items-center justify-center"> | ||
<input | ||
type="checkbox" | ||
className="mr-1" | ||
aria-label="Choice 1 is fixed position" | ||
/> | ||
</div> | ||
{/* TODO: Refactor the below duplication */} | ||
<div className="col-span-3"> | ||
<label> | ||
Choice 2: | ||
<input | ||
type="text" | ||
className="border border-gray-300 px-2 py-1 ml-2" | ||
/> | ||
</label> | ||
</div> | ||
<div className="col-span-1 flex items-center justify-center"> | ||
<input | ||
type="checkbox" | ||
className="mr-1" | ||
aria-label="Choice 2 is correct answer" | ||
/> | ||
</div> | ||
<div className="col-span-1 flex items-center justify-center"> | ||
<input | ||
type="checkbox" | ||
className="mr-1" | ||
aria-label="Choice 2 is fixed position" | ||
/> | ||
</div> | ||
|
||
<div className="col-span-1"> | ||
<button | ||
type="button" | ||
className="bg-blue-500 text-white px-4 py-2 rounded" | ||
> | ||
Add Choice | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<button | ||
type="button" | ||
className="bg-blue-500 text-white px-4 py-2 rounded" | ||
> | ||
Add Question | ||
</button> | ||
|
||
<div className="flex items-center justify-center w-full"> | ||
<button | ||
type="button" | ||
className="bg-green-500 text-white px-4 py-2 rounded" | ||
> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
) | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/app/components/mc/display.tsx → src/app/components/mc/quiz.tsx
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 @@ | ||
import { QuestionSetEditorUIService } from '../../components/mc/editor' | ||
|
||
export default function QuestionSetEditorPage() { | ||
return QuestionSetEditorUIService.create().getElement() | ||
} |
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
File renamed without changes.
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
File renamed without changes.
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,9 @@ | ||
import { NewVersionMultipleChoice } from './mc' | ||
|
||
export interface QuestionSet { | ||
name: string | ||
questions: ReadonlyArray<{ | ||
title: string | ||
mc: NewVersionMultipleChoice | ||
}> | ||
} |
File renamed without changes.
File renamed without changes.
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,20 @@ | ||
import { QuestionSet } from '../model/question_set' | ||
|
||
export interface QuestionSetRepo { | ||
getQuestionSetByName(questionSetName: string): QuestionSet | ||
} | ||
|
||
export class QuestionSetRepoFactory { | ||
static createTestInstance(): QuestionSetRepo { | ||
return new InMemoryQuestionSetRepo() | ||
} | ||
} | ||
|
||
class InMemoryQuestionSetRepo implements QuestionSetRepo { | ||
getQuestionSetByName(questionSetName: string): QuestionSet { | ||
return { | ||
name: 'Sample Question Set', | ||
questions: [], | ||
} | ||
} | ||
} |