test: canvas widget coverage junit (#26384)
## Description Improve the coverage for Widgets in Junit #### PR fixes following issue(s) Fixes #25589
This commit is contained in:
parent
d917b42126
commit
0168a31f06
|
|
@ -1,6 +1,7 @@
|
|||
package com.appsmith.git.helpers;
|
||||
|
||||
import com.appsmith.git.constants.CommonConstants;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
|
@ -9,7 +10,11 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -20,6 +25,8 @@ public class DSLTransformHelperTest {
|
|||
private Map<String, JSONObject> jsonMap;
|
||||
private Map<String, List<String>> pathMapping;
|
||||
|
||||
String path = "src/test/resources";
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
// Initialize the JSON map and path mapping for each test
|
||||
|
|
@ -27,6 +34,17 @@ public class DSLTransformHelperTest {
|
|||
pathMapping = new HashMap<>();
|
||||
}
|
||||
|
||||
private String getWidgetDSL(String fileName) {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
File file = new File(classLoader.getResource("DSLWidget/" + fileName).getFile());
|
||||
String data = CommonConstants.EMPTY_STRING;
|
||||
try {
|
||||
data = FileUtils.readFileToString(file, "UTF-8");
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasChildren_WithChildren() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
|
@ -75,33 +93,23 @@ public class DSLTransformHelperTest {
|
|||
Assertions.assertFalse(result);
|
||||
}
|
||||
|
||||
/*@Test
|
||||
@Test
|
||||
public void testCalculateParentDirectories() {
|
||||
// Test Case 1: Simple paths
|
||||
List<String> paths1 = Arrays.asList(
|
||||
"/root/dir1/file1",
|
||||
"/root/dir1/file2",
|
||||
"/root/dir2/file3",
|
||||
"/root/dir3/file4"
|
||||
);
|
||||
List<String> paths1 =
|
||||
Arrays.asList("/root/dir1/file1", "/root/dir1/file2", "/root/dir2/file3", "/root/dir3/file4");
|
||||
Map<String, List<String>> result1 = DSLTransformerHelper.calculateParentDirectories(paths1);
|
||||
Map<String, List<String>> expected1 = new HashMap<>();
|
||||
expected1.put("root", Arrays.asList("/root/dir1/file1", "/root/dir1/file2", "/root/dir2/file3", "/root/dir3/file4"));
|
||||
expected1.put("dir1", Arrays.asList("/root/dir1/file1", "/root/dir1/file2"));
|
||||
expected1.put("dir2", Arrays.asList("/root/dir2/file3"));
|
||||
expected1.put("dir3", Arrays.asList("/root/dir3/file4"));
|
||||
Assertions.assertEquals(expected1, result1);
|
||||
|
||||
// Test Case 2: Paths with duplicate directories
|
||||
List<String> paths2 = Arrays.asList(
|
||||
"/root/dir1/file1",
|
||||
"/root/dir1/file2",
|
||||
"/root/dir2/file3",
|
||||
"/root/dir1/file4"
|
||||
);
|
||||
List<String> paths2 =
|
||||
Arrays.asList("/root/dir1/file1", "/root/dir1/file2", "/root/dir2/file3", "/root/dir1/file4");
|
||||
Map<String, List<String>> result2 = DSLTransformerHelper.calculateParentDirectories(paths2);
|
||||
Map<String, List<String>> expected2 = new HashMap<>();
|
||||
expected2.put("root", Arrays.asList("/root/dir1/file1", "/root/dir1/file2", "/root/dir2/file3", "/root/dir1/file4"));
|
||||
expected2.put("dir1", Arrays.asList("/root/dir1/file1", "/root/dir1/file2", "/root/dir1/file4"));
|
||||
expected2.put("dir2", Arrays.asList("/root/dir2/file3"));
|
||||
Assertions.assertEquals(expected2, result2);
|
||||
|
|
@ -113,18 +121,14 @@ public class DSLTransformHelperTest {
|
|||
Assertions.assertEquals(expected3, result3);
|
||||
|
||||
// Test Case 4: Paths with single-level directories
|
||||
List<String> paths4 = Arrays.asList(
|
||||
"/dir1/file1",
|
||||
"/dir2/file2",
|
||||
"/dir3/file3"
|
||||
);
|
||||
List<String> paths4 = Arrays.asList("/dir1/file1", "/dir2/file2", "/dir3/file3");
|
||||
Map<String, List<String>> result4 = DSLTransformerHelper.calculateParentDirectories(paths4);
|
||||
Map<String, List<String>> expected4 = new HashMap<>();
|
||||
expected4.put("dir1", Arrays.asList("/dir1/file1"));
|
||||
expected4.put("dir2", Arrays.asList("/dir2/file2"));
|
||||
expected4.put("dir3", Arrays.asList("/dir3/file3"));
|
||||
Assertions.assertEquals(expected4, result4);
|
||||
}*/
|
||||
}
|
||||
|
||||
// Test case for nested JSON object construction
|
||||
// --------------------------------------------------------------------
|
||||
|
|
@ -273,4 +277,30 @@ public class DSLTransformHelperTest {
|
|||
.put(CommonConstants.PARENT_ID, "ExistingChild1")
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareWidgetsWithDSL() {
|
||||
String dsl = getWidgetDSL("AllWidgetsDSL.json");
|
||||
Map<String, JSONObject> flattenedWidgets = DSLTransformerHelper.flatten(new JSONObject(dsl));
|
||||
|
||||
// 62 because some of the widgets are nested inside List Modal etc
|
||||
Assertions.assertEquals(flattenedWidgets.size(), 62);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tabWidget_withNestedChildren_AllWidgetsAreParsed() {
|
||||
String dsl = getWidgetDSL("TabWidgetNestedChildren.json");
|
||||
Map<String, JSONObject> flattenedWidgets = DSLTransformerHelper.flatten(new JSONObject(dsl));
|
||||
|
||||
for (Map.Entry<String, JSONObject> entry : flattenedWidgets.entrySet()) {
|
||||
JSONObject widget = entry.getValue();
|
||||
String relativePath = entry.getKey();
|
||||
Assertions.assertEquals(relativePath.contains("Tabs1"), true);
|
||||
if (widget.getString(CommonConstants.WIDGET_NAME).equals("Button1")) {
|
||||
Assertions.assertEquals(relativePath.endsWith("Button1"), true);
|
||||
} else if (widget.getString(CommonConstants.WIDGET_NAME).equals("CurrencyInput1")) {
|
||||
Assertions.assertEquals(relativePath.endsWith("CurrencyInput1"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,292 @@
|
|||
{
|
||||
"widgetName": "MainContainer",
|
||||
"backgroundColor": "none",
|
||||
"rightColumn": 1224,
|
||||
"snapColumns": 64,
|
||||
"detachFromLayout": true,
|
||||
"widgetId": "0",
|
||||
"topRow": 0,
|
||||
"bottomRow": 520,
|
||||
"containerStyle": "none",
|
||||
"snapRows": 66,
|
||||
"parentRowSpace": 1,
|
||||
"type": "CANVAS_WIDGET",
|
||||
"canExtend": true,
|
||||
"version": 83,
|
||||
"minHeight": 680,
|
||||
"parentColumnSpace": 1,
|
||||
"dynamicBindingPathList": [],
|
||||
"leftColumn": 0,
|
||||
"children": [
|
||||
{
|
||||
"boxShadow": "{{appsmith.theme.boxShadow.appBoxShadow}}",
|
||||
"mobileBottomRow": 52,
|
||||
"widgetName": "Tabs1",
|
||||
"borderColor": "#E0DEDE",
|
||||
"isCanvas": true,
|
||||
"displayName": "Tabs",
|
||||
"iconSVG": "/static/media/icon.9e3d67c0af9c0bd092dc56240314e18a.svg",
|
||||
"topRow": 37,
|
||||
"bottomRow": 52,
|
||||
"parentRowSpace": 10,
|
||||
"type": "TABS_WIDGET",
|
||||
"hideCard": false,
|
||||
"shouldScrollContents": true,
|
||||
"mobileRightColumn": 60,
|
||||
"animateLoading": true,
|
||||
"parentColumnSpace": 0.984375,
|
||||
"leftColumn": 12,
|
||||
"dynamicBindingPathList": [
|
||||
{
|
||||
"key": "accentColor"
|
||||
},
|
||||
{
|
||||
"key": "borderRadius"
|
||||
},
|
||||
{
|
||||
"key": "boxShadow"
|
||||
}
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"tabId": "tab1",
|
||||
"mobileBottomRow": 150,
|
||||
"widgetName": "Canvas1",
|
||||
"displayName": "Canvas",
|
||||
"bottomRow": 110,
|
||||
"topRow": 0,
|
||||
"parentRowSpace": 1,
|
||||
"type": "CANVAS_WIDGET",
|
||||
"canExtend": true,
|
||||
"hideCard": true,
|
||||
"shouldScrollContents": false,
|
||||
"minHeight": 150,
|
||||
"mobileRightColumn": 23.625,
|
||||
"parentColumnSpace": 1,
|
||||
"leftColumn": 0,
|
||||
"dynamicBindingPathList": [],
|
||||
"children": [
|
||||
{
|
||||
"resetFormOnClick": false,
|
||||
"boxShadow": "none",
|
||||
"mobileBottomRow": 6,
|
||||
"widgetName": "Button1",
|
||||
"buttonColor": "{{appsmith.theme.colors.primaryColor}}",
|
||||
"displayName": "Button",
|
||||
"iconSVG": "/static/media/icon.05d209fafeb13a8569e3b4e97069d9ee.svg",
|
||||
"searchTags": [
|
||||
"click",
|
||||
"submit"
|
||||
],
|
||||
"topRow": 2,
|
||||
"bottomRow": 6,
|
||||
"parentRowSpace": 10,
|
||||
"type": "BUTTON_WIDGET",
|
||||
"hideCard": false,
|
||||
"mobileRightColumn": 23,
|
||||
"animateLoading": true,
|
||||
"parentColumnSpace": 3.87109375,
|
||||
"leftColumn": 7,
|
||||
"dynamicBindingPathList": [
|
||||
{
|
||||
"key": "buttonColor"
|
||||
},
|
||||
{
|
||||
"key": "borderRadius"
|
||||
}
|
||||
],
|
||||
"text": "Submit",
|
||||
"isDisabled": false,
|
||||
"key": "1bjhjogqwh",
|
||||
"isDeprecated": false,
|
||||
"rightColumn": 23,
|
||||
"isDefaultClickDisabled": true,
|
||||
"widgetId": "w1q15xxln9",
|
||||
"minWidth": 120,
|
||||
"isVisible": true,
|
||||
"recaptchaType": "V3",
|
||||
"version": 1,
|
||||
"parentId": "p0x6x4f231",
|
||||
"tags": [
|
||||
"Buttons"
|
||||
],
|
||||
"renderMode": "CANVAS",
|
||||
"isLoading": false,
|
||||
"mobileTopRow": 2,
|
||||
"responsiveBehavior": "hug",
|
||||
"disabledWhenInvalid": false,
|
||||
"borderRadius": "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
||||
"mobileLeftColumn": 7,
|
||||
"buttonVariant": "PRIMARY",
|
||||
"placement": "CENTER"
|
||||
}
|
||||
],
|
||||
"isDisabled": false,
|
||||
"key": "h25emmxpxr",
|
||||
"isDeprecated": false,
|
||||
"tabName": "Tab 1",
|
||||
"rightColumn": 23.625,
|
||||
"detachFromLayout": true,
|
||||
"widgetId": "p0x6x4f231",
|
||||
"minWidth": 450,
|
||||
"isVisible": true,
|
||||
"version": 1,
|
||||
"parentId": "hi5yp56ffm",
|
||||
"renderMode": "CANVAS",
|
||||
"isLoading": false,
|
||||
"mobileTopRow": 0,
|
||||
"responsiveBehavior": "fill",
|
||||
"mobileLeftColumn": 0,
|
||||
"flexLayers": []
|
||||
},
|
||||
{
|
||||
"tabId": "tab2",
|
||||
"mobileBottomRow": 150,
|
||||
"widgetName": "Canvas2",
|
||||
"displayName": "Canvas",
|
||||
"bottomRow": 110,
|
||||
"topRow": 0,
|
||||
"parentRowSpace": 1,
|
||||
"type": "CANVAS_WIDGET",
|
||||
"canExtend": true,
|
||||
"hideCard": true,
|
||||
"shouldScrollContents": false,
|
||||
"minHeight": 150,
|
||||
"mobileRightColumn": 23.625,
|
||||
"parentColumnSpace": 1,
|
||||
"leftColumn": 0,
|
||||
"dynamicBindingPathList": [],
|
||||
"children": [
|
||||
{
|
||||
"boxShadow": "none",
|
||||
"iconSVG": "/static/media/icon.950aa351208d9d9b2a695b3881ec3779.svg",
|
||||
"topRow": 2,
|
||||
"defaultCurrencyCode": "INR",
|
||||
"labelWidth": 5,
|
||||
"type": "CURRENCY_INPUT_WIDGET",
|
||||
"animateLoading": true,
|
||||
"resetOnSubmit": true,
|
||||
"leftColumn": 10,
|
||||
"dynamicBindingPathList": [
|
||||
{
|
||||
"key": "accentColor"
|
||||
},
|
||||
{
|
||||
"key": "borderRadius"
|
||||
}
|
||||
],
|
||||
"labelStyle": "",
|
||||
"isDisabled": false,
|
||||
"isRequired": false,
|
||||
"dynamicHeight": "FIXED",
|
||||
"accentColor": "{{appsmith.theme.colors.primaryColor}}",
|
||||
"showStepArrows": false,
|
||||
"isVisible": true,
|
||||
"allowCurrencyChange": false,
|
||||
"version": 1,
|
||||
"tags": [
|
||||
"Inputs"
|
||||
],
|
||||
"isLoading": false,
|
||||
"borderRadius": "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
||||
"mobileBottomRow": 9,
|
||||
"widgetName": "CurrencyInput1",
|
||||
"displayName": "Currency Input",
|
||||
"searchTags": [
|
||||
"amount",
|
||||
"total"
|
||||
],
|
||||
"bottomRow": 9,
|
||||
"parentRowSpace": 10,
|
||||
"autoFocus": false,
|
||||
"hideCard": false,
|
||||
"mobileRightColumn": 30,
|
||||
"parentColumnSpace": 3.87109375,
|
||||
"labelPosition": "Top",
|
||||
"key": "ibpiq8rgcp",
|
||||
"labelTextSize": "0.875rem",
|
||||
"isDeprecated": false,
|
||||
"rightColumn": 30,
|
||||
"widgetId": "wp8ui4zlhz",
|
||||
"minWidth": 450,
|
||||
"label": "Label",
|
||||
"parentId": "hvwk0q0v3j",
|
||||
"labelAlignment": "left",
|
||||
"renderMode": "CANVAS",
|
||||
"mobileTopRow": 2,
|
||||
"responsiveBehavior": "fill",
|
||||
"mobileLeftColumn": 10,
|
||||
"maxDynamicHeight": 9000,
|
||||
"decimals": 0,
|
||||
"iconAlign": "left",
|
||||
"defaultText": "",
|
||||
"minDynamicHeight": 4
|
||||
}
|
||||
],
|
||||
"isDisabled": false,
|
||||
"key": "h25emmxpxr",
|
||||
"isDeprecated": false,
|
||||
"tabName": "Tab 2",
|
||||
"rightColumn": 23.625,
|
||||
"detachFromLayout": true,
|
||||
"widgetId": "hvwk0q0v3j",
|
||||
"minWidth": 450,
|
||||
"isVisible": true,
|
||||
"version": 1,
|
||||
"parentId": "hi5yp56ffm",
|
||||
"renderMode": "CANVAS",
|
||||
"isLoading": false,
|
||||
"mobileTopRow": 0,
|
||||
"responsiveBehavior": "fill",
|
||||
"mobileLeftColumn": 0,
|
||||
"flexLayers": []
|
||||
}
|
||||
],
|
||||
"borderWidth": 1,
|
||||
"key": "1gptcxl57m",
|
||||
"backgroundColor": "#FFFFFF",
|
||||
"isDeprecated": false,
|
||||
"rightColumn": 60,
|
||||
"dynamicHeight": "AUTO_HEIGHT",
|
||||
"widgetId": "hi5yp56ffm",
|
||||
"accentColor": "{{appsmith.theme.colors.primaryColor}}",
|
||||
"defaultTab": "Tab 1",
|
||||
"shouldShowTabs": true,
|
||||
"minWidth": 450,
|
||||
"tabsObj": {
|
||||
"tab1": {
|
||||
"label": "Tab 1",
|
||||
"id": "tab1",
|
||||
"widgetId": "p0x6x4f231",
|
||||
"isVisible": true,
|
||||
"index": 0,
|
||||
"positioning": "vertical"
|
||||
},
|
||||
"tab2": {
|
||||
"label": "Tab 2",
|
||||
"id": "tab2",
|
||||
"widgetId": "hvwk0q0v3j",
|
||||
"isVisible": true,
|
||||
"index": 1,
|
||||
"positioning": "vertical"
|
||||
}
|
||||
},
|
||||
"isVisible": true,
|
||||
"version": 3,
|
||||
"parentId": "0",
|
||||
"tags": [
|
||||
"Layout"
|
||||
],
|
||||
"renderMode": "CANVAS",
|
||||
"isLoading": false,
|
||||
"mobileTopRow": 37,
|
||||
"responsiveBehavior": "fill",
|
||||
"originalTopRow": 37,
|
||||
"borderRadius": "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
||||
"mobileLeftColumn": 36,
|
||||
"maxDynamicHeight": 9000,
|
||||
"originalBottomRow": 56,
|
||||
"minDynamicHeight": 15
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user