Skip to content

Commit

Permalink
chore: add ignored test for long polling and @PreserveOnRefresh (#10317)
Browse files Browse the repository at this point in the history
* add IT to isolate the problem

* ignore until flow issue #10103 is fixed
  • Loading branch information
taefi authored May 4, 2021
1 parent fba584d commit df4b798
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResource.TRANSPORT;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* 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.vaadin.flow.uitest.ui;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.NativeButton;
import com.vaadin.flow.component.page.Push;
import com.vaadin.flow.router.PreserveOnRefresh;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.shared.ui.Transport;

@PreserveOnRefresh
@Push(transport = Transport.LONG_POLLING)
@Route("com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView")
public class PushLongPollingWithPreserveOnRefreshView extends Div {

public static final String ADD_BUTTON_ID = "add-button-id";
public static final String TEST_DIV_ID = "test-div-id";
public static final String TEXT_IN_DIV = "text in div";

public PushLongPollingWithPreserveOnRefreshView() {
NativeButton button = new NativeButton("Open Dialog",
e -> e.getSource().getUI().ifPresent(ui -> {
Div div = new Div();
div.setText(TEXT_IN_DIV);
div.setId(TEST_DIV_ID);
ui.add(div);
}));
button.setId(ADD_BUTTON_ID);
add(button);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* 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.vaadin.flow.uitest.ui;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.NoSuchElementException;

import com.vaadin.flow.testcategory.IgnoreOSGi;
import com.vaadin.flow.testutil.ChromeBrowserTest;

import static com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView.ADD_BUTTON_ID;
import static com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView.TEST_DIV_ID;
import static com.vaadin.flow.uitest.ui.PushLongPollingWithPreserveOnRefreshView.TEXT_IN_DIV;

@Category(IgnoreOSGi.class)
public class PushLongPollingWithPreserveOnRefreshIT extends ChromeBrowserTest {

@Ignore("https://github.com/vaadin/flow/issues/10103")
@Test
public void addDiv_refreshThePage_ensureNoErrorHappensAndDivIsPresent() {

open();

waitPageLoad();

findElement(By.id(ADD_BUTTON_ID)).click();

ensureDivIsPresent();

// refresh the browser
getDriver().navigate().refresh();

waitPageLoad();

ensureNoErrorIsDisplayed();

ensureDivIsPresent();
}

private void waitPageLoad() {
WebElement loadingIndicator = findElement(
By.className("v-loading-indicator"));
waitUntil(driver -> !loadingIndicator.isDisplayed());
}

private void ensureNoErrorIsDisplayed() {
Assert.assertThrows(NoSuchElementException.class,
() -> findElement(By.className("v-system-error")));
}

private void ensureDivIsPresent() {
WebElement div = findElement(By.id(TEST_DIV_ID));

Assert.assertNotNull(div);
Assert.assertEquals(TEXT_IN_DIV, div.getText());
}
}

0 comments on commit df4b798

Please sign in to comment.