Skip to content

Commit b2e1603

Browse files
paodbjavier-godoy
authored andcommitted
test: add test for #33
1 parent 9948680 commit b2e1603

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*-
2+
* #%L
3+
* ChipField Addon
4+
* %%
5+
* Copyright (C) 2018 - 2021 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.chipfield.integration;
21+
22+
import com.flowingcode.vaadin.addons.chipfield.integration.rpc.HasRpcSupport;
23+
24+
public abstract class AbstractRemoveAndReAddTest extends AbstractViewTest implements HasRpcSupport {
25+
26+
protected AbstractRemoveAndReAddTest() {
27+
super("remove-add-test");
28+
}
29+
30+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*-
2+
* #%L
3+
* ChipField Addon
4+
* %%
5+
* Copyright (C) 2018 - 2021 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.chipfield.integration;
21+
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertFalse;
24+
import static org.junit.Assert.assertTrue;
25+
26+
import org.junit.Test;
27+
28+
import com.vaadin.flow.component.button.testbench.ButtonElement;
29+
30+
/**
31+
* Test that shows that removing a chipfield with values from the layout and adding it again doesn't lose the chip values.
32+
*
33+
* @see https://github.com/FlowingCode/ChipFieldAddon/issues/33
34+
*
35+
*/
36+
public class RemoveAndReAddTestIT extends AbstractRemoveAndReAddTest {
37+
38+
@Test
39+
public void toggleChipField() {
40+
ChipFieldElement chipfield = $(ChipFieldElement.class).id("chipfield");
41+
assertTrue(chipfield.isDisplayed());
42+
assertEquals(chipfield.getValue().size(), 2);
43+
ButtonElement button = $(ButtonElement.class).id("toggle");
44+
button.click(); // remove chipfield
45+
assertFalse($(ChipFieldElement.class).exists());
46+
button.click(); // add chipfield again
47+
chipfield = $(ChipFieldElement.class).id("chipfield");
48+
assertTrue(chipfield.isDisplayed());
49+
assertEquals(chipfield.getValue().size(), 2);
50+
}
51+
52+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*-
2+
* #%L
3+
* ChipField Addon
4+
* %%
5+
* Copyright (C) 2018 - 2021 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.chipfield.integration;
21+
22+
import java.util.Arrays;
23+
24+
import com.flowingcode.vaadin.addons.chipfield.ChipField;
25+
import com.vaadin.flow.component.button.Button;
26+
import com.vaadin.flow.component.html.Div;
27+
import com.vaadin.flow.router.Route;
28+
29+
/**
30+
* Test class for fix for issue https://github.com/FlowingCode/ChipFieldAddon/issues/33
31+
*
32+
*/
33+
@Route("remove-add-test")
34+
public class RemoveAndReAddTestView extends Div {
35+
36+
public RemoveAndReAddTestView() {
37+
super.getElement().getStyle().set("padding", "5px");
38+
39+
setId("remove-add-test");
40+
41+
ChipField<String> chf =
42+
new ChipField<>("Planets", "Mercury", "Venus", "Earth");
43+
chf.setId("chipfield");
44+
chf.setWidthFull();
45+
46+
chf.addSelectedItem("Mercury");
47+
chf.addSelectedItem("Venus");
48+
chf.setValue(Arrays.asList("Mercury", "Venus"));
49+
50+
Button toggle = new Button("Toggle chipfield", e -> {
51+
if (getChildren().anyMatch(chf::equals)) {
52+
remove(chf);
53+
} else {
54+
add(chf);
55+
}
56+
});
57+
58+
toggle.setId("toggle");
59+
60+
add(toggle, chf);
61+
}
62+
63+
}

0 commit comments

Comments
 (0)