Skip to content

Commit

Permalink
test: refactor ConfirmDialog ITs to use AbstractComponentIT (#6990)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Dec 27, 2024
1 parent 4766431 commit 8bc0363
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

import com.vaadin.flow.component.button.testbench.ButtonElement;
import com.vaadin.flow.component.confirmdialog.testbench.ConfirmDialogElement;
import com.vaadin.tests.AbstractParallelTest;
import com.vaadin.flow.testutil.TestPath;
import com.vaadin.tests.AbstractComponentIT;

public class BasicUseIT extends AbstractParallelTest {
@TestPath("vaadin-confirm-dialog/basicuse")
public class BasicUseIT extends AbstractComponentIT {

@Before
public void init() {
String url = getBaseURL().replace(super.getBaseURL(),
super.getBaseURL() + "/vaadin-confirm-dialog") + "/basicuse";
getDriver().get(url);
open();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.ui.ExpectedConditions;

import com.vaadin.flow.component.button.testbench.ButtonElement;
import com.vaadin.flow.component.confirmdialog.testbench.ConfirmDialogElement;
import com.vaadin.flow.testutil.TestPath;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.tests.AbstractParallelTest;
import com.vaadin.tests.AbstractComponentIT;

/**
* DimensionsIT
*/
public class DimensionsIT extends AbstractParallelTest {
@TestPath("vaadin-confirm-dialog/Dimensions")
public class DimensionsIT extends AbstractComponentIT {

@Before
public void init() {
getDriver().manage().window().setSize(WINDOW_SIZE_LARGE);
String url = getBaseURL().replace(super.getBaseURL(),
super.getBaseURL() + "/vaadin-confirm-dialog") + "/Dimensions";
getDriver().get(url);
open();
getDriver().manage().window().setSize(new Dimension(1920, 1080));

waitUntil(ExpectedConditions
.presenceOfElementLocated(By.id(Dimensions.VIEW_ID)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,136 @@
*/
package com.vaadin.flow.component.confirmdialog.tests;

import java.util.Optional;

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

import com.vaadin.flow.component.confirmdialog.tests.helpers.Actionwords;
import com.vaadin.tests.AbstractParallelTest;
import com.vaadin.flow.component.button.testbench.ButtonElement;
import com.vaadin.flow.component.confirmdialog.ConfirmDialog;
import com.vaadin.flow.component.confirmdialog.testbench.ConfirmDialogElement;
import com.vaadin.flow.testutil.TestPath;
import com.vaadin.testbench.ElementQuery;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.tests.AbstractComponentIT;

public class FeaturesDiyIT extends AbstractParallelTest {
@TestPath("vaadin-confirm-dialog/FeaturesDiy")
public class FeaturesDiyIT extends AbstractComponentIT {

public Actionwords actionwords = new Actionwords(this, FeaturesDiy.class);
@Before
public void init() {
open();
}

@Test
public void testReminderDialog() throws Exception {
String sampleName = "SampleConfirmDialog";
actionwords.iHaveSampleDialog(sampleName);
actionwords.iOpenDialogDialog(sampleName);
actionwords.iCompareTheDialogToReferenceImage(sampleName);
actionwords.iClickConfirm();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.confirmEventIsFired();
openDialog("SampleConfirmDialog");
clickConfirm();
assertDialogClosed();
assertConfirmEventIsFired();
}

@Test
public void testConfirmDeleteDialog() throws Exception {
String sampleName = "SampleConfirmDeleteDialog";
actionwords.iHaveSampleDialog(sampleName);
actionwords.iOpenDialogDialog(sampleName);
actionwords.iCompareTheDialogToReferenceImage(sampleName);
actionwords.iClickConfirm();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.confirmEventIsFired();
actionwords.iOpenDialogDialog(sampleName);
actionwords.iClickCancel();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.cancelEventIsFired();
openDialog(sampleName);
clickConfirm();
assertDialogClosed();
assertConfirmEventIsFired();

openDialog(sampleName);
clickCancel();
assertDialogClosed();
assertCancelEventIsFired();
}

@Test
public void testAreYouSureYouWantToPublishDialog() throws Exception {
String sampleName = "SampleConfirmPublishDialog";
actionwords.iHaveSampleDialog(sampleName);
actionwords.iOpenDialogDialog(sampleName);
actionwords.iCompareTheDialogToReferenceImage(sampleName);
actionwords.iClickConfirm();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.confirmEventIsFired();
actionwords.iOpenDialogDialog(sampleName);
actionwords.iClickCancel();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.cancelEventIsFired();
openDialog(sampleName);
clickConfirm();
assertDialogClosed();
assertConfirmEventIsFired();

openDialog(sampleName);
clickCancel();
assertDialogClosed();
assertCancelEventIsFired();
}

@Test
public void testUnsavedChangesDialog() throws Exception {
String sampleName = "SampleUnsavedChangesDialog";
actionwords.iHaveSampleDialog(sampleName);
actionwords.iOpenDialogDialog(sampleName);
actionwords.iCompareTheDialogToReferenceImage(sampleName);
actionwords.iClickConfirm();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.confirmEventIsFired();
actionwords.iOpenDialogDialog(sampleName);
actionwords.iClickReject();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.rejectEventIsFired();
actionwords.iOpenDialogDialog(sampleName);
actionwords.iClickCancel();
actionwords.dialogDialogIsClosed(sampleName);
actionwords.cancelEventIsFired();
openDialog(sampleName);
clickConfirm();
assertDialogClosed();
assertConfirmEventIsFired();

openDialog(sampleName);
clickReject();
assertDialogClosed();
assertRejectEventIsFired();

openDialog(sampleName);
clickCancel();
assertDialogClosed();
assertCancelEventIsFired();
}

@Test
public void testConfirmDialogButtonsCount() throws Exception {
String sampleName = "SampleConfirmDialog";
actionwords.iHaveSampleDialog(sampleName);
actionwords.iOpenDialogDialog(sampleName);
openDialog("SampleConfirmDialog");
int confirmButtonCount = findElements(By.cssSelector(
"vaadin-confirm-dialog-overlay [slot='confirm-button']"))
.size();
Assert.assertEquals(1, confirmButtonCount);
}

private void openDialog(String dialog) {
$(ButtonElement.class).id(dialog).click();
}

private Optional<ConfirmDialogElement> getConfirmDialog() {
ElementQuery<ConfirmDialogElement> query = $(ConfirmDialogElement.class)
.onPage();
return query.exists() ? Optional.of(query.first()) : Optional.empty();
}

public void assertDialogClosed() {
Assert.assertFalse(getConfirmDialog().isPresent());
}

private void clickConfirm() {
getConfirmDialog().get().getConfirmButton().click();
}

private void clickCancel() {
getConfirmDialog().get().getCancelButton().click();
}

private void clickReject() {
getConfirmDialog().get().getRejectButton().click();
}

private String getEventName() {
return $(TestBenchElement.class).id("eventName").getText();
}

private void assertConfirmEventIsFired() {
checkFiredEventName(ConfirmDialog.ConfirmEvent.class);
}

private void assertCancelEventIsFired() {
checkFiredEventName(ConfirmDialog.CancelEvent.class);
}

private void assertRejectEventIsFired() {
checkFiredEventName(ConfirmDialog.RejectEvent.class);
}

private void checkFiredEventName(Class<?> eventClass) {
Assert.assertEquals(eventClass.getSimpleName(), getEventName());
}
}

This file was deleted.

0 comments on commit 8bc0363

Please sign in to comment.