From 76d7a8a858399d7ad196d78d45efa29970e35b79 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Tue, 3 Dec 2024 20:43:33 -0600 Subject: [PATCH] CE-1955 Initial checkin --- .../selenium/BaseSampleSeleniumTest.java | 85 +++++++++++++++++ .../selenium/BulkLoadSeleniumTest.java | 95 +++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BaseSampleSeleniumTest.java create mode 100644 qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BulkLoadSeleniumTest.java diff --git a/qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BaseSampleSeleniumTest.java b/qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BaseSampleSeleniumTest.java new file mode 100644 index 00000000..a0a904fc --- /dev/null +++ b/qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BaseSampleSeleniumTest.java @@ -0,0 +1,85 @@ +/* + * Copyright © 2022-2023. ColdTrack . All Rights Reserved. + */ + +package com.kingsrook.sampleapp.selenium; + + +import com.kingsrook.qqq.backend.core.logging.QLogger; +import com.kingsrook.qqq.frontend.materialdashboard.selenium.lib.QBaseSeleniumTest; +import com.kingsrook.sampleapp.SampleJavalinServer; +import org.junit.jupiter.api.BeforeEach; + + +/******************************************************************************* + ** + *******************************************************************************/ +public class BaseSampleSeleniumTest extends QBaseSeleniumTest +{ + private static final QLogger LOG = QLogger.getLogger(BaseSampleSeleniumTest.class); + + public static final Integer DEFAULT_WAIT_SECONDS = 10; + + private int port = 8011; + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + @BeforeEach + public void beforeEach() + { + super.beforeEach(); + qSeleniumLib.withBaseUrl("http://localhost:" + port); + qSeleniumLib.withWaitSeconds(DEFAULT_WAIT_SECONDS); + + new SampleJavalinServer().startJavalinServer(port); + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + protected boolean useInternalJavalin() + { + return (false); + } + + + + + /******************************************************************************* + ** + *******************************************************************************/ + public void clickLeftNavMenuItem(String text) + { + qSeleniumLib.waitForSelectorContaining(".MuiDrawer-paperAnchorLeft .MuiListItem-root", text).click(); + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + public void clickLeftNavMenuItemThenSubItem(String text, String subItemText) + { + qSeleniumLib.waitForSelectorContaining(".MuiDrawer-paperAnchorLeft .MuiListItem-root", text).click(); + qSeleniumLib.waitForSelectorContaining(".MuiDrawer-paperAnchorLeft .MuiCollapse-vertical.MuiCollapse-entered .MuiListItem-root", subItemText).click(); + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + public void goToPathAndWaitForSelectorContaining(String path, String selector, String text) + { + driver.get(qSeleniumLib.getBaseUrl() + path); + qSeleniumLib.waitForSelectorContaining(selector, text); + } + +} + diff --git a/qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BulkLoadSeleniumTest.java b/qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BulkLoadSeleniumTest.java new file mode 100644 index 00000000..02f2785d --- /dev/null +++ b/qqq-sample-project/src/test/java/com/kingsrook/sampleapp/selenium/BulkLoadSeleniumTest.java @@ -0,0 +1,95 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2024. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.sampleapp.selenium; + + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.UUID; +import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.Test; + + +/******************************************************************************* + ** + *******************************************************************************/ +public class BulkLoadSeleniumTest extends BaseSampleSeleniumTest +{ + /******************************************************************************* + ** + *******************************************************************************/ + @Test + void testSimple() throws IOException + { + String email = "jtkirk@starfleet.com"; + String tablePath = "/peopleApp/greetingsApp/person"; + + //////////////////////////////////// + // write a file to be bulk-loaded // + //////////////////////////////////// + String path = "/tmp/" + UUID.randomUUID() + ".csv"; + String csv = String.format(""" + email,firstName,lastName + %s,James T.,Kirk + """, email); + FileUtils.writeStringToFile(new File(path), csv, StandardCharsets.UTF_8); + + goToPathAndWaitForSelectorContaining(tablePath + "/person.bulkInsert", ".MuiTypography-h5", "Person Bulk Insert: Upload File"); + + ////////////////////////////// + // complete the upload form // + ////////////////////////////// + qSeleniumLib.waitForSelector("input[type=file]").sendKeys(path); + qSeleniumLib.waitForSelectorContaining("button", "next").click(); + + ///////////////////////////////////////// + // proceed through file-mapping screen // + ///////////////////////////////////////// + qSeleniumLib.waitForSelectorContaining("button", "next").click(); + + ////////////////////////////////////////////////// + // confirm data on preview screen, then proceed // + ////////////////////////////////////////////////// + qSeleniumLib.waitForSelectorContaining("form#review .MuiTypography-body2 div", email); + qSeleniumLib.waitForSelectorContaining("form#review .MuiTypography-body2 div", "Preview 1 of 1"); + qSeleniumLib.waitForSelectorContaining("button", "arrow_forward").click(); // to avoid the record-preview 'next' button + + /////////////////////////////////////// + // proceed through validation screen // + /////////////////////////////////////// + qSeleniumLib.waitForSelectorContaining("button", "submit").click(); + + //////////////////////////////////////// + // confirm result screen and close it // + //////////////////////////////////////// + qSeleniumLib.waitForSelectorContaining(".MuiListItemText-root", "1 Person record was inserted"); + qSeleniumLib.waitForSelectorContaining("button", "close").click(); + + //////////////////////////////////////////// + // go to the order that was just inserted // + // bonus - also test record-view-by-key // + //////////////////////////////////////////// + goToPathAndWaitForSelectorContaining(tablePath + "/key?email=" + email, "h5", "Viewing Person"); + } + +}