Skip to content
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

refactor: Separate business logic from user interface code #751

Merged
merged 68 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
286b2e7
First commit
ronzulu Aug 30, 2023
c6349c5
This doesn't build yet
ronzulu Aug 31, 2023
75bd952
Something
ronzulu Sep 1, 2023
8f62fec
Something
ronzulu Sep 1, 2023
6705092
Something
ronzulu Sep 2, 2023
2e8e335
Something
ronzulu Sep 3, 2023
a458f02
Something
ronzulu Sep 3, 2023
386214e
Something
ronzulu Sep 5, 2023
cda0aa6
Something
ronzulu Sep 6, 2023
4f23f1e
Something
ronzulu Sep 6, 2023
565383e
Something
ronzulu Sep 7, 2023
256bfe6
Something
ronzulu Sep 7, 2023
1a33ad2
Something
ronzulu Sep 8, 2023
0a524fa
Something
ronzulu Sep 8, 2023
d379897
Something
ronzulu Sep 8, 2023
a6794ee
Something
ronzulu Sep 9, 2023
bbc8514
Something
ronzulu Sep 11, 2023
82ea18a
Something
ronzulu Sep 11, 2023
b8a9897
Something
ronzulu Sep 11, 2023
79b2409
Something
ronzulu Sep 11, 2023
0613ff9
Something
ronzulu Sep 11, 2023
43985e5
Something
ronzulu Sep 12, 2023
b0246bc
Something
ronzulu Sep 12, 2023
cd5ef22
Something
ronzulu Sep 12, 2023
b017de3
Something
ronzulu Sep 12, 2023
4a4482d
Something
ronzulu Sep 12, 2023
c44fc27
Something
ronzulu Sep 13, 2023
b5cc80b
Something
ronzulu Sep 13, 2023
cac7876
Something
ronzulu Sep 13, 2023
b2fad64
Something
ronzulu Sep 13, 2023
d38382d
Something
ronzulu Sep 13, 2023
8e663c8
Something
ronzulu Sep 13, 2023
ace8679
Something
ronzulu Sep 14, 2023
02e3cf2
Something
ronzulu Sep 15, 2023
6a92397
Something
ronzulu Sep 15, 2023
e4ea4e9
Something
ronzulu Sep 15, 2023
b4d87e1
Something
ronzulu Sep 15, 2023
4252e10
Something
ronzulu Sep 17, 2023
3ca7486
Something
ronzulu Sep 18, 2023
1d7bfd4
Something
ronzulu Sep 19, 2023
4196b44
Something
ronzulu Sep 19, 2023
1c0c677
Something
ronzulu Sep 19, 2023
4de04c2
Something
ronzulu Sep 19, 2023
7140e62
Something
ronzulu Sep 19, 2023
58bf273
Added support for burySiblingCards
ronzulu Sep 21, 2023
25c929e
Fixed the card count displayed on the status bar
ronzulu Sep 22, 2023
a2cf659
Minor
ronzulu Sep 22, 2023
a1ffac6
Minor
ronzulu Sep 22, 2023
1242a9b
Refactoring in preparation for random DeckTreeIter
ronzulu Sep 23, 2023
e0e08c0
Support random sequencing of cards during review
ronzulu Sep 24, 2023
c90864a
Fixed statistics charts
ronzulu Sep 25, 2023
d50af7e
after npm run format
ronzulu Sep 25, 2023
67c4f03
Code for updating question text made resilient to whitespace differences
ronzulu Sep 28, 2023
a20b585
Added more test cases
ronzulu Sep 28, 2023
1dfdbc6
Added test case
ronzulu Sep 28, 2023
0f48611
Fixes for certain cases of whitespace following a question's topic tag
ronzulu Sep 30, 2023
273bd79
npm run format; update version in manifest.json
ronzulu Sep 30, 2023
c9710b4
Support the Enter key on the numeric keypad in the shortcuts #706
ronzulu Oct 1, 2023
8daa90b
In flashcard modal, allow user to click across entire tree item recta…
ronzulu Oct 1, 2023
3ee88b3
npm run format; temporary filename changes
ronzulu Oct 3, 2023
5cb9d3a
Updated formatting for lint, file rename
ronzulu Oct 3, 2023
11c0a7a
fix issues reported by pnpm lint
ronzulu Oct 4, 2023
3ecdb92
Restored version number to "1.10.1"
ronzulu Oct 4, 2023
8cc95c8
Restored pnpm-lock.yaml from version 1.10.1
ronzulu Oct 4, 2023
51de7bf
Updated change log to reference #706, and #709
ronzulu Oct 4, 2023
4abae80
Fixing capitalization of "Note.ts" (step 1)
ronzulu Oct 4, 2023
6337f78
Fixing capitalization of "Note.ts" step #2
ronzulu Oct 4, 2023
6794686
Reduced collectCoverageFrom to subset of files with 100% code coverage
ronzulu Oct 4, 2023
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
Prev Previous commit
Next Next commit
Something
  • Loading branch information
ronzulu committed Sep 1, 2023
commit 8f62fec4b7c5de06132d99f2e76779e631f333d1
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
},
moduleFileExtensions: ["js", "jsx", "ts", "tsx", "json", "node", "d.ts"],
roots: ["<rootDir>/src/", "<rootDir>/tests/unit/"],
collectCoverageFrom: ["src/**/lang/*.ts", "src/parser.ts", "src/scheduling.ts", "utils.ts"],
collectCoverageFrom: ["src/**/lang/*.ts", "src/parser.ts", "src/scheduling.ts", "utils.ts", "src/question-type.ts"],
coveragePathIgnorePatterns: [
"/node_modules/",
"src/lang/locale/",
Expand Down
17 changes: 13 additions & 4 deletions src/question-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class QuestionType_Cloze implements IQuestionTypeHandler {
if (a.index > b.index) {
return 1;
}
// What is unit test to cover following statement; otherwise jest please ignore
return 0;
});

Expand All @@ -110,7 +111,7 @@ class QuestionType_Cloze implements IQuestionTypeHandler {
deletionEnd: number = deletionStart + m[0].length;
front =
questionText.substring(0, deletionStart) +
"<span style='color:#2196f3'>[...]</span>" +
QuestionType_ClozeUtil.renderClozeFront() +
questionText.substring(deletionEnd);
front = front
.replace(/==/gm, "")
Expand All @@ -119,9 +120,7 @@ class QuestionType_Cloze implements IQuestionTypeHandler {
.replace(/}}/gm, "");
back =
questionText.substring(0, deletionStart) +
"<span style='color:#2196f3'>" +
questionText.substring(deletionStart, deletionEnd) +
"</span>" +
QuestionType_ClozeUtil.renderClozeBack(questionText.substring(deletionStart, deletionEnd)) +
questionText.substring(deletionEnd);
back = back
.replace(/==/gm, "")
Expand All @@ -135,6 +134,16 @@ class QuestionType_Cloze implements IQuestionTypeHandler {
}
}

export class QuestionType_ClozeUtil {
static renderClozeFront(): string {
return "<span style='color:#2196f3'>[...]</span>";
}

static renderClozeBack(str: string): string {
return "<span style='color:#2196f3'>" + str + "</span>";
}
}

export class QuestionTypeFactory {
static create(questionType: CardType): IQuestionTypeHandler {
var handler: IQuestionTypeHandler;
Expand Down
102 changes: 102 additions & 0 deletions tests/unit/question-type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { CardType } from "src/question";
import { CardFrontBack, CardFrontBackUtil, QuestionType_ClozeUtil } from "src/question-type";
import { DEFAULT_SETTINGS, SRSettings } from "src/settings";

test("CardType.SingleLineBasic", () => {
expect(
CardFrontBackUtil.expand(CardType.SingleLineBasic, "A::B", DEFAULT_SETTINGS),
).toEqual(
[new CardFrontBack("A", "B")]
);
});


test("CardType.SingleLineReversed", () => {
expect(
CardFrontBackUtil.expand(CardType.SingleLineReversed, "A:::B", DEFAULT_SETTINGS),
).toEqual([
new CardFrontBack("A", "B"),
new CardFrontBack("B", "A")
]
);
});


test("CardType.MultiLineBasic", () => {
expect(
CardFrontBackUtil.expand(CardType.MultiLineBasic, "A1\nA2\n?\nB1\nB2", DEFAULT_SETTINGS),
).toEqual([
new CardFrontBack("A1\nA2", "B1\nB2")
]
);
});


test("CardType.MultiLineReversed", () => {
expect(
CardFrontBackUtil.expand(CardType.MultiLineReversed, "A1\nA2\n??\nB1\nB2", DEFAULT_SETTINGS),
).toEqual([
new CardFrontBack("A1\nA2", "B1\nB2"),
new CardFrontBack("B1\nB2", "A1\nA2"),
]
);
});


test("CardType.Cloze", () => {
let frontHtml = QuestionType_ClozeUtil.renderClozeFront();

expect(
CardFrontBackUtil.expand(CardType.Cloze, "This is a very ==interesting== test", DEFAULT_SETTINGS),
).toEqual([
new CardFrontBack(
"This is a very " + frontHtml + " test",
"This is a very " + QuestionType_ClozeUtil.renderClozeBack("interesting") + " test",
)
]
);

let settings2: SRSettings = DEFAULT_SETTINGS;
settings2.convertBoldTextToClozes = true;
settings2.convertHighlightsToClozes = true;
settings2.convertCurlyBracketsToClozes = true;

expect(
CardFrontBackUtil.expand(CardType.Cloze, "This is a very **interesting** test", settings2),
).toEqual([
new CardFrontBack(
"This is a very " + frontHtml + " test",
"This is a very " + QuestionType_ClozeUtil.renderClozeBack("interesting") + " test"
)
]
);

expect(
CardFrontBackUtil.expand(CardType.Cloze, "This is a very {{interesting}} test", settings2),
).toEqual([
new CardFrontBack(
"This is a very " + frontHtml + " test",
"This is a very " + QuestionType_ClozeUtil.renderClozeBack("interesting") + " test"
)
]
);


expect(
CardFrontBackUtil.expand(CardType.Cloze, "This is a really very {{interesting}} and ==fascinating== and **great** test", settings2),
).toEqual([
new CardFrontBack(
"This is a really very <span style='color:#2196f3'>[...]</span> and fascinating and great test",
"This is a really very <span style='color:#2196f3'>interesting</span> and fascinating and great test"
),
new CardFrontBack(
"This is a really very interesting and <span style='color:#2196f3'>[...]</span> and great test",
"This is a really very interesting and <span style='color:#2196f3'>fascinating</span> and great test"
),
new CardFrontBack(
"This is a really very interesting and fascinating and <span style='color:#2196f3'>[...]</span> test",
"This is a really very interesting and fascinating and <span style='color:#2196f3'>great</span> test"
)
]
);
});