FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix ut · SuperMap/iClient-JavaScript@14a28f5 · GitHub

Commit 14a28f5

Browse files
committed
fix ut
AI-GEN: 100% gpt-6-luna
1 parent 6315883 commit 14a28f5

1 file changed

Lines changed: 45 additions & 67 deletions

File tree

‎test/common/mapping/WebMapV3Spec.js‎

Lines changed: 45 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createWebMapV3Extending } from '../../../src/common/mapping/WebMapV3';
2+
import { createWebMapBaseExtending } from '../../../src/common/mapping/WebMapBase';
23
import { Events } from '../../../src/common/commontypes';
34

45
const mockCrsManager = {
@@ -132,34 +133,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
132133
let instance;
133134

134135
beforeEach(() => {
135-
// Create a minimal mock instance with the method
136-
instance = {
137-
_mapResourceInfo: {},
138-
_getLegendInfoByCatalog: function(catalog, res = []) {
139-
const { catalogType, children, showLegend, title, layersContent, id } = catalog;
140-
if (catalogType === 'group' && children) {
141-
children.forEach(child => {
142-
this._getLegendInfoByCatalog(child, res);
143-
});
144-
}
145-
if (catalogType === 'layer') {
146-
res.push({
147-
showLegend: showLegend !== false,
148-
id: layersContent || id,
149-
title: title
150-
});
151-
}
152-
},
153-
_getLegendInfos: function(_mapResourceInfo) {
154-
const mapResourceInfo = _mapResourceInfo || this._mapResourceInfo;
155-
const { catalogs = [] } = mapResourceInfo;
156-
const res = [];
157-
catalogs.forEach((item) => {
158-
this._getLegendInfoByCatalog(item, res);
159-
});
160-
return res;
161-
}
162-
};
136+
instance = createWebMapV3Instance();
163137
});
164138

165139
describe('_getLegendInfos', () => {
@@ -170,13 +144,13 @@ describe('WebMapV3 - _getLegendInfos', () => {
170144
catalogType: 'layer',
171145
title: 'Layer1',
172146
showLegend: true,
173-
layersContent: 'layer1'
147+
id: 'layer1'
174148
},
175149
{
176150
catalogType: 'layer',
177151
title: 'Layer2',
178152
showLegend: false,
179-
layersContent: 'layer2'
153+
id: 'layer2'
180154
}
181155
]
182156
};
@@ -199,7 +173,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
199173
catalogType: 'layer',
200174
title: 'ChildLayer',
201175
showLegend: true,
202-
layersContent: 'childLayer'
176+
id: 'childLayer'
203177
}
204178
]
205179
}
@@ -219,7 +193,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
219193
{
220194
catalogType: 'layer',
221195
title: 'Layer1',
222-
layersContent: 'layer1'
196+
id: 'layer1'
223197
}
224198
]
225199
};
@@ -231,21 +205,22 @@ describe('WebMapV3 - _getLegendInfos', () => {
231205
]);
232206
});
233207

234-
it('should use id when layersContent is not available', () => {
235-
instance._mapResourceInfo = {
208+
it('should use the provided map resource info', () => {
209+
const mapResourceInfo = {
236210
catalogs: [
237211
{
238212
catalogType: 'layer',
239213
title: 'Layer1',
214+
showLegend: true,
240215
id: 'layer1'
241216
}
242217
]
243218
};
244219

245-
const result = instance._getLegendInfos();
220+
const result = instance._getLegendInfos(mapResourceInfo);
246221

247222
expect(result).toEqual([
248-
{ showLegend: false, id: 'layer1', title: 'Layer1' }
223+
{ showLegend: true, id: 'layer1', title: 'Layer1' }
249224
]);
250225
});
251226

@@ -270,7 +245,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
270245
catalogType: 'layer',
271246
title: 'NestedLayer',
272247
showLegend: true,
273-
layersContent: 'nestedLayer'
248+
id: 'nestedLayer'
274249
}
275250
]
276251
}
@@ -301,7 +276,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
301276
catalogType: 'layer',
302277
title: 'DeepLayer',
303278
showLegend: false,
304-
layersContent: 'deepLayer'
279+
id: 'deepLayer'
305280
}
306281
]
307282
}
@@ -325,7 +300,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
325300
catalogType: 'other',
326301
title: 'Other',
327302
showLegend: true,
328-
layersContent: 'other'
303+
id: 'other'
329304
};
330305

331306
instance._getLegendInfoByCatalog(catalog, res);
@@ -339,7 +314,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
339314
catalogType: 'layer',
340315
title: 'TestLayer',
341316
showLegend: true,
342-
layersContent: 'testLayer'
317+
id: 'testLayer'
343318
};
344319

345320
instance._getLegendInfoByCatalog(catalog, res);
@@ -354,7 +329,7 @@ describe('WebMapV3 - _getLegendInfos', () => {
354329
const catalog = {
355330
catalogType: 'layer',
356331
title: 'TestLayer',
357-
layersContent: 'testLayer'
332+
id: 'testLayer'
358333
};
359334

360335
instance._getLegendInfoByCatalog(catalog, res);
@@ -379,38 +354,41 @@ describe('WebMapV3 - _getLegendInfos', () => {
379354
});
380355

381356
describe('getLegendInfos (WebMapV3)', () => {
382-
it('should call _handler._getLegendInfos through WebMapBase', () => {
383-
const webMapBase = {
384-
_handler: null,
385-
getLegendInfos: function() {
386-
return (this._handler && this._handler._getLegendInfos()) || [];
387-
}
388-
};
357+
let webMapBase;
389358

390-
const mockLegendInfos = [
391-
{ showLegend: true, id: 'layer1', title: 'Layer1' }
392-
];
393-
webMapBase._handler = {
394-
_getLegendInfos: jasmine.createSpy('_getLegendInfos').and.returnValue(mockLegendInfos)
395-
};
396-
397-
const result = webMapBase.getLegendInfos();
398-
399-
expect(webMapBase._handler._getLegendInfos).toHaveBeenCalled();
400-
expect(result).toEqual(mockLegendInfos);
359+
beforeEach(() => {
360+
const WebMapBase = createWebMapBaseExtending(Events, { mapRepo: {} });
361+
webMapBase = new WebMapBase({}, { target: 'map' });
401362
});
402363

403-
it('should return empty array when _handler is null', () => {
404-
const webMapBase = {
405-
_handler: null,
406-
getLegendInfos: function() {
407-
return (this._handler && this._handler._getLegendInfos()) || [];
408-
}
364+
it('should return legend info from the WebMapV3 handler', () => {
365+
instance._mapResourceInfo = {
366+
catalogs: [
367+
{
368+
catalogType: 'layer',
369+
id: 'layer1',
370+
title: 'Layer1',
371+
showLegend: true
372+
},
373+
{
374+
catalogType: 'layer',
375+
id: 'layer2',
376+
title: 'Layer2'
377+
}
378+
]
409379
};
380+
webMapBase._handler = instance;
410381

411-
const result = webMapBase.getLegendInfos();
382+
expect(webMapBase.getLegendInfos()).toEqual([
383+
{ showLegend: true, id: 'layer1', title: 'Layer1' },
384+
{ showLegend: false, id: 'layer2', title: 'Layer2' }
385+
]);
386+
});
412387

413-
expect(result).toEqual([]);
388+
it('should return an empty array when the handler is null', () => {
389+
webMapBase._handler = null;
390+
391+
expect(webMapBase.getLegendInfos()).toEqual([]);
414392
});
415393
});
416394
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL