|
1 |
| -import { getPreviewGroupArea } from '@/utilities/get-preview-group-area'; |
| 1 | +import { getPreviewGroupArea, getPreviewId } from '@/utilities/get-preview-group-area'; |
2 | 2 |
|
3 | 3 | describe('get-preview-group-lengths', () => {
|
| 4 | + it('Should get preview id', () => { |
| 5 | + const previewId = getPreviewId(40, 'orders'); |
| 6 | + expect(previewId).toEqual('40.orders'); |
| 7 | + }); |
4 | 8 | it('With empty list', () => {
|
5 | 9 | const result = getPreviewGroupArea([]);
|
6 | 10 | expect(result).toEqual({});
|
7 | 11 | });
|
8 | 12 | it('With single field with preview variant', () => {
|
9 | 13 | const result = getPreviewGroupArea([{ variant: 'preview', name: 'orderId' }]);
|
10 |
| - expect(result).toEqual({ orderId: { height: 1, width: 0 } }); |
| 14 | + expect(result).toEqual({ ['0.orderId']: { height: 1, width: 0 } }); |
11 | 15 | });
|
12 | 16 | it('With all fields with preview variant', () => {
|
13 | 17 | const result = getPreviewGroupArea([
|
14 | 18 | { variant: 'preview', name: 'orderId' },
|
15 | 19 | { variant: 'preview', name: 'shippingAddress' },
|
16 | 20 | { variant: 'preview', name: 'transactionId' },
|
17 | 21 | ]);
|
18 |
| - expect(result).toEqual({ orderId: { height: 3, width: 0 } }); |
| 22 | + expect(result).toEqual({ ['0.orderId']: { height: 3, width: 0 } }); |
| 23 | + }); |
| 24 | + it('With all fields with preview variant, with duplicate names', () => { |
| 25 | + const result = getPreviewGroupArea([ |
| 26 | + { variant: 'preview', name: 'orderId' }, |
| 27 | + { variant: 'preview', name: 'orderId' }, |
| 28 | + { variant: 'preview', name: 'orderId' }, |
| 29 | + ]); |
| 30 | + expect(result).toEqual({ ['0.orderId']: { height: 3, width: 0 } }); |
19 | 31 | });
|
20 | 32 | it('With variable number of glyphs', () => {
|
21 | 33 | const result = getPreviewGroupArea([
|
22 | 34 | { variant: 'preview', name: 'orderId', glyphs: ['key', 'key'] },
|
23 | 35 | { variant: 'preview', name: 'shippingAddress', glyphs: ['key', 'key', 'key', 'key'] },
|
24 | 36 | { variant: 'preview', name: 'transactionId' },
|
25 | 37 | ]);
|
26 |
| - expect(result).toEqual({ orderId: { height: 3, width: 4 } }); |
| 38 | + expect(result).toEqual({ ['0.orderId']: { height: 3, width: 4 } }); |
27 | 39 | });
|
28 | 40 | it('With some fields with preview variant', () => {
|
29 | 41 | const result = getPreviewGroupArea([
|
30 | 42 | { variant: 'preview', name: 'orderId', glyphs: ['key'] },
|
31 | 43 | { name: 'shippingAddress' },
|
32 | 44 | { variant: 'preview', name: 'transactionId' },
|
33 | 45 | ]);
|
34 |
| - expect(result).toEqual({ orderId: { height: 1, width: 1 }, transactionId: { height: 1, width: 0 } }); |
| 46 | + expect(result).toEqual({ ['0.orderId']: { height: 1, width: 1 }, ['2.transactionId']: { height: 1, width: 0 } }); |
35 | 47 | });
|
36 | 48 | });
|
0 commit comments