forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_container_context_test.go
More file actions
88 lines (80 loc) · 2.8 KB
/
data_container_context_test.go
File metadata and controls
88 lines (80 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: Apache-2.0
// Tests for data container context hints (upstream issue #123).
package executor
import (
"bytes"
"strings"
"testing"
)
func TestOutputDataContainerContext_DataView(t *testing.T) {
var buf bytes.Buffer
outputDataContainerContext(&buf, " ", "dvOrder", "OrderManagement.PurchaseOrder", false)
got := buf.String()
expected := " -- Context: $currentObject (OrderManagement.PurchaseOrder)\n"
if got != expected {
t.Errorf("DataView context:\ngot: %q\nwant: %q", got, expected)
}
}
func TestOutputDataContainerContext_ListContainer(t *testing.T) {
var buf bytes.Buffer
outputDataContainerContext(&buf, " ", "dgOrders", "OrderManagement.PurchaseOrder", true)
got := buf.String()
expected := " -- Context: $currentObject (OrderManagement.PurchaseOrder), $dgOrders (selection)\n"
if got != expected {
t.Errorf("List container context:\ngot: %q\nwant: %q", got, expected)
}
}
func TestOutputDataContainerContext_EmptyEntity(t *testing.T) {
var buf bytes.Buffer
outputDataContainerContext(&buf, " ", "dv1", "", false)
got := buf.String()
if got != "" {
t.Errorf("Expected no output for empty entity, got: %q", got)
}
}
func TestOutputDataContainerContext_ListNoName(t *testing.T) {
var buf bytes.Buffer
outputDataContainerContext(&buf, " ", "", "Module.Entity", true)
got := buf.String()
// Should only show $currentObject, no selection variable when widget has no name
expected := " -- Context: $currentObject (Module.Entity)\n"
if got != expected {
t.Errorf("List container without name:\ngot: %q\nwant: %q", got, expected)
}
}
func TestOutputWidgetMDLV3_DataViewWithContext(t *testing.T) {
buf := &bytes.Buffer{}
e := New(buf)
w := rawWidget{
Type: "Forms$DataView",
Name: "dvOrder",
EntityContext: "OrderManagement.PurchaseOrder",
DataSource: &rawDataSource{Type: "parameter", Reference: "Order"},
Children: []rawWidget{
{Type: "Forms$TextBox", Name: "txtName", Content: "Name"},
},
}
e.outputWidgetMDLV3(w, 0)
got := buf.String()
if !strings.Contains(got, "-- Context: $currentObject (OrderManagement.PurchaseOrder)") {
t.Errorf("DataView output should contain context comment, got:\n%s", got)
}
}
func TestOutputWidgetMDLV3_ListViewWithContext(t *testing.T) {
buf := &bytes.Buffer{}
e := New(buf)
w := rawWidget{
Type: "Forms$ListView",
Name: "lvItems",
EntityContext: "Module.Item",
DataSource: &rawDataSource{Type: "database", Reference: "Module.Item"},
Children: []rawWidget{
{Type: "Forms$TextBox", Name: "txtDesc", Content: "Description"},
},
}
e.outputWidgetMDLV3(w, 0)
got := buf.String()
if !strings.Contains(got, "-- Context: $currentObject (Module.Item), $lvItems (selection)") {
t.Errorf("ListView output should contain context comment with selection, got:\n%s", got)
}
}