|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +//go:build integration |
| 4 | + |
| 5 | +package executor |
| 6 | + |
| 7 | +import ( |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/mendixlabs/mxcli/mdl/ast" |
| 12 | +) |
| 13 | + |
| 14 | +// TestMxCheck_DataGridPage creates a page with a DATAGRID widget and verifies |
| 15 | +// mx check passes. This is a regression test for issue #6: DATAGRID was |
| 16 | +// completely unusable because placeholder IDs leaked during template |
| 17 | +// augmentation when the .mpk file added extra properties. |
| 18 | +func TestMxCheck_DataGridPage(t *testing.T) { |
| 19 | + if !mxCheckAvailable() { |
| 20 | + t.Skip("mx command not available") |
| 21 | + } |
| 22 | + |
| 23 | + env := setupTestEnv(t) |
| 24 | + defer env.teardown() |
| 25 | + |
| 26 | + // Create entity for the DataGrid |
| 27 | + entityName := testModule + ".MxCheckDGItem" |
| 28 | + env.registerCleanup("entity", entityName) |
| 29 | + |
| 30 | + if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY ` + entityName + ` ( |
| 31 | + Name: String(100), |
| 32 | + Description: String(500), |
| 33 | + Active: Boolean DEFAULT true |
| 34 | + );`); err != nil { |
| 35 | + t.Fatalf("Failed to create entity: %v", err) |
| 36 | + } |
| 37 | + |
| 38 | + // Create page with DATAGRID using DATABASE datasource and columns |
| 39 | + pageName := testModule + ".MxCheckDataGridPage" |
| 40 | + env.registerCleanup("page", pageName) |
| 41 | + |
| 42 | + createPageMDL := `CREATE PAGE ` + pageName + ` ( |
| 43 | + Title: 'DataGrid Check Test', |
| 44 | + Layout: Atlas_Core.Atlas_Default |
| 45 | + ) { |
| 46 | + LAYOUTGRID mainGrid { |
| 47 | + ROW row1 { |
| 48 | + COLUMN col1 (DesktopWidth: 12) { |
| 49 | + DATAGRID dg (DataSource: DATABASE ` + entityName + `) { |
| 50 | + COLUMN colName (Attribute: Name, Caption: 'Name') |
| 51 | + COLUMN colDesc (Attribute: Description, Caption: 'Description') |
| 52 | + COLUMN colActive (Attribute: Active, Caption: 'Active') |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + }` |
| 58 | + |
| 59 | + if err := env.executeMDL(createPageMDL); err != nil { |
| 60 | + t.Fatalf("Failed to create page with DATAGRID: %v", err) |
| 61 | + } |
| 62 | + |
| 63 | + // Disconnect to flush changes before mx check |
| 64 | + env.executor.Execute(&ast.DisconnectStmt{}) |
| 65 | + |
| 66 | + // Run mx check |
| 67 | + output, err := runMxCheck(t, env.projectPath) |
| 68 | + if err != nil { |
| 69 | + if strings.Contains(output, "error") || strings.Contains(output, "Error") { |
| 70 | + t.Errorf("mx check found errors for DATAGRID page:\n%s", output) |
| 71 | + } else { |
| 72 | + t.Logf("mx check output:\n%s", output) |
| 73 | + } |
| 74 | + } else { |
| 75 | + t.Logf("mx check passed for DATAGRID page:\n%s", output) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +// TestMxCheck_DataGridNoColumns creates a DATAGRID without explicit columns |
| 80 | +// (uses template defaults) and verifies the page is created successfully. |
| 81 | +// Note: template default columns reference attributes that don't exist on the |
| 82 | +// test entity, so mx check will report CE errors about missing attributes. |
| 83 | +// The key validation is that the page is created without placeholder ID leaks. |
| 84 | +func TestMxCheck_DataGridNoColumns(t *testing.T) { |
| 85 | + if !mxCheckAvailable() { |
| 86 | + t.Skip("mx command not available") |
| 87 | + } |
| 88 | + |
| 89 | + env := setupTestEnv(t) |
| 90 | + defer env.teardown() |
| 91 | + |
| 92 | + entityName := testModule + ".MxCheckDGNoColItem" |
| 93 | + env.registerCleanup("entity", entityName) |
| 94 | + |
| 95 | + if err := env.executeMDL(`CREATE OR MODIFY PERSISTENT ENTITY ` + entityName + ` ( |
| 96 | + Code: String(50), |
| 97 | + Value: Integer |
| 98 | + );`); err != nil { |
| 99 | + t.Fatalf("Failed to create entity: %v", err) |
| 100 | + } |
| 101 | + |
| 102 | + pageName := testModule + ".MxCheckDGNoColPage" |
| 103 | + env.registerCleanup("page", pageName) |
| 104 | + |
| 105 | + createPageMDL := `CREATE PAGE ` + pageName + ` ( |
| 106 | + Title: 'DataGrid No Columns Test', |
| 107 | + Layout: Atlas_Core.Atlas_Default |
| 108 | + ) { |
| 109 | + LAYOUTGRID mainGrid { |
| 110 | + ROW row1 { |
| 111 | + COLUMN col1 (DesktopWidth: 12) { |
| 112 | + DATAGRID dg (DataSource: DATABASE ` + entityName + `) |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + }` |
| 117 | + |
| 118 | + if err := env.executeMDL(createPageMDL); err != nil { |
| 119 | + t.Fatalf("Failed to create page with DATAGRID (no columns): %v", err) |
| 120 | + } |
| 121 | + |
| 122 | + // Disconnect to flush changes before mx check |
| 123 | + env.executor.Execute(&ast.DisconnectStmt{}) |
| 124 | + |
| 125 | + // Run mx check — template default columns won't match the entity's attributes, |
| 126 | + // so CE errors about missing attributes are expected. But placeholder ID leaks |
| 127 | + // or structural errors (CE0463) would indicate a regression. |
| 128 | + output, err := runMxCheck(t, env.projectPath) |
| 129 | + if err != nil { |
| 130 | + if strings.Contains(output, "placeholder") || strings.Contains(output, "CE0463") { |
| 131 | + t.Errorf("mx check found structural errors (possible placeholder leak):\n%s", output) |
| 132 | + } else { |
| 133 | + t.Logf("mx check output (attribute errors expected for template defaults):\n%s", output) |
| 134 | + } |
| 135 | + } else { |
| 136 | + t.Logf("mx check passed for DATAGRID (no columns) page:\n%s", output) |
| 137 | + } |
| 138 | +} |
0 commit comments