Skip to content

Commit

Permalink
add tests for beakerx.widgets package (#5692)
Browse files Browse the repository at this point in the history
* revert property for extra test output

* add tests for beakerx.widgets package

* add tests for beakerx.widgets package
  • Loading branch information
EfimovVladimir authored and scottdraves committed Jul 19, 2017
1 parent 14f792d commit 0fb52a7
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

/*
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
116 changes: 116 additions & 0 deletions kernel/base/src/test/java/com/twosigma/beakerx/widgets/LayoutTest.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 0fb52a7

Please sign in to comment.