|
1 |
| -import { clone, deserialize, fill, safeNormalize, serialize, urlEncode } from '../src/object'; |
| 1 | +import { |
| 2 | + clone, |
| 3 | + deserialize, |
| 4 | + fill, |
| 5 | + safeNormalize, |
| 6 | + serialize, |
| 7 | + serializeKeysToEventMessage, |
| 8 | + urlEncode, |
| 9 | +} from '../src/object'; |
2 | 10 |
|
3 | 11 | const MATRIX = [
|
4 | 12 | { name: 'boolean', object: true, serialized: 'true' },
|
@@ -142,6 +150,34 @@ describe('deserialize()', () => {
|
142 | 150 | }
|
143 | 151 | });
|
144 | 152 |
|
| 153 | +describe('serializeKeysToEventMessage()', () => { |
| 154 | + test('no keys', () => { |
| 155 | + expect(serializeKeysToEventMessage([], 10)).toEqual('[object has no keys]'); |
| 156 | + }); |
| 157 | + |
| 158 | + test('one key should be returned as a whole if not over the length limit', () => { |
| 159 | + expect(serializeKeysToEventMessage(['foo'], 10)).toEqual('foo'); |
| 160 | + expect(serializeKeysToEventMessage(['foobarbazx'], 10)).toEqual('foobarbazx'); |
| 161 | + }); |
| 162 | + |
| 163 | + test('one key should be appended with ... and truncated when over the limit', () => { |
| 164 | + expect(serializeKeysToEventMessage(['foobarbazqux'], 10)).toEqual('foobarbazq...'); |
| 165 | + }); |
| 166 | + |
| 167 | + test('multiple keys should be joined as a whole if not over the length limit', () => { |
| 168 | + expect(serializeKeysToEventMessage(['foo', 'bar'], 10)).toEqual('foo, bar'); |
| 169 | + }); |
| 170 | + |
| 171 | + test('multiple keys should include only as much keys as can fit into the limit', () => { |
| 172 | + expect(serializeKeysToEventMessage(['foo', 'bar', 'baz'], 10)).toEqual('foo, bar'); |
| 173 | + expect(serializeKeysToEventMessage(['foo', 'verylongkey', 'baz'], 10)).toEqual('foo'); |
| 174 | + }); |
| 175 | + |
| 176 | + test('multiple keys should truncate first key if its too long', () => { |
| 177 | + expect(serializeKeysToEventMessage(['foobarbazqux', 'bar', 'baz'], 10)).toEqual('foobarbazq...'); |
| 178 | + }); |
| 179 | +}); |
| 180 | + |
145 | 181 | describe('fill()', () => {
|
146 | 182 | test('wraps a method by calling a replacement function on it', () => {
|
147 | 183 | const source = {
|
|
0 commit comments