|
| 1 | +import sortMenu from '../sortMenu'; |
| 2 | + |
| 3 | +describe('sortMenu', () => { |
| 4 | + it('modifies original array to follow the group, then name order provided', () => { |
| 5 | + const initialArray = [ |
| 6 | + {props: {group: 'DEV', name: 'Inspector'}}, |
| 7 | + {props: {group: 'DEV', name: 'JSON'}}, |
| 8 | + ]; |
| 9 | + const orderProp = [{group: 'DEV', name: 'JSON'}, {group: 'DEV', name: 'Inspector'}]; |
| 10 | + sortMenu(initialArray, orderProp); |
| 11 | + |
| 12 | + expect(initialArray[0].props.name).toBe('JSON'); |
| 13 | + expect(initialArray[1].props.name).toBe('Inspector'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('sorts the array by group, then by name', () => { |
| 17 | + const initialArray = [ |
| 18 | + {props: {group: 'Structure', name: 'Create'}}, |
| 19 | + {props: {group: 'Structure', name: 'Subplots'}}, |
| 20 | + {props: {group: 'Style', name: 'Color Bars'}}, |
| 21 | + {props: {group: 'Style', name: 'Annotation'}}, |
| 22 | + {props: {group: 'DEV', name: 'Inspector'}}, |
| 23 | + {props: {group: 'DEV', name: 'JSON'}}, |
| 24 | + ]; |
| 25 | + |
| 26 | + const orderProp = [ |
| 27 | + {group: 'DEV', name: 'JSON'}, |
| 28 | + {group: 'DEV', name: 'Inspector'}, |
| 29 | + {group: 'Structure', name: 'Subplots'}, |
| 30 | + {group: 'Structure', name: 'Create'}, |
| 31 | + {group: 'Style', name: 'Color Bars'}, |
| 32 | + {group: 'Style', name: 'Annotation'}, |
| 33 | + ]; |
| 34 | + |
| 35 | + sortMenu(initialArray, orderProp); |
| 36 | + expect(initialArray[0].props.group).toBe('DEV'); |
| 37 | + expect(initialArray[0].props.name).toBe('JSON'); |
| 38 | + expect(initialArray[1].props.group).toBe('DEV'); |
| 39 | + expect(initialArray[1].props.name).toBe('Inspector'); |
| 40 | + expect(initialArray[2].props.group).toBe('Structure'); |
| 41 | + expect(initialArray[2].props.name).toBe('Subplots'); |
| 42 | + expect(initialArray[3].props.group).toBe('Structure'); |
| 43 | + expect(initialArray[3].props.name).toBe('Create'); |
| 44 | + expect(initialArray[4].props.group).toBe('Style'); |
| 45 | + expect(initialArray[4].props.name).toBe('Color Bars'); |
| 46 | + expect(initialArray[5].props.group).toBe('Style'); |
| 47 | + expect(initialArray[5].props.name).toBe('Annotation'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('puts not mentionned panels to the bottom of list and sorts alphabetically', () => { |
| 51 | + const initialArray = [ |
| 52 | + {props: {group: 'DEV', name: 'JSON'}}, |
| 53 | + {props: {group: 'DEV', name: 'Inspector'}}, |
| 54 | + {props: {group: 'Structure', name: 'Create'}}, |
| 55 | + {props: {group: 'Structure', name: 'Subplots'}}, |
| 56 | + {props: {group: 'Style', name: 'Color Bars'}}, |
| 57 | + {props: {group: 'Style', name: 'Annotation'}}, |
| 58 | + ]; |
| 59 | + const orderProp = [ |
| 60 | + {group: 'Structure', name: 'Subplots'}, |
| 61 | + {group: 'Structure', name: 'Create'}, |
| 62 | + {group: 'Style', name: 'Color Bars'}, |
| 63 | + {group: 'Style', name: 'Annotation'}, |
| 64 | + ]; |
| 65 | + |
| 66 | + sortMenu(initialArray, orderProp); |
| 67 | + expect(initialArray[0].props.group).toBe('Structure'); |
| 68 | + expect(initialArray[0].props.name).toBe('Subplots'); |
| 69 | + expect(initialArray[1].props.group).toBe('Structure'); |
| 70 | + expect(initialArray[1].props.name).toBe('Create'); |
| 71 | + expect(initialArray[2].props.group).toBe('Style'); |
| 72 | + expect(initialArray[2].props.name).toBe('Color Bars'); |
| 73 | + expect(initialArray[3].props.group).toBe('Style'); |
| 74 | + expect(initialArray[3].props.name).toBe('Annotation'); |
| 75 | + expect(initialArray[4].props.group).toBe('DEV'); |
| 76 | + expect(initialArray[4].props.name).toBe('Inspector'); |
| 77 | + expect(initialArray[5].props.group).toBe('DEV'); |
| 78 | + expect(initialArray[5].props.name).toBe('JSON'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('orders not mentionned subpanels at the end, alphabetically', () => { |
| 82 | + const initialArray = [ |
| 83 | + {props: {group: 'Style', name: 'General'}}, |
| 84 | + {props: {group: 'Style', name: 'Traces'}}, |
| 85 | + {props: {group: 'Style', name: 'Axes'}}, |
| 86 | + {props: {group: 'Structure', name: 'Create'}}, |
| 87 | + ]; |
| 88 | + const orderProp = [{group: 'Style', name: 'Traces'}, {group: 'Structure', name: 'Create'}]; |
| 89 | + |
| 90 | + sortMenu(initialArray, orderProp); |
| 91 | + expect(initialArray[0].props.group).toBe('Style'); |
| 92 | + expect(initialArray[0].props.name).toBe('Traces'); |
| 93 | + expect(initialArray[1].props.group).toBe('Style'); |
| 94 | + expect(initialArray[1].props.name).toBe('Axes'); |
| 95 | + expect(initialArray[2].props.group).toBe('Style'); |
| 96 | + expect(initialArray[2].props.name).toBe('General'); |
| 97 | + expect(initialArray[3].props.group).toBe('Structure'); |
| 98 | + expect(initialArray[3].props.name).toBe('Create'); |
| 99 | + }); |
| 100 | + |
| 101 | + it('ignores non existent panel groups', () => { |
| 102 | + const initialArray = [ |
| 103 | + {props: {group: 'Structure', name: 'Create'}}, |
| 104 | + {props: {group: 'Structure', name: 'Subplots'}}, |
| 105 | + {props: {group: 'Style', name: 'Color Bars'}}, |
| 106 | + {props: {group: 'Style', name: 'Annotation'}}, |
| 107 | + ]; |
| 108 | + |
| 109 | + const orderProp = [ |
| 110 | + {group: 'Non Existent', name: 'Subplots'}, |
| 111 | + {group: 'Structure', name: 'Create'}, |
| 112 | + {group: 'Style', name: 'Color Bars'}, |
| 113 | + {group: 'Style', name: 'Annotation'}, |
| 114 | + ]; |
| 115 | + |
| 116 | + sortMenu(initialArray, orderProp); |
| 117 | + expect(initialArray[0].props.group).toBe('Structure'); |
| 118 | + expect(initialArray[0].props.name).toBe('Create'); |
| 119 | + expect(initialArray[1].props.group).toBe('Structure'); |
| 120 | + expect(initialArray[1].props.name).toBe('Subplots'); |
| 121 | + expect(initialArray[2].props.group).toBe('Style'); |
| 122 | + expect(initialArray[2].props.name).toBe('Color Bars'); |
| 123 | + expect(initialArray[3].props.group).toBe('Style'); |
| 124 | + expect(initialArray[3].props.name).toBe('Annotation'); |
| 125 | + }); |
| 126 | + |
| 127 | + it('ignores non existent panel names', () => { |
| 128 | + const initialArray = [ |
| 129 | + {props: {group: 'Structure', name: 'Subplots'}}, |
| 130 | + {props: {group: 'Structure', name: 'Create'}}, |
| 131 | + {props: {group: 'Style', name: 'Color Bars'}}, |
| 132 | + {props: {group: 'Style', name: 'Annotation'}}, |
| 133 | + ]; |
| 134 | + |
| 135 | + const orderProp = [ |
| 136 | + {group: 'Structure', name: 'Non Existent'}, |
| 137 | + {group: 'Style', name: 'Color Bars'}, |
| 138 | + {group: 'Style', name: 'Annotation'}, |
| 139 | + ]; |
| 140 | + |
| 141 | + sortMenu(initialArray, orderProp); |
| 142 | + expect(initialArray[0].props.group).toBe('Style'); |
| 143 | + expect(initialArray[0].props.name).toBe('Color Bars'); |
| 144 | + expect(initialArray[1].props.group).toBe('Style'); |
| 145 | + expect(initialArray[1].props.name).toBe('Annotation'); |
| 146 | + expect(initialArray[2].props.group).toBe('Structure'); |
| 147 | + expect(initialArray[2].props.name).toBe('Create'); |
| 148 | + expect(initialArray[3].props.group).toBe('Structure'); |
| 149 | + expect(initialArray[3].props.name).toBe('Subplots'); |
| 150 | + }); |
| 151 | + |
| 152 | + it('ignores invalid combinations', () => { |
| 153 | + const initialArray = [ |
| 154 | + {props: {group: 'Structure', name: 'Subplots'}}, |
| 155 | + {props: {group: 'Structure', name: 'Create'}}, |
| 156 | + {props: {group: 'Style', name: 'Color Bars'}}, |
| 157 | + {props: {group: 'Style', name: 'Annotation'}}, |
| 158 | + ]; |
| 159 | + |
| 160 | + const orderProp = [ |
| 161 | + {group: 'Structure', name: 'Annotation'}, |
| 162 | + {group: 'Style', name: 'Color Bars'}, |
| 163 | + {group: 'Style', name: 'Annotation'}, |
| 164 | + ]; |
| 165 | + |
| 166 | + sortMenu(initialArray, orderProp); |
| 167 | + expect(initialArray[0].props.group).toBe('Style'); |
| 168 | + expect(initialArray[0].props.name).toBe('Color Bars'); |
| 169 | + expect(initialArray[1].props.group).toBe('Style'); |
| 170 | + expect(initialArray[1].props.name).toBe('Annotation'); |
| 171 | + expect(initialArray[2].props.group).toBe('Structure'); |
| 172 | + expect(initialArray[2].props.name).toBe('Create'); |
| 173 | + expect(initialArray[3].props.group).toBe('Structure'); |
| 174 | + expect(initialArray[3].props.name).toBe('Subplots'); |
| 175 | + }); |
| 176 | +}); |
0 commit comments