|
6 | 6 | "testing" |
7 | 7 |
|
8 | 8 | "github.com/mendixlabs/mxcli/mdl/ast" |
| 9 | + "github.com/mendixlabs/mxcli/model" |
9 | 10 | "github.com/mendixlabs/mxcli/sdk/microflows" |
10 | 11 | ) |
11 | 12 |
|
@@ -310,3 +311,131 @@ func TestInheritanceSplitCaptionApplied(t *testing.T) { |
310 | 311 | t.Errorf("inheritance split caption: got %q, want %q", split.Caption, "Customer type?") |
311 | 312 | } |
312 | 313 | } |
| 314 | + |
| 315 | +func TestFreeAnnotationBeforePositionStaysUnattached(t *testing.T) { |
| 316 | + body := []ast.MicroflowStatement{ |
| 317 | + &ast.LogStmt{ |
| 318 | + Level: ast.LogInfo, |
| 319 | + Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "message"}, |
| 320 | + Annotations: &ast.ActivityAnnotations{ |
| 321 | + FreeAnnotation: "free synthetic note", |
| 322 | + Position: &ast.Position{X: 120, Y: 240}, |
| 323 | + }, |
| 324 | + }, |
| 325 | + } |
| 326 | + |
| 327 | + fb := &flowBuilder{posX: 100, posY: 100, spacing: HorizontalSpacing} |
| 328 | + oc := fb.buildFlowGraph(body, nil) |
| 329 | + |
| 330 | + freeAnnotations := collectFreeAnnotations(oc) |
| 331 | + if len(freeAnnotations) != 1 || freeAnnotations[0] != "free synthetic note" { |
| 332 | + t.Fatalf("free annotations = %#v, want one free note", freeAnnotations) |
| 333 | + } |
| 334 | + |
| 335 | + attached := buildAnnotationsByTarget(oc) |
| 336 | + for activityID, captions := range attached { |
| 337 | + for _, caption := range captions { |
| 338 | + if caption == "free synthetic note" { |
| 339 | + t.Fatalf("free note was attached to activity %s", activityID) |
| 340 | + } |
| 341 | + } |
| 342 | + } |
| 343 | +} |
| 344 | + |
| 345 | +func TestMultipleFreeAnnotationsBeforePositionStayUnattached(t *testing.T) { |
| 346 | + body := []ast.MicroflowStatement{ |
| 347 | + &ast.LogStmt{ |
| 348 | + Level: ast.LogInfo, |
| 349 | + Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "message"}, |
| 350 | + Annotations: &ast.ActivityAnnotations{ |
| 351 | + FreeAnnotations: []string{"first free note", "second free note"}, |
| 352 | + Position: &ast.Position{X: 120, Y: 240}, |
| 353 | + }, |
| 354 | + }, |
| 355 | + } |
| 356 | + |
| 357 | + fb := &flowBuilder{posX: 100, posY: 100, spacing: HorizontalSpacing} |
| 358 | + oc := fb.buildFlowGraph(body, nil) |
| 359 | + |
| 360 | + freeAnnotations := collectFreeAnnotations(oc) |
| 361 | + want := []string{"first free note", "second free note"} |
| 362 | + if len(freeAnnotations) != len(want) { |
| 363 | + t.Fatalf("free annotations = %#v, want %#v", freeAnnotations, want) |
| 364 | + } |
| 365 | + for i, wantText := range want { |
| 366 | + if freeAnnotations[i] != wantText { |
| 367 | + t.Fatalf("free annotation %d = %q, want %q", i, freeAnnotations[i], wantText) |
| 368 | + } |
| 369 | + } |
| 370 | +} |
| 371 | + |
| 372 | +func TestIfBranchActionCaptionStaysWithAction(t *testing.T) { |
| 373 | + ifStmt := &ast.IfStmt{ |
| 374 | + Condition: &ast.LiteralExpr{Kind: ast.LiteralBoolean, Value: true}, |
| 375 | + ThenBody: []ast.MicroflowStatement{ |
| 376 | + &ast.LogStmt{ |
| 377 | + Level: ast.LogInfo, |
| 378 | + Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "branch"}, |
| 379 | + Annotations: &ast.ActivityAnnotations{Caption: "Branch activity"}, |
| 380 | + }, |
| 381 | + }, |
| 382 | + } |
| 383 | + |
| 384 | + fb := &flowBuilder{posX: 100, posY: 100, spacing: HorizontalSpacing} |
| 385 | + fb.buildFlowGraph([]ast.MicroflowStatement{ifStmt}, nil) |
| 386 | + |
| 387 | + for _, obj := range fb.objects { |
| 388 | + activity, ok := obj.(*microflows.ActionActivity) |
| 389 | + if !ok { |
| 390 | + continue |
| 391 | + } |
| 392 | + if _, ok := activity.Action.(*microflows.LogMessageAction); ok { |
| 393 | + if activity.Caption != "Branch activity" { |
| 394 | + t.Fatalf("branch activity caption = %q, want Branch activity", activity.Caption) |
| 395 | + } |
| 396 | + if activity.AutoGenerateCaption { |
| 397 | + t.Fatal("branch activity caption should not be autogenerated") |
| 398 | + } |
| 399 | + return |
| 400 | + } |
| 401 | + } |
| 402 | + t.Fatal("expected branch log activity") |
| 403 | +} |
| 404 | + |
| 405 | +func TestIfBranchActionAnnotationStaysWithAction(t *testing.T) { |
| 406 | + ifStmt := &ast.IfStmt{ |
| 407 | + Condition: &ast.LiteralExpr{Kind: ast.LiteralBoolean, Value: true}, |
| 408 | + ThenBody: []ast.MicroflowStatement{ |
| 409 | + &ast.LogStmt{ |
| 410 | + Level: ast.LogInfo, |
| 411 | + Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "branch"}, |
| 412 | + Annotations: &ast.ActivityAnnotations{ |
| 413 | + AnnotationText: "Branch note", |
| 414 | + }, |
| 415 | + }, |
| 416 | + }, |
| 417 | + } |
| 418 | + |
| 419 | + fb := &flowBuilder{posX: 100, posY: 100, spacing: HorizontalSpacing} |
| 420 | + oc := fb.buildFlowGraph([]ast.MicroflowStatement{ifStmt}, nil) |
| 421 | + |
| 422 | + var logID model.ID |
| 423 | + for _, obj := range oc.Objects { |
| 424 | + activity, ok := obj.(*microflows.ActionActivity) |
| 425 | + if !ok { |
| 426 | + continue |
| 427 | + } |
| 428 | + if _, ok := activity.Action.(*microflows.LogMessageAction); ok { |
| 429 | + logID = activity.ID |
| 430 | + break |
| 431 | + } |
| 432 | + } |
| 433 | + if logID == "" { |
| 434 | + t.Fatal("expected branch log activity") |
| 435 | + } |
| 436 | + |
| 437 | + attached := buildAnnotationsByTarget(oc) |
| 438 | + if got := attached[logID]; len(got) != 1 || got[0] != "Branch note" { |
| 439 | + t.Fatalf("branch log annotations = %#v, want [Branch note]", got) |
| 440 | + } |
| 441 | +} |
0 commit comments