Skip to content
Draft
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
79 changes: 79 additions & 0 deletions packages/cli-kit/src/public/node/notifications-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
fetchNotificationsInBackground,
filterNotifications,
showNotificationsIfNeeded,
stringifyFilters,
} from './notifications-system.js'
import {renderError, renderInfo, renderWarning} from './ui.js'
import {fetch} from './http.js'
Expand Down Expand Up @@ -498,3 +499,81 @@ describe('fetchNotifications', () => {
vi.unstubAllEnvs()
})
})

describe('stringifyFilters', () => {
test('returns an empty string when notification has no filter options set', () => {
// Given
const notification: Notification = {
id: 'test',
message: 'msg',
type: 'info',
frequency: 'always',
ownerChannel: 'channel',
}

// When
const result = stringifyFilters(notification)

// Then
expect(result).toBe('')
})

test('stringifies dates, versions, frequencies, surface, and commands filters', () => {
// Given
const notification: Notification = {
id: 'test',
message: 'msg',
type: 'info',
frequency: 'once_a_day',
ownerChannel: 'channel',
minDate: '2023-01-01',
maxDate: '2023-12-31',
minVersion: '3.0.0',
maxVersion: '4.0.0',
surface: 'theme',
commands: ['theme:dev', 'theme:push'],
}

// When
const result = stringifyFilters(notification)

// Then
expect(result).toBe(
[
'from 2023-01-01',
'to 2023-12-31',
'from v3.0.0',
'to v4.0.0',
'show once a day',
'surface = theme',
'commands = theme:dev, theme:push',
].join('\n'),
)
})

test('stringifies frequency once and once_a_week correctly', () => {
// Given
const onceNotification: Notification = {
id: 'once',
message: 'msg',
type: 'info',
frequency: 'once',
ownerChannel: 'channel',
}
const onceAWeekNotification: Notification = {
id: 'once_a_week',
message: 'msg',
type: 'info',
frequency: 'once_a_week',
ownerChannel: 'channel',
}

// When
const onceResult = stringifyFilters(onceNotification)
const onceAWeekResult = stringifyFilters(onceAWeekNotification)

// Then
expect(onceResult).toBe('show only once')
expect(onceAWeekResult).toBe('show once a week')
})
})
Loading