mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-05 18:38:54 +00:00
Adding a link bookmark fills the name from the page's title and saved it as is. The server rejects a display name longer than 64 characters (model.DisplayNameMaxRunes) with only "Could not save bookmark", so bookmarking a page with a long title failed. mattermost.com's title is now 93 characters, which is why channel_bookmark_link_external started failing on iOS and Android. Names from a page title, a file name or typing are cut to 64 characters, counted as the server counts them so a character is never split, and the name field takes at most 64, as in the webapp.
29 lines
1.5 KiB
TypeScript
29 lines
1.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {BOOKMARK_DISPLAY_NAME_MAX_LENGTH, limitBookmarkDisplayName} from './channel_bookmark';
|
|
|
|
describe('limitBookmarkDisplayName', () => {
|
|
it('keeps a name within the limit as is', () => {
|
|
expect(limitBookmarkDisplayName('Mattermost')).toBe('Mattermost');
|
|
const exact = 'a'.repeat(BOOKMARK_DISPLAY_NAME_MAX_LENGTH);
|
|
expect(limitBookmarkDisplayName(exact)).toBe(exact);
|
|
});
|
|
|
|
it('cuts a page title longer than the server allows', () => {
|
|
// mattermost.com's title, 93 characters; saving it failed with "Could not save bookmark."
|
|
const title = 'Mattermost | Operational and AI Sovereignty for Critical Infrastructure and National Security';
|
|
const limited = limitBookmarkDisplayName(title);
|
|
expect(limited).toBe(title.slice(0, BOOKMARK_DISPLAY_NAME_MAX_LENGTH));
|
|
expect(limited).toHaveLength(BOOKMARK_DISPLAY_NAME_MAX_LENGTH);
|
|
});
|
|
|
|
it('counts characters as the server does and never splits one', () => {
|
|
const name = '😀'.repeat(BOOKMARK_DISPLAY_NAME_MAX_LENGTH + 1);
|
|
const limited = limitBookmarkDisplayName(name);
|
|
expect(Array.from(limited)).toHaveLength(BOOKMARK_DISPLAY_NAME_MAX_LENGTH);
|
|
expect(limited).toBe('😀'.repeat(BOOKMARK_DISPLAY_NAME_MAX_LENGTH));
|
|
expect(limitBookmarkDisplayName('😀'.repeat(BOOKMARK_DISPLAY_NAME_MAX_LENGTH))).toBe('😀'.repeat(BOOKMARK_DISPLAY_NAME_MAX_LENGTH));
|
|
});
|
|
});
|