-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage ignore and formatTitle utility function***
- Loading branch information
1 parent
b75a88b
commit a6dfe1c
Showing
7 changed files
with
518 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -9,4 +9,6 @@ wrangler.toml | |
yarn.lock | ||
pnpm-lock.yaml | ||
|
||
.idea | ||
.idea | ||
|
||
coverage |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,44 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { Rooms } from "../schema"; | ||
import { formatTitle } from "./format-tilte"; | ||
|
||
describe("formatTitle", () => { | ||
it("should return the room ID if roomTitle is falsy", () => { | ||
const room: typeof Rooms.$inferSelect = { | ||
roomId: "test-room-id", | ||
roomTitle: null, | ||
roomCreated: "2021-01-01T00:00:00Z", | ||
roomUpdated: "2021-01-01T00:00:00Z", | ||
}; | ||
|
||
const result = formatTitle(room); | ||
|
||
expect(result).toBe("test-room-id"); | ||
}); | ||
|
||
it("should truncate the roomTitle if it exceeds the specified length", () => { | ||
const room: typeof Rooms.$inferSelect = { | ||
roomId: "test-room-id", | ||
roomTitle: "This is a very long room title", | ||
roomCreated: "2021-01-01T00:00:00Z", | ||
roomUpdated: "2021-01-01T00:00:00Z", | ||
}; | ||
|
||
const result = formatTitle(room, 10); | ||
|
||
expect(result).toBe("This is a ..."); | ||
}); | ||
|
||
it("should return the roomTitle as is if it does not exceed the specified length", () => { | ||
const room: typeof Rooms.$inferSelect = { | ||
roomId: "test-room-id", | ||
roomTitle: "Short title", | ||
roomCreated: "2021-01-01T00:00:00Z", | ||
roomUpdated: "2021-01-01T00:00:00Z", | ||
}; | ||
|
||
const result = formatTitle(room, 20); | ||
|
||
expect(result).toBe("Short title"); | ||
}); | ||
}); |
This file contains 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,10 @@ | ||
import { Rooms } from "../schema"; | ||
|
||
export const formatTitle = (room: typeof Rooms.$inferSelect, len = 20) => { | ||
if (!room.roomTitle) { | ||
return room.roomId; | ||
} | ||
return room.roomTitle.length > len | ||
? `${room.roomTitle.slice(0, len)}...` | ||
: room.roomTitle; | ||
}; |
This file contains 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 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