|
4 | 4 | getAllowedImageEntries, |
5 | 5 | getPageTokenImageMap, |
6 | 6 | openImage, |
| 7 | + generateGrid3Guid, |
| 8 | + createSettingsXml, |
| 9 | + createFileMapXml, |
7 | 10 | } from '../src/processors/gridset/helpers'; |
8 | 11 |
|
9 | 12 | describe('Gridset helper APIs', () => { |
@@ -75,3 +78,136 @@ describe('Gridset helper APIs', () => { |
75 | 78 | expect(missing).toBeNull(); |
76 | 79 | }); |
77 | 80 | }); |
| 81 | + |
| 82 | +describe('Grid3 GUID Generation', () => { |
| 83 | + it('generateGrid3Guid generates a valid GUID format', () => { |
| 84 | + const guid = generateGrid3Guid(); |
| 85 | + // Check format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx |
| 86 | + const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; |
| 87 | + expect(guid).toMatch(guidRegex); |
| 88 | + }); |
| 89 | + |
| 90 | + it('generateGrid3Guid generates unique GUIDs', () => { |
| 91 | + const guid1 = generateGrid3Guid(); |
| 92 | + const guid2 = generateGrid3Guid(); |
| 93 | + const guid3 = generateGrid3Guid(); |
| 94 | + expect(guid1).not.toBe(guid2); |
| 95 | + expect(guid2).not.toBe(guid3); |
| 96 | + expect(guid1).not.toBe(guid3); |
| 97 | + }); |
| 98 | + |
| 99 | + it('generateGrid3Guid generates GUIDs with correct version and variant', () => { |
| 100 | + // Generate multiple GUIDs and check they all have version 4 and variant 1 |
| 101 | + for (let i = 0; i < 10; i++) { |
| 102 | + const guid = generateGrid3Guid(); |
| 103 | + const parts = guid.split('-'); |
| 104 | + // Version 4 is in the first character of the 3rd group |
| 105 | + expect(parts[2][0]).toBe('4'); |
| 106 | + // Variant 1 is in the first character of the 4th group (should be 8, 9, a, or b) |
| 107 | + expect(['8', '9', 'a', 'b']).toContain(parts[3][0].toLowerCase()); |
| 108 | + } |
| 109 | + }); |
| 110 | +}); |
| 111 | + |
| 112 | +describe('Grid3 Settings XML Builder', () => { |
| 113 | + it('createSettingsXml creates valid XML with default options', () => { |
| 114 | + const xml = createSettingsXml('Home'); |
| 115 | + expect(xml).toContain('<GridSetSettings'); |
| 116 | + expect(xml).toContain('<StartGrid>Home</StartGrid>'); |
| 117 | + expect(xml).toContain('<ScanEnabled>false</ScanEnabled>'); |
| 118 | + expect(xml).toContain('<HoverEnabled>false</HoverEnabled>'); |
| 119 | + expect(xml).toContain('<MouseclickEnabled>true</MouseclickEnabled>'); |
| 120 | + expect(xml).toContain('<Language>en-US</Language>'); |
| 121 | + }); |
| 122 | + |
| 123 | + it('createSettingsXml respects custom options', () => { |
| 124 | + const xml = createSettingsXml('MainMenu', { |
| 125 | + scanEnabled: true, |
| 126 | + scanTimeoutMs: 3000, |
| 127 | + hoverEnabled: true, |
| 128 | + hoverTimeoutMs: 1500, |
| 129 | + mouseclickEnabled: false, |
| 130 | + language: 'fr-FR', |
| 131 | + }); |
| 132 | + expect(xml).toContain('<StartGrid>MainMenu</StartGrid>'); |
| 133 | + expect(xml).toContain('<ScanEnabled>true</ScanEnabled>'); |
| 134 | + expect(xml).toContain('<ScanTimeoutMs>3000</ScanTimeoutMs>'); |
| 135 | + expect(xml).toContain('<HoverEnabled>true</HoverEnabled>'); |
| 136 | + expect(xml).toContain('<HoverTimeoutMs>1500</HoverTimeoutMs>'); |
| 137 | + expect(xml).toContain('<MouseclickEnabled>false</MouseclickEnabled>'); |
| 138 | + expect(xml).toContain('<Language>fr-FR</Language>'); |
| 139 | + }); |
| 140 | + |
| 141 | + it('createSettingsXml includes XML namespace', () => { |
| 142 | + const xml = createSettingsXml('Home'); |
| 143 | + expect(xml).toContain('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'); |
| 144 | + }); |
| 145 | + |
| 146 | + it('createSettingsXml handles partial options', () => { |
| 147 | + const xml = createSettingsXml('Home', { |
| 148 | + scanEnabled: true, |
| 149 | + language: 'de-DE', |
| 150 | + }); |
| 151 | + expect(xml).toContain('<ScanEnabled>true</ScanEnabled>'); |
| 152 | + expect(xml).toContain('<Language>de-DE</Language>'); |
| 153 | + // Should still have defaults for unspecified options |
| 154 | + expect(xml).toContain('<HoverEnabled>false</HoverEnabled>'); |
| 155 | + expect(xml).toContain('<MouseclickEnabled>true</MouseclickEnabled>'); |
| 156 | + }); |
| 157 | +}); |
| 158 | + |
| 159 | +describe('Grid3 FileMap XML Builder', () => { |
| 160 | + it('createFileMapXml creates valid XML with single grid', () => { |
| 161 | + const xml = createFileMapXml([{ name: 'Home', path: 'Grids\\Home\\grid.xml' }]); |
| 162 | + expect(xml).toContain('<FileMap'); |
| 163 | + expect(xml).toContain('<Entries>'); |
| 164 | + expect(xml).toContain('<Entry'); |
| 165 | + expect(xml).toContain('StaticFile="Grids\\Home\\grid.xml"'); |
| 166 | + }); |
| 167 | + |
| 168 | + it('createFileMapXml creates valid XML with multiple grids', () => { |
| 169 | + const xml = createFileMapXml([ |
| 170 | + { name: 'Home', path: 'Grids\\Home\\grid.xml' }, |
| 171 | + { name: 'Menu', path: 'Grids\\Menu\\grid.xml' }, |
| 172 | + { name: 'Settings', path: 'Grids\\Settings\\grid.xml' }, |
| 173 | + ]); |
| 174 | + expect(xml).toContain('StaticFile="Grids\\Home\\grid.xml"'); |
| 175 | + expect(xml).toContain('StaticFile="Grids\\Menu\\grid.xml"'); |
| 176 | + expect(xml).toContain('StaticFile="Grids\\Settings\\grid.xml"'); |
| 177 | + }); |
| 178 | + |
| 179 | + it('createFileMapXml includes dynamic files when provided', () => { |
| 180 | + const xml = createFileMapXml([ |
| 181 | + { |
| 182 | + name: 'Home', |
| 183 | + path: 'Grids\\Home\\grid.xml', |
| 184 | + dynamicFiles: ['dynamic1.xml', 'dynamic2.xml'], |
| 185 | + }, |
| 186 | + ]); |
| 187 | + expect(xml).toContain('<DynamicFiles>'); |
| 188 | + expect(xml).toContain('<File>dynamic1.xml</File>'); |
| 189 | + expect(xml).toContain('<File>dynamic2.xml</File>'); |
| 190 | + }); |
| 191 | + |
| 192 | + it('createFileMapXml omits DynamicFiles when empty', () => { |
| 193 | + const xml = createFileMapXml([ |
| 194 | + { name: 'Home', path: 'Grids\\Home\\grid.xml', dynamicFiles: [] }, |
| 195 | + ]); |
| 196 | + expect(xml).not.toContain('<DynamicFiles>'); |
| 197 | + }); |
| 198 | + |
| 199 | + it('createFileMapXml includes XML namespace', () => { |
| 200 | + const xml = createFileMapXml([{ name: 'Home', path: 'Grids\\Home\\grid.xml' }]); |
| 201 | + expect(xml).toContain('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'); |
| 202 | + }); |
| 203 | + |
| 204 | + it('createFileMapXml handles mixed grids with and without dynamic files', () => { |
| 205 | + const xml = createFileMapXml([ |
| 206 | + { name: 'Home', path: 'Grids\\Home\\grid.xml' }, |
| 207 | + { name: 'Menu', path: 'Grids\\Menu\\grid.xml', dynamicFiles: ['menu_dynamic.xml'] }, |
| 208 | + ]); |
| 209 | + expect(xml).toContain('StaticFile="Grids\\Home\\grid.xml"'); |
| 210 | + expect(xml).toContain('StaticFile="Grids\\Menu\\grid.xml"'); |
| 211 | + expect(xml).toContain('<File>menu_dynamic.xml</File>'); |
| 212 | + }); |
| 213 | +}); |
0 commit comments