1// 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', () => { 18 const tripleDot = '\u2026'; 19 const emoji = '\uD83D\uDE00'; 20 expect(cropText( 21 'com.android.camera [4096]', 22 /*charWidth=*/ 5, 23 /*rectWidth=*/ 2 * 5)) 24 .toBe('c'); 25 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); 29 expect(cropText('com.android.camera [4096]', 5, 13 * 5 + 2)) 30 .toBe('com.android' + tripleDot); 31 expect(cropText('com.android.camera [4096]', 5, 26 * 5 + 2)) 32 .toBe('com.android.camera [4096]'); 33 expect(cropText(emoji + 'abc', 5, 2 * 5)).toBe(emoji); 34 expect(cropText(emoji + 'abc', 5, 5 * 5)).toBe(emoji + 'a' + tripleDot); 35}); 36