Skip to content

Commit 80d9f42

Browse files
committed
Fix unit tests
1 parent eac6a33 commit 80d9f42

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/scripts/db/SparkService.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import type AppDB from "./AppDB";
55
describe("SparkService", () => {
66
let sparkService: SparkService;
77
let db: AppDB;
8+
const toArrayMock = vi.fn();
89

910
beforeEach(() => {
1011
db = {
1112
sparks: {
1213
add: vi.fn(),
1314
update: vi.fn(),
1415
delete: vi.fn(),
16+
orderBy: vi.fn().mockReturnValue({
17+
reverse: vi.fn().mockReturnValue({ toArray: toArrayMock }),
18+
}),
1519
toCollection: vi.fn().mockReturnValue({
1620
reverse: vi.fn().mockReturnValue({ sortBy: vi.fn() }),
1721
}),
@@ -30,6 +34,7 @@ describe("SparkService", () => {
3034
expect(db.sparks.add).toHaveBeenCalledWith({
3135
plainText: plainText,
3236
html: html,
37+
originalHtml: html,
3338
creationDate: expect.any(Number),
3439
tags: expect.any(Array),
3540
contextTags: expect.any(Array),
@@ -60,12 +65,10 @@ describe("SparkService", () => {
6065

6166
describe("listSparks", () => {
6267
test("returns a sorted list of sparks from the database", async () => {
63-
await sparkService.listSparksWithTags();
68+
await sparkService.listSparks();
6469

65-
expect(db.sparks.toCollection).toHaveBeenCalled();
66-
expect(
67-
db.sparks.toCollection().reverse().sortBy,
68-
).toHaveBeenCalledWith("creationDate");
70+
expect(db.sparks.orderBy).toHaveBeenCalled();
71+
expect(toArrayMock).toHaveBeenCalled();
6972
});
7073
});
7174
});

src/scripts/utils/stringUtils.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ describe("extractTags", () => {
112112
'<span style="--tag-color: 135" data-type="mention" class="tag" data-id="tag1">#tag1</span> <span style="--tag-color: 140" data-type="mention" class="tag" data-id="tag2">#tag2</span> <span style="--tag-color: 145" data-type="mention" class="tag" data-id="tag3">#tag3</span> ';
113113
const expectedTags = ["tag1", "tag2", "tag3"];
114114
const expectStrippedPlainText = "";
115-
const expectStrippedHtml = "<p></p>";
115+
const expectStrippedHtml =
116+
'<p><span style="--tag-color: 135" data-type="mention" class="tag" data-id="tag1">#tag1</span> <span style="--tag-color: 140" data-type="mention" class="tag" data-id="tag2">#tag2</span> <span style="--tag-color: 145" data-type="mention" class="tag" data-id="tag3">#tag3</span></p>';
116117

117118
const {
118119
prefixTags,

src/scripts/utils/stringUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const extractTags = (plainText: string, html: string) => {
6565
isCollectPrefixTags = false;
6666
}
6767

68+
tags.push(tagName);
6869
if (isCollectPrefixTags) {
6970
prefixTags.push(tagName);
7071
prefixTagsHtml += `${tagNode.outerHTML} `;

0 commit comments

Comments
 (0)