|
1 | 1 | import { fromPartial } from '@total-typescript/shoehorn'; |
2 | 2 | import type { TFunction } from 'i18next'; |
3 | | -import { ErrorFromResponse } from 'stream-chat'; |
| 3 | +import { ErrorFromResponse, ScheduledMessageBlockReason } from 'stream-chat'; |
4 | 4 | import type { Notification } from 'stream-chat'; |
5 | 5 |
|
6 | | -import { translateScheduledMessageCreateFailed } from '../TranslationBuilder/notifications/translators'; |
| 6 | +import { |
| 7 | + translateScheduledMessageBlocked, |
| 8 | + translateScheduledMessageCreateFailed, |
| 9 | +} from '../TranslationBuilder/notifications/translators'; |
7 | 10 | import { translatorsByNotificationType } from '../TranslationBuilder/notifications/translatorsByNotificationType'; |
8 | 11 |
|
9 | 12 | const t = ((key: string) => key) as TFunction; |
@@ -63,18 +66,45 @@ describe('translateScheduledMessageCreateFailed', () => { |
63 | 66 | }); |
64 | 67 | }); |
65 | 68 |
|
| 69 | +const translateBlocked = (reason?: string) => |
| 70 | + translateScheduledMessageBlocked({ |
| 71 | + key: '', |
| 72 | + options: { |
| 73 | + notification: fromPartial<Notification>({ |
| 74 | + message: 'This message cannot be scheduled', |
| 75 | + metadata: reason ? { reason } : undefined, |
| 76 | + type: 'validation:scheduled-message:blocked', |
| 77 | + }), |
| 78 | + }, |
| 79 | + t, |
| 80 | + value: '', |
| 81 | + }); |
| 82 | + |
| 83 | +describe('translateScheduledMessageBlocked', () => { |
| 84 | + it.each([ |
| 85 | + [ScheduledMessageBlockReason.Command, "Slash commands can't be scheduled"], |
| 86 | + [ScheduledMessageBlockReason.Poll, "Polls can't be scheduled"], |
| 87 | + [ScheduledMessageBlockReason.SharedLocation, "Locations can't be scheduled"], |
| 88 | + ])('translates the %s reason', (reason, expected) => { |
| 89 | + expect(translateBlocked(reason)).toBe(expected); |
| 90 | + }); |
| 91 | + |
| 92 | + it('falls back to the generic copy without a known reason', () => { |
| 93 | + expect(translateBlocked()).toBe("This message can't be scheduled"); |
| 94 | + expect(translateBlocked('unknown')).toBe("This message can't be scheduled"); |
| 95 | + }); |
| 96 | +}); |
| 97 | + |
66 | 98 | describe('scheduled message notification types', () => { |
67 | 99 | it('registers translators for the composer notifications', () => { |
68 | 100 | expect(translatorsByNotificationType['api:scheduled-message:create:failed']).toBe( |
69 | 101 | translateScheduledMessageCreateFailed, |
70 | 102 | ); |
71 | | - expect( |
72 | | - translatorsByNotificationType['validation:scheduled-message:command']?.({ |
73 | | - key: '', |
74 | | - options: {}, |
75 | | - t, |
76 | | - value: '', |
77 | | - }), |
78 | | - ).toBe("Slash commands can't be scheduled"); |
| 103 | + expect(translatorsByNotificationType['validation:scheduled-message:blocked']).toBe( |
| 104 | + translateScheduledMessageBlocked, |
| 105 | + ); |
| 106 | + expect(translatorsByNotificationType).not.toHaveProperty( |
| 107 | + 'validation:scheduled-message:command', |
| 108 | + ); |
79 | 109 | }); |
80 | 110 | }); |
0 commit comments