blob: 19363bf0b679ba8571b47e614e7c5345fa2ab5ce [file] [log] [blame]
AndrewB3307fab8f62020-07-02 22:45:51 +03001// Copyright (C) 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {cropText} from './canvas_utils';
16
17test('cropHelper regular text', () => {
Primiano Tucci81f14f62021-02-25 01:27:19 +010018 const tripleDot = '\u2026';
19 const emoji = '\uD83D\uDE00';
AndrewB3307fab8f62020-07-02 22:45:51 +030020 expect(cropText(
21 'com.android.camera [4096]',
22 /*charWidth=*/ 5,
Primiano Tucci81f14f62021-02-25 01:27:19 +010023 /*rectWidth=*/ 2 * 5))
AndrewB3307fab8f62020-07-02 22:45:51 +030024 .toBe('c');
Primiano Tucci81f14f62021-02-25 01:27:19 +010025 expect(cropText('com.android.camera [4096]', 5, 4 * 5 + 2))
26 .toBe('co' + tripleDot);
27 expect(cropText('com.android.camera [4096]', 5, 5 * 5 + 2))
28 .toBe('com' + tripleDot);
AndrewB3307fab8f62020-07-02 22:45:51 +030029 expect(cropText('com.android.camera [4096]', 5, 13 * 5 + 2))
Primiano Tucci81f14f62021-02-25 01:27:19 +010030 .toBe('com.android' + tripleDot);
31 expect(cropText('com.android.camera [4096]', 5, 26 * 5 + 2))
AndrewB3307fab8f62020-07-02 22:45:51 +030032 .toBe('com.android.camera [4096]');
Primiano Tucci81f14f62021-02-25 01:27:19 +010033 expect(cropText(emoji + 'abc', 5, 2 * 5)).toBe(emoji);
34 expect(cropText(emoji + 'abc', 5, 5 * 5)).toBe(emoji + 'a' + tripleDot);
AndrewB3307fab8f62020-07-02 22:45:51 +030035});