Skip to content

Commit

Permalink
orphaned complete answers recording card
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Aug 28, 2023
1 parent 91b932b commit 371daad
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/src/components/home/answer-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function AnswerList(props: {
answers: Answer[];
questions: QuestionEdits[];
expandLists: boolean;
subjectId: string;
onRecordAll: () => void;
onRecordOne: (question: QuestionEdits) => void;
onEditQuestion: (question: QuestionEdits) => void;
Expand All @@ -39,6 +40,7 @@ function AnswerList(props: {
classes,
header,
answers,
subjectId,
onRecordAll,
onRecordOne,
onEditQuestion,
Expand Down Expand Up @@ -86,6 +88,7 @@ function AnswerList(props: {
{onAddQuestion ? (
<Button
data-cy="add-question"
disabled={!subjectId}
color="primary"
variant="outlined"
startIcon={<AddIcon />}
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/home/recording-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default function RecordingBlockItem(props: {
<div style={{ flex: "auto" }}>
<AnswerList
classes={classes}
subjectId={block.subject}
mentorId={props.mentorId}
header="Complete"
answers={complete}
Expand All @@ -89,6 +90,7 @@ export default function RecordingBlockItem(props: {
/>
<AnswerList
classes={classes}
subjectId={block.subject}
header="Incomplete"
answers={incomplete}
questions={questionEdits}
Expand Down
29 changes: 29 additions & 0 deletions client/src/hooks/graphql/use-with-review-answer-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,34 @@ export function useWithReviewAnswerState(
});
}
});

// Add a block for complete answers that are not in any subject
const _allSubjectsQuestions = mentorSubjects.map((s) =>
s.questions.map((sq) => sq.question)
);
const allSubjectsQuestionIds: string[] = ([] as string[]).concat.apply(
[],
_allSubjectsQuestions
);
const answersNotInSubjects = mentorAnswers.filter(
(a) =>
isAnswerComplete(a, undefined, mentorType) &&
!allSubjectsQuestionIds.find((qs) => qs.includes(a.question))
);
const completeQuestionsNotInSubjects = answersNotInSubjects.map(
(a) => a.question
);
if (completeQuestionsNotInSubjects.length > 0) {
_blocks.push({
subject: "",
category: undefined,
name: "Orphaned Complete Answers",
description:
"Complete answers that do not belong to any subject. This may be the result of a subject being deleted.",
questions: completeQuestionsNotInSubjects,
});
}

// Sort blocks by config priority
const subjectPriority = configState.config.subjectRecordPriority;
const prioritizedBlocks = _blocks.filter((block) =>
Expand Down Expand Up @@ -234,6 +262,7 @@ export function useWithReviewAnswerState(
total: mentorAnswers.length,
});
}

setBlocks(_blocks);
}, [
mentorSubjects,
Expand Down
8 changes: 8 additions & 0 deletions cypress/cypress/fixtures/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ export const questions: Question[] = [
name: null,
paraphrases: [],
},
{
_id: "Q5_5_5",
clientId: "C_A5_5_5",
question: "This question does not belong to any subject",
type: QuestionType.QUESTION,
name: null,
paraphrases: [],
},
];

export default questions;
39 changes: 38 additions & 1 deletion cypress/cypress/integration/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import clint from "../fixtures/mentor/clint_home";
import clint3 from "../fixtures/mentor/clint_setup3";
import clint12 from "../fixtures/mentor/clint_setup12";
import { login as loginDefault } from "../fixtures/login";
import { UserRole } from "../support/types";
import { QuestionType, Status, UserRole } from "../support/types";

export function taskListBuild(progressForAllTasks) {
return {
Expand Down Expand Up @@ -298,4 +298,41 @@ describe("Index page", () => {
assert($el, "/subjects");
});
});

it("answers that do not belong to any subject exist in their own recording card", () => {
cyMockDefault(cy, {
mentor: {
...clint,
answers: [
...clint.answers,
{
previousVersions: [],
_id: "A5_5_5",
question: {
_id: "Q5_5_5",
clientId: "C_A5_5_5",
question: "This question does not belong to any subject",
type: QuestionType.QUESTION,
name: null,
paraphrases: [],
},
transcript: "Test transcription.",
status: Status.COMPLETE,
},
],
},
});
cy.visit("/");
cy.get("[data-cy=setup-no]").click();
cy.get("[data-cy=block-4]").within(() => {
cy.contains("Orphaned Complete Answers");
cy.get("[data-cy=answers-Complete]").within(() => {
cy.get("[data-cy=expand-btn]").click();
cy.get("[data-cy=answer-list]").within(() => {
cy.contains("This question does not belong to any subject");
});
});
cy.get("[data-cy=add-question]").should("be.disabled");
});
});
});

0 comments on commit 371daad

Please sign in to comment.