-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(textParse): refactor method and tests
- split logic for federated users from host and from own server - wrap user mentions in double quotes Signed-off-by: Maksim Sukharev <[email protected]>
- Loading branch information
Showing
2 changed files
with
67 additions
and
13 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import { parseMentions, parseSpecialSymbols } from '../textParse.ts' | ||
|
||
jest.mock('@nextcloud/router', () => ({ | ||
getBaseUrl: jest.fn().mockReturnValue('server2.com') | ||
getBaseUrl: jest.fn().mockReturnValue('https://server2.com') | ||
})) | ||
|
||
describe('textParse', () => { | ||
|
@@ -38,7 +38,7 @@ describe('textParse', () => { | |
|
||
it('replaces {mention-user} correctly', () => { | ||
const input = 'test {mention-user1} test {mention-user2}' | ||
const output = 'test @alice test @"alice [email protected]"' | ||
const output = 'test @"alice" test @"alice [email protected]"' | ||
const parameters = { | ||
'mention-user1': { | ||
id: 'alice', | ||
|
@@ -72,15 +72,69 @@ describe('textParse', () => { | |
expect(parseMentions(input, parameters)).toBe(output) | ||
}) | ||
|
||
it('replaces {mention-team} correctly', () => { | ||
const input = 'test {mention-team1} test {mention-team2}' | ||
const output = 'test @"team/talk" test @"team/space talk"' | ||
const parameters = { | ||
'mention-team1': { | ||
id: 'talk', | ||
name: 'Talk Group', | ||
type: 'circle', | ||
}, | ||
'mention-team2': { | ||
id: 'space talk', | ||
name: 'Out of space Talk Group', | ||
type: 'team', | ||
} | ||
} | ||
expect(parseMentions(input, parameters)).toBe(output) | ||
}) | ||
|
||
it('replaces {mention-guest} correctly', () => { | ||
const input = 'test {mention-guest1} test {mention-guest2}' | ||
const output = 'test @"guest/abcd" test @"guest/efgh"' | ||
const parameters = { | ||
'mention-guest1': { | ||
id: 'guest/abcd', | ||
name: 'Guest A', | ||
type: 'guest', | ||
}, | ||
'mention-guest2': { | ||
id: 'guest/efgh', | ||
name: 'Guest E', | ||
type: 'guest', | ||
} | ||
} | ||
expect(parseMentions(input, parameters)).toBe(output) | ||
}) | ||
|
||
it('replaces {mention-email} correctly', () => { | ||
const input = 'test {mention-email1} test {mention-email2}' | ||
const output = 'test @"email/abcd" test @"email/efgh"' | ||
const parameters = { | ||
'mention-email1': { | ||
id: 'abcd', | ||
name: 'Email Guest A', | ||
type: 'email', | ||
}, | ||
'mention-email2': { | ||
id: 'efgh', | ||
name: 'Email Guest E', | ||
type: 'email', | ||
} | ||
} | ||
expect(parseMentions(input, parameters)).toBe(output) | ||
}) | ||
|
||
it('replaces {mention-federated-user} correctly (for host and other federations)', () => { | ||
const input = 'test {mention-federated-user1}' | ||
const output = 'test @"federated_user/[email protected]"' | ||
const parameters = { | ||
'mention-federated-user1': { | ||
id: 'alice', | ||
name: 'Feder Alice', | ||
type: 'user', | ||
server: 'server3.com' | ||
type: 'federated_user', | ||
server: 'https://server3.com' | ||
} | ||
} | ||
expect(parseMentions(input, parameters)).toBe(output) | ||
|
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