-
Notifications
You must be signed in to change notification settings - Fork 37
fix(app): require review notes to contain readable text #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tonylam0
merged 2 commits into
bluelearn-org:main
from
GamingDragonwastaken:fix/require-meaningful-review-notes
Aug 31, 2026
+108
−13
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,75 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| hasMeaningfulText, | ||
| validateReviewDecision, | ||
| } from "@/lib/reviewValidation"; | ||
|
|
||
| const rejection = (notes: string) => ({ | ||
| decision: "reject", | ||
| notes, | ||
| reasons: ["inaccurate"], | ||
| }); | ||
|
|
||
| describe("hasMeaningfulText", () => { | ||
| it("accepts letters and numbers in any script", () => { | ||
| expect(hasMeaningfulText("Needs a worked example.")).toBe(true); | ||
| expect(hasMeaningfulText("需要一个例子")).toBe(true); | ||
| expect(hasMeaningfulText("يحتاج إلى مثال")).toBe(true); | ||
| expect(hasMeaningfulText("Нужен пример")).toBe(true); | ||
| expect(hasMeaningfulText("42")).toBe(true); | ||
| }); | ||
|
|
||
| it("rejects input with no letters or numbers", () => { | ||
| expect(hasMeaningfulText("")).toBe(false); | ||
| expect(hasMeaningfulText(" ")).toBe(false); | ||
| expect(hasMeaningfulText("\t\n")).toBe(false); | ||
| expect(hasMeaningfulText("...")).toBe(false); | ||
| expect(hasMeaningfulText("-")).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("validateReviewDecision", () => { | ||
| it("asks for a decision before anything else", () => { | ||
| expect( | ||
| validateReviewDecision({ decision: "", notes: "", reasons: [] }) | ||
| ).toBe("Choose approve or reject before submitting"); | ||
| }); | ||
|
|
||
| it("lets an approval through without notes or reasons", () => { | ||
| expect( | ||
| validateReviewDecision({ decision: "approve", notes: "", reasons: [] }) | ||
| ).toBe(""); | ||
| }); | ||
|
|
||
| it("lets a complete rejection through", () => { | ||
| expect(validateReviewDecision(rejection("Missing prerequisites."))).toBe( | ||
| "" | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects a note with no readable text", () => { | ||
| expect(validateReviewDecision(rejection(" "))).toBe( | ||
| "Rejections require a note" | ||
| ); | ||
| expect(validateReviewDecision(rejection("..."))).toBe( | ||
| "Rejections require a note" | ||
| ); | ||
| }); | ||
|
|
||
| it("still requires at least one reason", () => { | ||
| expect( | ||
| validateReviewDecision({ | ||
| decision: "reject", | ||
| notes: "Needs work.", | ||
| reasons: [], | ||
| }) | ||
| ).toBe("Rejections require at least one reason"); | ||
| }); | ||
|
|
||
| it("reports both problems together", () => { | ||
| expect( | ||
| validateReviewDecision({ decision: "reject", notes: " ", reasons: [] }) | ||
| ).toBe("Rejections require at least one reason and a note"); | ||
| }); | ||
| }); |
This file contains hidden or 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,31 @@ | ||
| export type ReviewDecisionInput = { | ||
| decision: string; | ||
| notes: string; | ||
| reasons: Array<string>; | ||
| }; | ||
|
|
||
| // Any letter or number in any script counts, so notes are not limited to Latin | ||
| // characters. Whitespace and bare punctuation are not a note. | ||
| const MEANINGFUL_TEXT = /[\p{L}\p{N}]/u; | ||
|
|
||
| export function hasMeaningfulText(value: string): boolean { | ||
| return MEANINGFUL_TEXT.test(value); | ||
| } | ||
|
|
||
| /** | ||
| * Describes what is stopping a decision from being submitted, or returns an | ||
| * empty string when it is ready to go. | ||
| */ | ||
| export function validateReviewDecision(review: ReviewDecisionInput): string { | ||
| if (review.decision === "") | ||
| return "Choose approve or reject before submitting"; | ||
| if (review.decision === "approve") return ""; | ||
|
|
||
| const missing = []; | ||
| if (review.reasons.length === 0) missing.push("at least one reason"); | ||
| if (!hasMeaningfulText(review.notes)) missing.push("a note"); | ||
|
|
||
| return missing.length === 0 | ||
| ? "" | ||
| : `Rejections require ${missing.join(" and ")}`; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second paragraph is not required in this comment because it details bug history rather than something a future reader may need. Shorten this comment to only include the current use of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done — removed in 99d6c0e.