|
| 1 | +import omit from 'lodash/omit'; |
| 2 | + |
1 | 3 | import { CARD_TYPES, BAR_CHART_TYPES } from '../..'; |
2 | 4 |
|
3 | 5 | import { |
@@ -266,6 +268,14 @@ describe('editorUtils', () => { |
266 | 268 | }); |
267 | 269 | }); |
268 | 270 | describe('handleDataSeriesChange', () => { |
| 271 | + it('should just return cardConfig if there is no Type', () => { |
| 272 | + const newCard = handleDataSeriesChange( |
| 273 | + [], |
| 274 | + omit(mockTimeSeriesCard, 'type') |
| 275 | + ); |
| 276 | + expect(newCard).toEqual(omit(mockTimeSeriesCard, 'type')); |
| 277 | + }); |
| 278 | + |
269 | 279 | it('should correctly format the data in Timeseries', () => { |
270 | 280 | const selectedItems = [ |
271 | 281 | { id: 'key1', text: 'Key 1' }, |
@@ -322,8 +332,184 @@ describe('editorUtils', () => { |
322 | 332 | type: 'VALUE', |
323 | 333 | }); |
324 | 334 | }); |
| 335 | + |
| 336 | + it('should correctly format the data in Image Card', () => { |
| 337 | + const mockImageCard = { |
| 338 | + type: CARD_TYPES.IMAGE, |
| 339 | + content: { |
| 340 | + hotspots: [ |
| 341 | + { |
| 342 | + title: 'elevators', |
| 343 | + content: { |
| 344 | + attributes: [ |
| 345 | + { |
| 346 | + dataSourceId: 'temp_last', |
| 347 | + label: '{high} temp', |
| 348 | + unit: '{unitVar}', |
| 349 | + }, |
| 350 | + { |
| 351 | + dataSourceId: 'elevators', |
| 352 | + label: 'Elevators', |
| 353 | + unit: 'floor', |
| 354 | + }, |
| 355 | + ], |
| 356 | + }, |
| 357 | + }, |
| 358 | + ], |
| 359 | + }, |
| 360 | + thresholds: [ |
| 361 | + { |
| 362 | + dataSourceId: 'temp_last', |
| 363 | + comparison: '>=', |
| 364 | + color: '#da1e28', |
| 365 | + icon: 'Checkmark', |
| 366 | + value: 98, |
| 367 | + }, |
| 368 | + ], |
| 369 | + }; |
| 370 | + const selectedItems = [ |
| 371 | + { dataSourceId: 'temp_last', label: '{high} temp', unit: '{unitVar}' }, |
| 372 | + { dataSourceId: 'elevators', label: 'Elevators', unit: '°' }, |
| 373 | + { dataSourceId: 'pressure', label: 'Pressure', unit: 'psi' }, |
| 374 | + ]; |
| 375 | + const newCard = handleDataSeriesChange( |
| 376 | + selectedItems, |
| 377 | + mockImageCard, |
| 378 | + null, |
| 379 | + 0 |
| 380 | + ); |
| 381 | + |
| 382 | + expect(newCard).toEqual({ |
| 383 | + type: CARD_TYPES.IMAGE, |
| 384 | + content: { |
| 385 | + hotspots: [ |
| 386 | + { |
| 387 | + title: 'elevators', |
| 388 | + content: { |
| 389 | + attributes: [ |
| 390 | + { |
| 391 | + dataSourceId: 'temp_last', |
| 392 | + label: '{high} temp', |
| 393 | + unit: '{unitVar}', |
| 394 | + }, |
| 395 | + { |
| 396 | + dataSourceId: 'elevators', |
| 397 | + label: 'Elevators', |
| 398 | + unit: '°', |
| 399 | + }, |
| 400 | + { |
| 401 | + dataSourceId: 'pressure', |
| 402 | + label: 'Pressure', |
| 403 | + unit: 'psi', |
| 404 | + }, |
| 405 | + ], |
| 406 | + }, |
| 407 | + }, |
| 408 | + ], |
| 409 | + }, |
| 410 | + thresholds: [ |
| 411 | + { |
| 412 | + dataSourceId: 'temp_last', |
| 413 | + comparison: '>=', |
| 414 | + color: '#da1e28', |
| 415 | + icon: 'Checkmark', |
| 416 | + value: 98, |
| 417 | + }, |
| 418 | + ], |
| 419 | + }); |
| 420 | + }); |
325 | 421 | }); |
326 | 422 | describe('handleDataItemEdit', () => { |
| 423 | + it('should correctly format the data in Image Card', () => { |
| 424 | + const mockImageCard = { |
| 425 | + type: CARD_TYPES.IMAGE, |
| 426 | + content: { |
| 427 | + hotspots: [ |
| 428 | + { |
| 429 | + title: 'elevators', |
| 430 | + content: { |
| 431 | + attributes: [ |
| 432 | + { |
| 433 | + dataSourceId: 'temp_last', |
| 434 | + label: '{high} temp', |
| 435 | + unit: '{unitVar}', |
| 436 | + }, |
| 437 | + ], |
| 438 | + }, |
| 439 | + }, |
| 440 | + ], |
| 441 | + }, |
| 442 | + }; |
| 443 | + const editDataItem = { |
| 444 | + dataSourceId: 'temp_last', |
| 445 | + label: '{high} temps', |
| 446 | + unit: 'degrees', |
| 447 | + thresholds: [ |
| 448 | + { |
| 449 | + dataSourceId: 'temp_last', |
| 450 | + comparison: '>', |
| 451 | + color: '#da1e28', |
| 452 | + icon: 'Checkmark', |
| 453 | + value: 98, |
| 454 | + }, |
| 455 | + { |
| 456 | + dataSourceId: 'temp_last', |
| 457 | + comparison: '=', |
| 458 | + color: '#ffffff', |
| 459 | + icon: 'Checkmark', |
| 460 | + value: 100, |
| 461 | + }, |
| 462 | + ], |
| 463 | + }; |
| 464 | + let newCard = handleDataItemEdit(editDataItem, mockImageCard, null, 0); |
| 465 | + |
| 466 | + expect(newCard).toEqual({ |
| 467 | + type: CARD_TYPES.IMAGE, |
| 468 | + content: { |
| 469 | + hotspots: [ |
| 470 | + { |
| 471 | + title: 'elevators', |
| 472 | + content: { |
| 473 | + attributes: [ |
| 474 | + { |
| 475 | + dataSourceId: 'temp_last', |
| 476 | + label: '{high} temps', |
| 477 | + unit: 'degrees', |
| 478 | + }, |
| 479 | + ], |
| 480 | + }, |
| 481 | + }, |
| 482 | + ], |
| 483 | + }, |
| 484 | + thresholds: [ |
| 485 | + { |
| 486 | + dataSourceId: 'temp_last', |
| 487 | + comparison: '>', |
| 488 | + color: '#da1e28', |
| 489 | + icon: 'Checkmark', |
| 490 | + value: 98, |
| 491 | + }, |
| 492 | + { |
| 493 | + dataSourceId: 'temp_last', |
| 494 | + comparison: '=', |
| 495 | + color: '#ffffff', |
| 496 | + icon: 'Checkmark', |
| 497 | + value: 100, |
| 498 | + }, |
| 499 | + ], |
| 500 | + }); |
| 501 | + |
| 502 | + const withoutThresholds = omit(mockImageCard, 'thresholds'); |
| 503 | + newCard = handleDataSeriesChange( |
| 504 | + editDataItem, |
| 505 | + withoutThresholds, |
| 506 | + null, |
| 507 | + 0 |
| 508 | + ); |
| 509 | + |
| 510 | + expect(newCard).toEqual(withoutThresholds); |
| 511 | + }); |
| 512 | + |
327 | 513 | it('should correctly format the data in Timeseries', () => { |
328 | 514 | const editDataItem = { |
329 | 515 | dataSourceId: 'torque', |
|
0 commit comments