package org.vaadin.elements;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.vaadin.elements.impl.RootImpl;

import com.vaadin.ui.Label;

import elemental.json.JsonArray;

public class RootTest {

    private RootImpl root;
    private Element child;

    @Before
    public void init() {
        child = Elements.create("div");
        root = (RootImpl) ElementIntegration.getRoot(new Label());
    }

    @Test
    public void testAppendChild() {
        root.appendChild(child);

        JsonArray pendingCommands = root.flushPendingCommands();

        Assert.assertEquals(
                "[[\"createElement\",3,\"div\"],[\"appendChild\",0,3]]",
                pendingCommands.toJson());
    }

    @Test
    public void testRemoveChild() {
        root.appendChild(child);
        root.flushPendingCommands();

        child.remove();

        JsonArray pendingCommands = root.flushPendingCommands();

        Assert.assertEquals("[[\"remove\",3]]", pendingCommands.toJson());
    }

}

@@ -645,17 +645,17 @@
 ement%5C%22,
-3
+2
 ,%5C%22div%5C%22
@@ -675,17 +675,17 @@
 ild%5C%22,0,
-3
+2
 %5D%5D%22,%0A   
@@ -985,9 +985,9 @@
 e%5C%22,
-3
+2
 %5D%5D%22,

Update test for changed indexing