Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
derwebcoder committed Oct 15, 2024
1 parent eac6a33 commit 80d9f42
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/scripts/db/SparkService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import type AppDB from "./AppDB";
describe("SparkService", () => {
let sparkService: SparkService;
let db: AppDB;
const toArrayMock = vi.fn();

beforeEach(() => {
db = {
sparks: {
add: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
orderBy: vi.fn().mockReturnValue({
reverse: vi.fn().mockReturnValue({ toArray: toArrayMock }),
}),
toCollection: vi.fn().mockReturnValue({
reverse: vi.fn().mockReturnValue({ sortBy: vi.fn() }),
}),
Expand All @@ -30,6 +34,7 @@ describe("SparkService", () => {
expect(db.sparks.add).toHaveBeenCalledWith({
plainText: plainText,
html: html,
originalHtml: html,
creationDate: expect.any(Number),
tags: expect.any(Array),
contextTags: expect.any(Array),
Expand Down Expand Up @@ -60,12 +65,10 @@ describe("SparkService", () => {

describe("listSparks", () => {
test("returns a sorted list of sparks from the database", async () => {
await sparkService.listSparksWithTags();
await sparkService.listSparks();

expect(db.sparks.toCollection).toHaveBeenCalled();
expect(
db.sparks.toCollection().reverse().sortBy,
).toHaveBeenCalledWith("creationDate");
expect(db.sparks.orderBy).toHaveBeenCalled();
expect(toArrayMock).toHaveBeenCalled();
});
});
});
3 changes: 2 additions & 1 deletion src/scripts/utils/stringUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ describe("extractTags", () => {
'<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> ';
const expectedTags = ["tag1", "tag2", "tag3"];
const expectStrippedPlainText = "";
const expectStrippedHtml = "<p></p>";
const expectStrippedHtml =
'<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>';

const {
prefixTags,
Expand Down
1 change: 1 addition & 0 deletions src/scripts/utils/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const extractTags = (plainText: string, html: string) => {
isCollectPrefixTags = false;
}

tags.push(tagName);
if (isCollectPrefixTags) {
prefixTags.push(tagName);
prefixTagsHtml += `${tagNode.outerHTML} `;
Expand Down

0 comments on commit 80d9f42

Please sign in to comment.