|
1 | 1 | import { Duration, Stack } from '@aws-cdk/core';
|
2 |
| -import { Alarm, AlarmWidget, Color, GraphWidget, GraphWidgetView, LegendPosition, LogQueryWidget, Metric, Shading, SingleValueWidget, LogQueryVisualizationType } from '../lib'; |
| 2 | +import { Alarm, AlarmWidget, Color, GraphWidget, GraphWidgetView, LegendPosition, LogQueryWidget, Metric, Shading, SingleValueWidget, LogQueryVisualizationType, CustomWidget } from '../lib'; |
3 | 3 |
|
4 | 4 | describe('Graphs', () => {
|
5 | 5 | test('add stacked property to graphs', () => {
|
@@ -348,6 +348,71 @@ describe('Graphs', () => {
|
348 | 348 |
|
349 | 349 | });
|
350 | 350 |
|
| 351 | + test('custom widget basic', () => { |
| 352 | + // GIVEN |
| 353 | + const stack = new Stack(); |
| 354 | + |
| 355 | + // WHEN |
| 356 | + const widget = new CustomWidget({ |
| 357 | + functionArn: 'arn:aws:lambda:us-east-1:123456789:function:customwidgetfunction', |
| 358 | + title: 'CustomWidget', |
| 359 | + }); |
| 360 | + |
| 361 | + // THEN |
| 362 | + expect(stack.resolve(widget.toJson())).toEqual([{ |
| 363 | + type: 'custom', |
| 364 | + width: 6, |
| 365 | + height: 6, |
| 366 | + properties: { |
| 367 | + title: 'CustomWidget', |
| 368 | + endpoint: 'arn:aws:lambda:us-east-1:123456789:function:customwidgetfunction', |
| 369 | + updateOn: { |
| 370 | + refresh: true, |
| 371 | + resize: true, |
| 372 | + timeRange: true, |
| 373 | + }, |
| 374 | + }, |
| 375 | + }]); |
| 376 | + }); |
| 377 | + |
| 378 | + test('custom widget full config', () => { |
| 379 | + // GIVEN |
| 380 | + const stack = new Stack(); |
| 381 | + |
| 382 | + // WHEN |
| 383 | + const widget = new CustomWidget({ |
| 384 | + functionArn: 'arn:aws:lambda:us-east-1:123456789:function:customwidgetfunction', |
| 385 | + title: 'CustomWidget', |
| 386 | + height: 1, |
| 387 | + width: 1, |
| 388 | + params: { |
| 389 | + any: 'param', |
| 390 | + }, |
| 391 | + updateOnRefresh: false, |
| 392 | + updateOnResize: false, |
| 393 | + updateOnTimeRangeChange: false, |
| 394 | + }); |
| 395 | + |
| 396 | + // THEN |
| 397 | + expect(stack.resolve(widget.toJson())).toEqual([{ |
| 398 | + type: 'custom', |
| 399 | + width: 1, |
| 400 | + height: 1, |
| 401 | + properties: { |
| 402 | + title: 'CustomWidget', |
| 403 | + endpoint: 'arn:aws:lambda:us-east-1:123456789:function:customwidgetfunction', |
| 404 | + params: { |
| 405 | + any: 'param', |
| 406 | + }, |
| 407 | + updateOn: { |
| 408 | + refresh: false, |
| 409 | + resize: false, |
| 410 | + timeRange: false, |
| 411 | + }, |
| 412 | + }, |
| 413 | + }]); |
| 414 | + }); |
| 415 | + |
351 | 416 | test('add annotations to graph', () => {
|
352 | 417 | // WHEN
|
353 | 418 | const stack = new Stack();
|
|
0 commit comments