Skip to content

Commit

Permalink
Add AboutViewTest
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuJLund committed Jul 14, 2024
1 parent e6b8f8a commit b9ae5fd
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.vaadin.tatu.vaadincreate;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.testbench.elements.TextAreaElement;

public class AboutViewIT extends AbstractViewTest {
Expand All @@ -17,6 +19,11 @@ public void setup() throws Exception {
open("#!" + AboutView.VIEW_NAME);
}

@After
public void cleanup() {
$(MenuBarElement.class).first().findElement(By.id("logout-2")).click();
}

@Test
public void leaveMessageSanitized() {
waitForElementPresent(By.id("admins-note"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.vaadin.tatu.vaadincreate;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.vaadin.tatu.vaadincreate.crud.BookForm;
import org.vaadin.tatu.vaadincreate.crud.BookGrid;
import org.vaadin.tatu.vaadincreate.crud.BooksView;

import com.vaadin.server.ServiceException;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.TextAreaElement;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.VerticalLayout;

public class AboutViewTest extends AbstractUITest {

private VaadinCreateUI ui;
private AboutView view;

@Before
public void setup() throws ServiceException {
ui = new VaadinCreateUI();
mockVaadin(ui);
login();

view = navigate(AboutView.VIEW_NAME, AboutView.class);

var layout = $(view, VerticalLayout.class).first();
}

@After
public void cleanUp() {
logout();
tearDown();
}

@Test
public void leaveMessageSanitized() {
var note = $(Label.class).id("admins-note");
var oldText = note.getValue();

test($(Button.class).id("admin-edit")).click();
var area = $(TextArea.class).id("admins-text-area");
assertTrue(area.isVisible());
// If not sanitized this would be XSS
test(area).setValue(
"<b><img src=1 onerror=alert(document.domain)>A new message</b>");
test($(Button.class).id("about")).focus();
// Changing field value should hide it
assertFalse(area.isVisible());
// Assert the new value
note = $(Label.class).id("admins-note");
assertEquals("<b><img>A new message</b>", note.getValue());

waitWhile(view, n -> $(Notification.class).last() == null, 2);
var notification = $(Notification.class).last();
assertEquals("<b><img>A new message</b>",
notification.getDescription());

// Return the old value
test($(Button.class).id("admin-edit")).click();
assertTrue(area.isVisible());
test(area).setValue(oldText);
test($(Button.class).id("about")).focus();
assertFalse(area.isVisible());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.IOException;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
Expand All @@ -12,6 +13,7 @@
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.testbench.elements.UIElement;
Expand All @@ -27,6 +29,11 @@ public void setup() throws Exception {
+ CategoryManagementView.VIEW_NAME);
}

@After
public void cleanup() {
$(MenuBarElement.class).first().findElement(By.id("logout-2")).click();
}

@Test
public void addAndRemoveCategory() {
waitForElementPresent(By.id("new-category"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
Expand All @@ -14,6 +15,7 @@
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.testbench.elements.PasswordFieldElement;
import com.vaadin.testbench.elements.TextFieldElement;
Expand All @@ -29,6 +31,11 @@ public void setup() throws Exception {
open("#!" + AdminView.VIEW_NAME + "/" + UserManagementView.VIEW_NAME);
}

@After
public void cleanup() {
$(MenuBarElement.class).first().findElement(By.id("logout-2")).click();
}

@Test
public void createSaveAndDeleteUser() {
waitForElementPresent(By.id("new-button"));
Expand Down Expand Up @@ -111,8 +118,7 @@ public void createSaveAndDeleteUser() {
@Test
public void visual() throws IOException {
if (visualTests()) {
assertTrue(
$(UIElement.class).first().compareScreen("user.png"));
assertTrue($(UIElement.class).first().compareScreen("user.png"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
Expand All @@ -14,6 +15,7 @@
import com.vaadin.testbench.elements.CssLayoutElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.testbench.elements.UIElement;
Expand All @@ -33,6 +35,11 @@ public void setup() throws Exception {
open("#!" + BooksView.VIEW_NAME);
}

@After
public void cleanup() {
$(MenuBarElement.class).first().findElement(By.id("logout-2")).click();
}

@Test
public void fakeGridShown() {
waitForElementPresent(By.id("fake-grid"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import java.io.IOException;

import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.By;
import org.vaadin.tatu.vaadincreate.AbstractViewTest;

import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.testbench.elements.UIElement;

public class StatsViewIT extends AbstractViewTest {
Expand All @@ -20,6 +22,11 @@ public void setup() throws Exception {
open("#!" + StatsView.VIEW_NAME);
}

@After
public void cleanup() {
$(MenuBarElement.class).first().findElement(By.id("logout-2")).click();
}

@Test
public void chartsRendered() {
var dashboard = findElement(By.className("dashboard"));
Expand Down

0 comments on commit b9ae5fd

Please sign in to comment.