mattermost-mobile-upstream/app/utils/channel_bookmark.test.ts
yasser khan d295fa1c9e
Limit bookmark names to the server's 64 characters (#10211)
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.
2026-10-04 10:23:59 +05:30

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));
});
});