Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"dependencies": {
"@pnpm/tabtab": "0.5.4",
"@todoist/cli-core": "2.0.0",
"@todoist/comms-sdk": "5.0.1",
"@todoist/comms-sdk": "5.2.2",
"chalk": "5.6.2",
"commander": "14.0.3",
"marked": "18.0.3",
Expand Down
20 changes: 20 additions & 0 deletions src/commands/status/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ describe('tdc status', () => {
expect(logged(spy)).toBe('🎯 Deep work (notifications paused)')
})

// A status can be just an emoji, which the API returns with a null or absent message.
it.each([
['null', { message: null, emoji: '🎯' }, '🎯'],
['absent', { emoji: '🎯' }, '🎯'],
[
'null, with a pause',
{
message: null,
emoji: '🎯',
effects: { pauseNotifications: { scope: { mode: 'all' } } },
},
'🎯 (notifications paused)',
],
])('prints an emoji-only status whose message is %s', async (_name, status, expected) => {
apiMocks.getSessionUser.mockResolvedValue({ status })
const spy = captureConsole('log')
await run('show')
expect(logged(spy)).toBe(expected)
})

it('names each paused effect, notifications first', async () => {
apiMocks.getSessionUser.mockResolvedValue({
status: {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/status.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { UserStatus } from '@todoist/comms-sdk'
import { formatDateTime } from './dates.js'

/** One line for a status: emoji and message, then the expiry and the pause when they apply. */
/**
* One line for a status: emoji and message, then the expiry and the pause when they apply.
* A status has a message, an emoji or both.
*/
export function formatStatus(status: UserStatus): string {
const parts = [status.emoji ? `${status.emoji} ${status.message}` : status.message]
const parts = [[status.emoji, status.message].filter(Boolean).join(' ')]
if (status.activeUntil) {
parts.push(`until ${formatDateTime(new Date(status.activeUntil))}`)
}
Expand Down
Loading