|
| 1 | +import { expect } from '@open-wc/testing'; |
| 2 | +import { UmbUfmTruncateFilterApi } from './truncate.filter.js'; |
| 3 | + |
| 4 | +describe('UmbUfmTruncateFilter', () => { |
| 5 | + let filter: UmbUfmTruncateFilterApi; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + filter = new UmbUfmTruncateFilterApi(); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('filter', () => { |
| 12 | + it('should not add ellipsis when text is shorter than length', () => { |
| 13 | + const result = filter.filter('Test', 10); |
| 14 | + expect(result).to.equal('Test'); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should not add ellipsis when text equals length', () => { |
| 18 | + const result = filter.filter('Test', 4); |
| 19 | + expect(result).to.equal('Test'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should add ellipsis when text is longer than length', () => { |
| 23 | + const result = filter.filter('Lorem ipsum', 5); |
| 24 | + expect(result).to.equal('Lorem…'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should add custom tail when text is truncated', () => { |
| 28 | + const result = filter.filter('Lorem ipsum', 5, '...'); |
| 29 | + expect(result).to.equal('Lorem...'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should not add tail when tail is false and text is truncated', () => { |
| 33 | + const result = filter.filter('Lorem ipsum', 5, 'false'); |
| 34 | + expect(result).to.equal('Lorem'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should add ellipsis when tail is true and text is truncated', () => { |
| 38 | + const result = filter.filter('Lorem ipsum', 5, 'true'); |
| 39 | + expect(result).to.equal('Lorem…'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should not add ellipsis when tail is false and text is not truncated', () => { |
| 43 | + const result = filter.filter('Test', 10, 'false'); |
| 44 | + expect(result).to.equal('Test'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should not add custom tail when text is not truncated', () => { |
| 48 | + const result = filter.filter('Test', 10, '...'); |
| 49 | + expect(result).to.equal('Test'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should handle empty string', () => { |
| 53 | + const result = filter.filter('', 10); |
| 54 | + expect(result).to.equal(''); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should handle non-string input', () => { |
| 58 | + const result = filter.filter(null as any, 10); |
| 59 | + expect(result).to.equal(null); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should trim whitespace before adding ellipsis', () => { |
| 63 | + const result = filter.filter('Hello world', 6); |
| 64 | + expect(result).to.equal('Hello…'); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments