|
5 | 5 | import { parseMentions, parseSpecialSymbols } from '../textParse.ts' |
6 | 6 |
|
7 | 7 | jest.mock('@nextcloud/router', () => ({ |
8 | | - getBaseUrl: jest.fn().mockReturnValue('server2.com') |
| 8 | + getBaseUrl: jest.fn().mockReturnValue('https://server2.com') |
9 | 9 | })) |
10 | 10 |
|
11 | 11 | describe('textParse', () => { |
12 | 12 | describe('parseMentions', () => { |
| 13 | + it('replaces mentions correctly if mention-id is available', () => { |
| 14 | + const input = 'test {mention-call1} test {mention-user1} test {mention-group1} test {mention-federated-user1}' |
| 15 | + const output = 'test @"all" test @"alice" test @"group/talk" test @"federated_user/alice@server2.com"' |
| 16 | + const parameters = { |
| 17 | + 'mention-call1': { |
| 18 | + id: 'room-id', |
| 19 | + name: 'Room Display Name', |
| 20 | + type: 'call', |
| 21 | + 'mention-id': 'all', |
| 22 | + }, |
| 23 | + 'mention-user1': { |
| 24 | + id: 'alice', |
| 25 | + name: 'Just Alice', |
| 26 | + type: 'user', |
| 27 | + 'mention-id': 'alice', |
| 28 | + }, |
| 29 | + 'mention-group1': { |
| 30 | + id: 'talk', |
| 31 | + name: 'Talk Group', |
| 32 | + type: 'user-group', |
| 33 | + 'mention-id': 'group/talk', |
| 34 | + }, |
| 35 | + 'mention-federated-user1': { |
| 36 | + id: 'alice', |
| 37 | + name: 'Feder Alice', |
| 38 | + type: 'user', |
| 39 | + server: 'https://server2.com', |
| 40 | + 'mention-id': 'federated_user/alice@server2.com', |
| 41 | + } |
| 42 | + } |
| 43 | + expect(parseMentions(input, parameters)).toBe(output) |
| 44 | + }) |
| 45 | + |
13 | 46 | it('replaces {mention-call} correctly', () => { |
14 | 47 | const input = 'test {mention-call1}' |
15 | 48 | const output = 'test @all' |
@@ -38,7 +71,7 @@ describe('textParse', () => { |
38 | 71 |
|
39 | 72 | it('replaces {mention-user} correctly', () => { |
40 | 73 | const input = 'test {mention-user1} test {mention-user2}' |
41 | | - const output = 'test @alice test @"alice space@mail.com"' |
| 74 | + const output = 'test @"alice" test @"alice space@mail.com"' |
42 | 75 | const parameters = { |
43 | 76 | 'mention-user1': { |
44 | 77 | id: 'alice', |
@@ -72,15 +105,69 @@ describe('textParse', () => { |
72 | 105 | expect(parseMentions(input, parameters)).toBe(output) |
73 | 106 | }) |
74 | 107 |
|
| 108 | + it('replaces {mention-team} correctly', () => { |
| 109 | + const input = 'test {mention-team1} test {mention-team2}' |
| 110 | + const output = 'test @"team/talk" test @"team/space talk"' |
| 111 | + const parameters = { |
| 112 | + 'mention-team1': { |
| 113 | + id: 'talk', |
| 114 | + name: 'Talk Group', |
| 115 | + type: 'circle', |
| 116 | + }, |
| 117 | + 'mention-team2': { |
| 118 | + id: 'space talk', |
| 119 | + name: 'Out of space Talk Group', |
| 120 | + type: 'team', |
| 121 | + } |
| 122 | + } |
| 123 | + expect(parseMentions(input, parameters)).toBe(output) |
| 124 | + }) |
| 125 | + |
| 126 | + it('replaces {mention-guest} correctly', () => { |
| 127 | + const input = 'test {mention-guest1} test {mention-guest2}' |
| 128 | + const output = 'test @"guest/abcd" test @"guest/efgh"' |
| 129 | + const parameters = { |
| 130 | + 'mention-guest1': { |
| 131 | + id: 'guest/abcd', |
| 132 | + name: 'Guest A', |
| 133 | + type: 'guest', |
| 134 | + }, |
| 135 | + 'mention-guest2': { |
| 136 | + id: 'guest/efgh', |
| 137 | + name: 'Guest E', |
| 138 | + type: 'guest', |
| 139 | + } |
| 140 | + } |
| 141 | + expect(parseMentions(input, parameters)).toBe(output) |
| 142 | + }) |
| 143 | + |
| 144 | + it('replaces {mention-email} correctly', () => { |
| 145 | + const input = 'test {mention-email1} test {mention-email2}' |
| 146 | + const output = 'test @"email/abcd" test @"email/efgh"' |
| 147 | + const parameters = { |
| 148 | + 'mention-email1': { |
| 149 | + id: 'abcd', |
| 150 | + name: 'Email Guest A', |
| 151 | + type: 'email', |
| 152 | + }, |
| 153 | + 'mention-email2': { |
| 154 | + id: 'efgh', |
| 155 | + name: 'Email Guest E', |
| 156 | + type: 'email', |
| 157 | + } |
| 158 | + } |
| 159 | + expect(parseMentions(input, parameters)).toBe(output) |
| 160 | + }) |
| 161 | + |
75 | 162 | it('replaces {mention-federated-user} correctly (for host and other federations)', () => { |
76 | 163 | const input = 'test {mention-federated-user1}' |
77 | 164 | const output = 'test @"federated_user/alice@server3.com"' |
78 | 165 | const parameters = { |
79 | 166 | 'mention-federated-user1': { |
80 | 167 | id: 'alice', |
81 | 168 | name: 'Feder Alice', |
82 | | - type: 'user', |
83 | | - server: 'server3.com' |
| 169 | + type: 'federated_user', |
| 170 | + server: 'https://server3.com' |
84 | 171 | } |
85 | 172 | } |
86 | 173 | expect(parseMentions(input, parameters)).toBe(output) |
|
0 commit comments