diff --git a/kernel/base/src/main/java/com/twosigma/beakerx/widgets/Layout.java b/kernel/base/src/main/java/com/twosigma/beakerx/widgets/Layout.java index 0d40d264e2..614cd9f257 100644 --- a/kernel/base/src/main/java/com/twosigma/beakerx/widgets/Layout.java +++ b/kernel/base/src/main/java/com/twosigma/beakerx/widgets/Layout.java @@ -28,9 +28,8 @@ public class Layout extends Widget { public static final String WIDTH = "width"; public static final String HEIGHT = "height"; public static final String PX = "px"; - - private String VIEW_NAME_VALUE = "LayoutView"; - private String MODEL_NAME_VALUE = "LayoutModel"; + public static final String VIEW_NAME_VALUE = "LayoutView"; + public static final String MODEL_NAME_VALUE = "LayoutModel"; private String display; private String align_items; diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/evaluator/EvaluatorResultTestWatcher.java b/kernel/base/src/test/java/com/twosigma/beakerx/evaluator/EvaluatorResultTestWatcher.java index ec6a1c4641..bcada57adc 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/evaluator/EvaluatorResultTestWatcher.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/evaluator/EvaluatorResultTestWatcher.java @@ -29,7 +29,7 @@ public class EvaluatorResultTestWatcher { public static final int ATTEMPT = 2000; - public static final int SLEEP_IN_MILLIS = 10; + public static final int SLEEP_IN_MILLIS = 20; public static void waitForResult(SimpleEvaluationObject seo) throws InterruptedException { int count = 0; diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ButtonTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ButtonTest.java index b2597c7ba0..e92175df1f 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ButtonTest.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ButtonTest.java @@ -1,5 +1,4 @@ - -/* + /* * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +15,9 @@ */ package com.twosigma.beakerx.widgets; - import com.twosigma.beakerx.KernelTest; import com.twosigma.beakerx.kernel.KernelManager; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -49,7 +48,12 @@ public void shouldSendCommOpenWhenCreate() throws Exception { //when new Button(); //then - verifyInternalOpenCommMsgWitLayout(groovyKernel.getPublishedMessages(), Button.MODEL_NAME_VALUE, Button.VIEW_NAME_VALUE, Widget.MODEL_MODULE_VALUE, Widget.VIEW_MODULE_VALUE); + verifyInternalOpenCommMsgWitLayout( + groovyKernel.getPublishedMessages(), + Button.MODEL_NAME_VALUE, + Button.VIEW_NAME_VALUE, + Widget.MODEL_MODULE_VALUE, + Widget.VIEW_MODULE_VALUE); } @Test @@ -72,6 +76,28 @@ public void shouldSendCommMsgWhenTagChange() throws Exception { verifyMsgForProperty(groovyKernel, Button.TAG, "Tag2"); } + @Test + public void setButtonStyle_hasThatButtonStyle() throws Exception { + String expected = "test"; + //given + Button button = button(); + //when + button.setButton_style(expected); + //then + Assertions.assertThat(button.getButton_style()).isEqualTo(expected); + } + + @Test + public void setTooltip_hasThatTooltip() throws Exception { + String expected = "test"; + //given + Button button = button(); + //when + button.setTooltip(expected); + //then + Assertions.assertThat(button.getTooltip()).isEqualTo(expected); + } + private Button button() throws NoSuchAlgorithmException { Button widget = new Button(); groovyKernel.clearPublishedMessages(); diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ColorPickerTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ColorPickerTest.java index f37d9a0271..7bdd8b73e7 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ColorPickerTest.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ColorPickerTest.java @@ -17,6 +17,7 @@ import com.twosigma.beakerx.KernelTest; import com.twosigma.beakerx.kernel.KernelManager; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -69,6 +70,16 @@ public void shouldSendCommMsgWhenConciseChange() throws Exception { TestWidgetUtils.verifyMsgForProperty(groovyKernel, ColorPicker.CONCISE, true); } + @Test + public void setConciseFlag_hasThatConciseFlag() throws Exception { + boolean expected = true; + //given + ColorPicker colorPicker = colorPicker(); + //when + colorPicker.setConcise(expected); + //then + Assertions.assertThat(colorPicker.getConcise()).isEqualTo(expected); + } private ColorPicker colorPicker() throws NoSuchAlgorithmException { ColorPicker widget = new ColorPicker(); diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/DatePickerTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/DatePickerTest.java index 3a6f983c2c..15ec59ccd6 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/DatePickerTest.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/DatePickerTest.java @@ -17,16 +17,15 @@ import com.twosigma.beakerx.KernelTest; import com.twosigma.beakerx.kernel.KernelManager; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.security.NoSuchAlgorithmException; -import java.text.SimpleDateFormat; -import static com.twosigma.beakerx.widgets.DatePicker.YYYY_MM_DD; + import static com.twosigma.beakerx.widgets.TestWidgetUtils.verifyInternalOpenCommMsgWitLayout; import static com.twosigma.beakerx.widgets.TestWidgetUtils.verifyMsgForProperty; -import static org.assertj.core.api.Assertions.assertThat; public class DatePickerTest { @@ -53,18 +52,18 @@ public void shouldSendCommOpenWhenCreate() throws Exception { } @Test - public void shouldSendCommMsgWhenValueChange() throws Exception { + public void changeValue_shouldSendCommMessage() throws Exception { + String expected = "20120101"; //given DatePicker widget = widget(); //when - widget.setValue("20120101"); + widget.setValue(expected); //then - TestWidgetUtils.verifyMsgForProperty(groovyKernel, DatePicker.VALUE, "20120101"); - assertThat(widget.getValue()).isEqualTo(new SimpleDateFormat(YYYY_MM_DD).parse("20120101")); + TestWidgetUtils.verifyMsgForProperty(groovyKernel, DatePicker.VALUE, expected); } @Test - public void shouldSendCommMsgWhenShowTimeChange() throws Exception { + public void setShowTime_shouldSendCommMessage() throws Exception { //given DatePicker widget = widget(); //when @@ -73,6 +72,17 @@ public void shouldSendCommMsgWhenShowTimeChange() throws Exception { verifyMsgForProperty(groovyKernel, DatePicker.SHOW_TIME, true); } + @Test + public void setShowTimeFlag_hasThatShowTimeFlag() throws Exception { + boolean expected = true; + //given + DatePicker widget = widget(); + //when + widget.setShowTime(expected); + //then + Assertions.assertThat(widget.getShowTime()).isEqualTo(expected); + } + private DatePicker widget() throws NoSuchAlgorithmException { DatePicker widget = new DatePicker(); groovyKernel.clearPublishedMessages(); diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ImageTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ImageTest.java index a5e62836d5..a6f9760c43 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ImageTest.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ImageTest.java @@ -17,6 +17,7 @@ import com.twosigma.beakerx.KernelTest; import com.twosigma.beakerx.kernel.KernelManager; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -89,6 +90,39 @@ public void shouldSendCommMsgWhenWidthChange() throws Exception { TestWidgetUtils.verifyMsgForProperty(groovyKernel, Image.WIDTH, "321"); } + @Test + public void setWidth_hasThatWidth() throws Exception { + String expected = "123"; + //given + Image widget = image(); + //when + widget.setWidth(expected); + //then + Assertions.assertThat(widget.getWidth()).isEqualTo(expected); + } + + @Test + public void setHeight_hasThatHeight() throws Exception { + String expected = "123"; + //given + Image widget = image(); + //when + widget.setHeight(expected); + //then + Assertions.assertThat(widget.getHeight()).isEqualTo(expected); + } + + @Test + public void setFormat_hasThatFormat() throws Exception { + String expected = "test"; + //given + Image widget = image(); + //when + widget.setFormat(expected); + //then + Assertions.assertThat(widget.getFormat()).isEqualTo(expected); + } + private Image image() throws NoSuchAlgorithmException { Image widget = new Image(); groovyKernel.clearPublishedMessages(); diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/LayoutTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/LayoutTest.java new file mode 100644 index 0000000000..af1feebd51 --- /dev/null +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/LayoutTest.java @@ -0,0 +1,116 @@ +/* + * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.twosigma.beakerx.widgets; + +import com.twosigma.beakerx.KernelTest; +import com.twosigma.beakerx.jupyter.SearchMessages; +import com.twosigma.beakerx.kernel.KernelManager; +import org.assertj.core.api.Assertions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.security.NoSuchAlgorithmException; + +public class LayoutTest { + + private KernelTest kernel; + + @Before + public void setUp() throws Exception { + kernel = new KernelTest(); + KernelManager.register(kernel); + } + + @After + public void tearDown() throws Exception { + KernelManager.register(null); + } + + @Test + public void shouldSendCommOpenWhenCreate() throws Exception { + //given + //when + new Layout(); + //then + Assertions.assertThat( + SearchMessages.getListWidgetsByModelName(kernel.getPublishedMessages(), Layout.MODEL_NAME_VALUE) + ).isNotEmpty(); + } + + @Test + public void setAlignItems_hasThatAlignItems() throws Exception { + String expected = "test"; + //given + Layout layout = layout(); + //when + layout.setAlign_items(expected); + //then + Assertions.assertThat(layout.getAlign_items()).isEqualTo(expected); + } + + @Test + public void setDisplay_hasThatDisplay() throws Exception { + String expected = "test"; + //given + Layout layout = layout(); + //when + layout.setDisplay(expected); + //then + Assertions.assertThat(layout.getDisplay()).isEqualTo(expected); + } + + @Test + public void setFlexFlow_hasThatFlexFlow() throws Exception { + String expected = "test"; + //given + Layout layout = layout(); + //when + layout.setFlex_flow(expected); + //then + Assertions.assertThat(layout.getFlex_flow()).isEqualTo(expected); + } + + @Test + public void setHeight_hasThatHeight() throws Exception { + String expected = "10"; + //given + Layout layout = layout(); + //when + layout.setHeight(expected); + //then + Assertions.assertThat(layout.getHeight()).isEqualTo(expected); + } + + @Test + public void setWidth_hasThatWidth() throws Exception { + String expected = "20"; + //given + Layout layout = layout(); + //when + layout.setWidth(expected); + //then + Assertions.assertThat(layout.getWidth()).isEqualTo(expected); + } + + private Layout layout() throws NoSuchAlgorithmException { + Layout widget = new Layout(); + kernel.clearPublishedMessages(); + return widget; + } + +} diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ValueWidgetTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ValueWidgetTest.java index 92ff16293f..33541cd5d6 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ValueWidgetTest.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/ValueWidgetTest.java @@ -94,7 +94,7 @@ public void getDoubleWithDoubleParam_returnDouble() throws Exception { @Test public void getDoubleWithIntegerParam_returnDouble() throws Exception { //when - Double value = valueWidget.getDouble(new Double(123d)); + Double value = valueWidget.getDouble(new Integer(123)); //then Assertions.assertThat(value.doubleValue()).isEqualTo(123d); } diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ToggleButtonTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ToggleButtonTest.java index 2f63391e23..47d0a829bc 100644 --- a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ToggleButtonTest.java +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ToggleButtonTest.java @@ -17,6 +17,8 @@ import com.twosigma.beakerx.kernel.KernelManager; import com.twosigma.beakerx.KernelTest; +import com.twosigma.beakerx.widgets.integers.IntProgress; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -70,6 +72,38 @@ public void shouldSendCommMsgWhenTooltipChange() throws Exception { verifyMsgForProperty(groovyKernel, ToggleButton.TOOLTIP, "Tooltip 2"); } + @Test + public void setButtonStyle_hasThatButtonStyle() throws Exception { + String expected = "test"; + //given + ToggleButton toggleButton = toggleButton(); + //when + toggleButton.setButton_style(expected); + //then + Assertions.assertThat(toggleButton.getButton_style()).isEqualTo(expected); + } + + @Test + public void setIcon_hasThatIcon() throws Exception { + String expected = "test"; + //given + ToggleButton toggleButton = toggleButton(); + //when + toggleButton.setIcon(expected); + //then + Assertions.assertThat(toggleButton.getIcon()).isEqualTo(expected); + } + + @Test + public void setTooltip_hasThatTooltip() throws Exception { + String expected = "test"; + //given + ToggleButton toggleButton = toggleButton(); + //when + toggleButton.setTooltip(expected); + //then + Assertions.assertThat(toggleButton.getTooltip()).isEqualTo(expected); + } private ToggleButton toggleButton() throws NoSuchAlgorithmException { ToggleButton widget = new ToggleButton(); diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ValidTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ValidTest.java new file mode 100644 index 0000000000..983cebae74 --- /dev/null +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/bools/ValidTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.twosigma.beakerx.widgets.bools; + +import com.twosigma.beakerx.KernelTest; +import com.twosigma.beakerx.kernel.KernelManager; +import com.twosigma.beakerx.widgets.integers.IntSlider; +import org.assertj.core.api.Assertions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static com.twosigma.beakerx.widgets.TestWidgetUtils.verifyOpenCommMsg; + +public class ValidTest { + + private KernelTest kernel; + + @Before + public void setUp() throws Exception { + kernel = new KernelTest(); + KernelManager.register(kernel); + } + + @After + public void tearDown() throws Exception { + KernelManager.register(null); + } + + @Test + public void shouldSendCommOpenWhenCreate() throws Exception { + //given + //when + new Valid(); + //then + verifyOpenCommMsg( + kernel.getPublishedMessages(), + Valid.MODEL_NAME_VALUE, + Valid.VIEW_NAME_VALUE); + } + + @Test + public void setReadOutFlag_hasThatReadOutFlag() throws Exception { + boolean expected = true; + //given + Valid valid = new Valid(); + kernel.clearPublishedMessages(); + //when + valid.setReadOut(expected); + //then + Assertions.assertThat(valid.getReadOut()).isEqualTo(expected); + } + +} diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/link/DirectionalLinkTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/link/DirectionalLinkTest.java new file mode 100644 index 0000000000..c0fd9b4d2a --- /dev/null +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/link/DirectionalLinkTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.twosigma.beakerx.widgets.link; + +import com.twosigma.beakerx.KernelTest; +import com.twosigma.beakerx.jupyter.SearchMessages; +import com.twosigma.beakerx.kernel.KernelManager; +import com.twosigma.beakerx.widgets.Widget; +import com.twosigma.beakerx.widgets.integers.IntSlider; +import com.twosigma.beakerx.widgets.strings.Text; +import org.assertj.core.api.Assertions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class DirectionalLinkTest { + + private KernelTest kernel; + + @Before + public void setUp() throws Exception { + kernel = new KernelTest(); + KernelManager.register(kernel); + } + + @After + public void tearDown() throws Exception { + KernelManager.register(null); + } + + @Test + public void createWithFourParams_shouldSendCommOpenMessage() throws Exception { + //given + Widget source = new IntSlider(); + Widget target = new Text(); + kernel.clearPublishedMessages(); + //when + new DirectionalLink(source, "source", target, "target"); + //then + Assertions.assertThat( + SearchMessages.getListWidgetsByModelName(kernel.getPublishedMessages(), DirectionalLink.MODEL_NAME_VALUE) + ).isNotEmpty(); + } + +} diff --git a/kernel/base/src/test/java/com/twosigma/beakerx/widgets/link/LinkTest.java b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/link/LinkTest.java new file mode 100644 index 0000000000..4cbd44497e --- /dev/null +++ b/kernel/base/src/test/java/com/twosigma/beakerx/widgets/link/LinkTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.twosigma.beakerx.widgets.link; + +import com.twosigma.beakerx.KernelTest; +import com.twosigma.beakerx.jupyter.SearchMessages; +import com.twosigma.beakerx.kernel.KernelManager; +import com.twosigma.beakerx.widgets.Widget; +import com.twosigma.beakerx.widgets.integers.IntSlider; +import com.twosigma.beakerx.widgets.strings.Text; +import org.assertj.core.api.Assertions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class LinkTest { + + private KernelTest kernel; + + @Before + public void setUp() throws Exception { + kernel = new KernelTest(); + KernelManager.register(kernel); + } + + @After + public void tearDown() throws Exception { + KernelManager.register(null); + } + + @Test + public void createWithFourParams_shouldSendCommOpenMessage() throws Exception { + //given + Widget source = new IntSlider(); + Widget target = new Text(); + kernel.clearPublishedMessages(); + //when + new Link(source, "source", target, "target"); + //then + Assertions.assertThat( + SearchMessages.getListWidgetsByModelName(kernel.getPublishedMessages(), Link.MODEL_NAME_VALUE) + ).isNotEmpty(); + } + +}