AndrewB330 | 7fab8f6 | 2020-07-02 22:45:51 +0300 | [diff] [blame] | 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 | |
| 15 | import {cropText} from './canvas_utils'; |
| 16 | |
| 17 | test('cropHelper regular text', () => { |
Primiano Tucci | 81f14f6 | 2021-02-25 01:27:19 +0100 | [diff] [blame] | 18 | const tripleDot = '\u2026'; |
| 19 | const emoji = '\uD83D\uDE00'; |
AndrewB330 | 7fab8f6 | 2020-07-02 22:45:51 +0300 | [diff] [blame] | 20 | expect(cropText( |
| 21 | 'com.android.camera [4096]', |
| 22 | /*charWidth=*/ 5, |
Primiano Tucci | 81f14f6 | 2021-02-25 01:27:19 +0100 | [diff] [blame] | 23 | /*rectWidth=*/ 2 * 5)) |
AndrewB330 | 7fab8f6 | 2020-07-02 22:45:51 +0300 | [diff] [blame] | 24 | .toBe('c'); |
Primiano Tucci | 81f14f6 | 2021-02-25 01:27:19 +0100 | [diff] [blame] | 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); |
AndrewB330 | 7fab8f6 | 2020-07-02 22:45:51 +0300 | [diff] [blame] | 29 | expect(cropText('com.android.camera [4096]', 5, 13 * 5 + 2)) |
Primiano Tucci | 81f14f6 | 2021-02-25 01:27:19 +0100 | [diff] [blame] | 30 | .toBe('com.android' + tripleDot); |
| 31 | expect(cropText('com.android.camera [4096]', 5, 26 * 5 + 2)) |
AndrewB330 | 7fab8f6 | 2020-07-02 22:45:51 +0300 | [diff] [blame] | 32 | .toBe('com.android.camera [4096]'); |
Primiano Tucci | 81f14f6 | 2021-02-25 01:27:19 +0100 | [diff] [blame] | 33 | expect(cropText(emoji + 'abc', 5, 2 * 5)).toBe(emoji); |
| 34 | expect(cropText(emoji + 'abc', 5, 5 * 5)).toBe(emoji + 'a' + tripleDot); |
AndrewB330 | 7fab8f6 | 2020-07-02 22:45:51 +0300 | [diff] [blame] | 35 | }); |