Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert empty array elements #23

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions json-form/src/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,14 @@ export function actionAddElementToArray(
JsFacade.validate(schemaAny, valueToAny(tmpRoot)),
);

debugger;
const proposals = newValidationResult
.map((vr) => getProposals(vr, path.append(newElemIndex), -1))
.withDefault([]);

const proposal = maybeOf(proposals[0]).withDefault(jvNull);
const newArray: JvArray = {
...array,
elems: [...array.elems, proposal],
elems: [...array.elems, clearPropertiesIfObject(proposal)],
};
const newRoot = setValueAt(model.root.b, path, newArray);
return setRoot(model, newRoot);
Expand Down
14 changes: 14 additions & 0 deletions sandbox/src/initdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const Sample_EnumArray = `{
}
}`;

const Sample_ObjectArray = `{
"type": [
"array", "null"
],
"items": {
"type": [ "object", "null" ],
"properties": {
"foo": { "type": "number" },
"bar": { "type": "boolean" }
}
}
}`;

const Sample_BeanContainingOtherBean = `{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://schema.BeanWithBean",
Expand Down Expand Up @@ -310,6 +323,7 @@ export const samples = [
["Long", Sample_Long],
["String", Sample_String],
["EnumArray", Sample_EnumArray],
["ObjectArray", Sample_ObjectArray],
["BeanContainingOtherBean", Sample_BeanContainingOtherBean],
["Inheritance", Sample_Inheritance],
["Polymorphism", Example_Polymorphism],
Expand Down
17 changes: 5 additions & 12 deletions webtests/helpers/src/main/java/diesel/json/FArray.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package diesel.json;

import com.pojosontheweb.selenium.Findr;
import com.pojosontheweb.selenium.Findrs;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import static com.pojosontheweb.selenium.Findrs.textEquals;

import java.util.function.Function;
import org.openqa.selenium.By;

import static com.pojosontheweb.selenium.Findrs.textEquals;
import com.pojosontheweb.selenium.Findr;
import com.pojosontheweb.selenium.Findrs;

public class FArray extends FJsonValue {

Expand All @@ -22,8 +18,7 @@ public class FArray extends FJsonValue {

private Findr.ListFindr findElems() {
return getFindr().elemList(
By.xpath("./div[contains(@class,'array-elem')]")
);
By.xpath("./div[contains(@class,'array-elem')]"));
}

public FString getStringCell(int index) {
Expand All @@ -33,7 +28,6 @@ public FString getStringCell(int index) {

}


public FArray assertLength(int expectedLength) {
findElems().count(expectedLength).eval();
return this;
Expand All @@ -57,5 +51,4 @@ public FArray assertError(String expectedError) {
return this;
}


}
38 changes: 17 additions & 21 deletions webtests/helpers/src/main/java/diesel/json/FObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ public FObject assertError(String expectedError) {
private Findr.ListFindr findPropButtons() {
return getFindr()
.elemList(
By.xpath("./div/div[contains(@class,'add-prop-row')]/button")
);
By.xpath("./div/div[contains(@class,'add-prop-row')]/button"));
}

public FObject assertAddPropButtons(String prop, String... rest) {
List<String> props = Stream.concat(
Stream.of(prop),
Stream.of(rest)
).collect(Collectors.toList());
Stream.of(rest)).collect(Collectors.toList());

findPropButtons()
.eval(elems -> {
Expand All @@ -65,24 +63,22 @@ public FObject clickAddPropButton(String propName) {
public FObject assertProperties(String... props) {
List<String> expected = Stream.of(props).collect(Collectors.toList());
getFindr()
.elemList(
By.xpath(
"./div[contains(@class,'object-prop')]/div[contains(@class,'prop-name-row')]/div[contains(@class,'prop-name')]"
)
)
.eval(elems -> {
List<String> actual = elems.stream().map(WebElement::getText).collect(Collectors.toList());
return actual.equals(expected);
});
.elemList(
By.xpath(
"./div[contains(@class,'object-prop')]/div[contains(@class,'prop-name-row')]/div[contains(@class,'prop-name')]"))
.eval(elems -> {
List<String> actual = elems.stream().map(WebElement::getText).collect(Collectors.toList());
return actual.equals(expected);
});
return this;
}
public FObject assertEmptyProperties(String... props){

public FObject assertEmptyProperties(String... props) {
List<String> expected = Stream.of(props).collect(Collectors.toList());
getFindr()
.elemList(
By.xpath(
"./div/div[contains(@class,'add-prop-row')]/button")
)
"./div/div[contains(@class,'add-prop-row')]/button"))
.eval(elems -> {
List<String> actual = elems.stream().map(WebElement::getText).collect(Collectors.toList());
return actual.equals(expected);
Expand All @@ -95,8 +91,7 @@ private Findr findPropRow(String propName) {
.where(e -> {
WebElement propNameElem = e.findElement(
By.xpath(
"./div[contains(@class,'prop-name-row')]/div[contains(@class,'prop-name')]")
);
"./div[contains(@class,'prop-name-row')]/div[contains(@class,'prop-name')]"));
if (propNameElem == null) {
return false;
}
Expand Down Expand Up @@ -127,10 +122,11 @@ public FObject assertArrayLength(String propName, int expectedCount) {
.eval();
return this;
}
public FObject selectPropertyValue(String property, String value){

public FObject selectPropertyValue(String property, String value) {
Findr findSelect = findPropRow(property)
.$$(".bx--list-box__menu-icon")
.expectOne();
.$$(".bx--list-box__menu-icon")
.expectOne();

findSelect.click();
$$(".bx--list-box__menu-item__option")
Expand Down
26 changes: 26 additions & 0 deletions webtests/webapp/src/it/java/diesel/sandbox/tests/SandboxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void simpleLong() {

private final String BeanContainingOtherBean = "BeanContainingOtherBean";
private final String EnumArray = "EnumArray";
private final String ObjectArray = "ObjectArray";

@Test
public void customerAge() {
Expand Down Expand Up @@ -158,6 +159,31 @@ public void addProperty() {
f.objectAt(customerPath).assertEmpty();
}

@Test
public void addArrayElement() {
FJsonForm f = sandbox.jsonForm;

sandbox.selectSample(ObjectArray);
sandbox.jsonEditor.focus().clearText();
sandbox.jsonEditor.assertText("");

f
.clickRootMenu()
.clickPropose("array");
f
.arrayAt(JsPath.empty)
.assertLength(0);
f
.clickRootMenu()
.clickAddElement();
f
.arrayAt(JsPath.empty)
.assertLength(1);
f
.objectAt(JsPath.empty.append(0))
.assertEmpty();
}

private void assertErrorInvalidType(String type) {
sandbox.schemaEditor
.focus()
Expand Down