Skip to content

Commit

Permalink
Fixed test cases after merging with st3v3nmw#815
Browse files Browse the repository at this point in the history
  • Loading branch information
ronzulu committed Feb 3, 2024
1 parent 721a38a commit d0b2f32
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/NoteQuestionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class NoteQuestionParser {
// If present, the question specific TopicPath takes precedence over everything else
const questionText: QuestionText = question.questionText;
if (questionText.topicPathWithWs)
result = new TopicPathList([questionText.topicPathWithWs.topicPath]);
result = new TopicPathList([questionText.topicPathWithWs.topicPath], question.parsedQuestionInfo.firstLineNum);
else {
// By default we start off with any TopicPathList present in the frontmatter
result = this.frontmatterTopicPathList;
Expand Down
7 changes: 4 additions & 3 deletions src/TopicPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class TopicPathList {
return result;
}

static getFlashcardSettingsTopicPathList(settings: SRSettings): TopicPathList {
static getFlashcardSettingsTopicPathList(settings: SRSettings, lineNum: number): TopicPathList {
return this.convertTagListToTopicPathList(settings.flashcardTags);
}

Expand All @@ -142,14 +142,15 @@ export class TopicPathList {
//
static filterValidTopicPathsFromTagList(
list: TopicPathList,
validTopicPathList: TopicPathList,
validTopicPathList: TopicPathList,
lineNum: number = null
): TopicPathList {
const result: TopicPath[] = [];
for (const tag of list.list) {
if (validTopicPathList.isAnyElementSameOrAncestorOf(tag)) result.push(tag);
}

return new TopicPathList(result);
return new TopicPathList(result, lineNum);
}

static convertTagListToTopicPathList(tagList: string[]): TopicPathList {
Expand Down
56 changes: 38 additions & 18 deletions tests/unit/NoteQuestionParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ A::B

describe("Single question in the text (with block identifier)", () => {
test("SingleLineBasic: No schedule info", async () => {
let noteText: string = `
let noteText: string = `#flashcards
A::B ^d7cee0
`;
let noteFile: ISRFile = new UnitTestSRFile(noteText);
Expand All @@ -127,22 +127,27 @@ A::B ^d7cee0
};
let expected = [
{
questionType: CardType.SingleLineBasic,
topicPath: TopicPath.emptyPath,
topicPathList: {
list: [ TopicPath.getTopicPathFromTag("#flashcards")],
lineNum: 0
},
parsedQuestionInfo: {
cardType: CardType.SingleLineBasic,
firstLineNum: 1
},
questionText: {
original: `A::B ^d7cee0`,
actualQuestion: "A::B",
obsidianBlockId: "^d7cee0",
},

lineNo: 1,
hasEditLaterTag: false,
cards: [card1],
hasChanged: false,
},
];
expect(
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath),
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});

Expand All @@ -166,27 +171,32 @@ A::B ^d7cee0
};
let expected = [
{
questionType: CardType.SingleLineBasic,
topicPath: new TopicPath(["flashcards", "test"]),
topicPathList: {
list: [ TopicPath.getTopicPathFromTag("#flashcards/test")],
lineNum: 0
},
parsedQuestionInfo: {
cardType: CardType.SingleLineBasic,
firstLineNum: 1
},
questionText: {
original: `A::B ^d7cee0
<!--SR:!2023-09-03,1,230-->`,
actualQuestion: "A::B",
textHash: "1c6b0b01215dc4",
obsidianBlockId: "^d7cee0",
},
lineNo: 1,
hasEditLaterTag: false,
cards: [card1],
hasChanged: false,
},
];
expect(
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath),
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});

test("SingleLineBasic: With schedule info (same line)", async () => {
test.only("SingleLineBasic: With schedule info (same line)", async () => {
let noteText: string = `#flashcards/test
A::B <!--SR:!2023-09-03,1,230--> ^d7cee0
`;
Expand All @@ -205,22 +215,27 @@ A::B <!--SR:!2023-09-03,1,230--> ^d7cee0
};
let expected = [
{
questionType: CardType.SingleLineBasic,
topicPath: new TopicPath(["flashcards", "test"]),
topicPathList: {
list: [ TopicPath.getTopicPathFromTag("#flashcards/test")],
lineNum: 1
},
parsedQuestionInfo: {
cardType: CardType.SingleLineBasic,
firstLineNum: 1
},
questionText: {
original: `A::B <!--SR:!2023-09-03,1,230--> ^d7cee0`,
actualQuestion: "A::B",
textHash: "1c6b0b01215dc4",
obsidianBlockId: "^d7cee0",
},
lineNo: 1,
hasEditLaterTag: false,
cards: [card1],
hasChanged: false,
},
];
expect(
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath),
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});

Expand All @@ -243,21 +258,26 @@ A::B <!--SR:!2023-09-03,1,230--> ^d7cee0
};
let expected = [
{
questionType: CardType.SingleLineBasic,
topicPath: new TopicPath(["flashcards", "test"]),
topicPathList: {
list: [ TopicPath.getTopicPathFromTag("#flashcards/test")],
lineNum: 1
},
parsedQuestionInfo: {
cardType: CardType.SingleLineBasic,
firstLineNum: 1
},
questionText: {
original: `#flashcards/test A::B <!--SR:!2023-09-03,1,230--> ^d7cee0`,
actualQuestion: "A::B",
obsidianBlockId: "^d7cee0",
},
lineNo: 1,
hasEditLaterTag: false,
cards: [card1],
hasChanged: false,
},
];
expect(
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath),
await parserWithDefaultSettings.createQuestionList(noteFile, folderTopicPath, true),
).toMatchObject(expected);
});
});
Expand Down

0 comments on commit d0b2f32

Please sign in to comment.