Skip to content

Commit

Permalink
Merge pull request #6717 from davidwatkins73/waltz-6716-testing-creat…
Browse files Browse the repository at this point in the history
…e-user

Playwright Testing: create user
  • Loading branch information
davidwatkins73 authored Aug 20, 2023
2 parents 21835df + e81bec2 commit b2e3f42
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static String readAsString(InputStream stream) {
checkNotNull(stream, "stream must not be null");

return streamLines(stream)
.collect(Collectors.joining());
.collect(Collectors.joining("\n"));
}


Expand Down
3 changes: 2 additions & 1 deletion waltz-ng/client/system/system-admin-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<div class="col-md-12">
<h3 ng-bind="section.name"></h3>

<div ng-repeat="option in section.options">
<div ng-repeat="option in section.options"
data-testid="{{option.name}}">
<a ui-state="option.state">
<waltz-icon class='text-muted'
fixed-width="true"
Expand Down
1 change: 1 addition & 0 deletions waltz-ng/client/user/svelte/UserCreatePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
</div>
<div class="col-sm-3">
<button class="btn btn-success"
data-testid="submit-new-user-btn"
on:click={() => registerUser()}
disabled={disabled}>
Register
Expand Down
1 change: 1 addition & 0 deletions waltz-ng/client/user/svelte/UserSelectList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<p>
Use the search below to select a user and edit their roles or
<button class="btn btn-skinny"
data-testid="add-user-btn"
on:click={() => $activeMode = Modes.ADD}>
<Icon name="plus"/> add a new user
</button>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import org.finos.waltz.common.StringUtilities;
import org.finos.waltz.common.IOUtilities;

import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import static java.lang.String.format;
import static org.finos.waltz.common.StringUtilities.mkPath;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class ScreenshotHelper {

Expand All @@ -18,6 +24,7 @@ public class ScreenshotHelper {

private final Page page;
private final String basePath;
private final Map<String, String> filenameMap = new HashMap<>();

public ScreenshotHelper(Page page, String basePath) {
this.page = page;
Expand All @@ -28,7 +35,7 @@ public ScreenshotHelper(Page page, String basePath) {
public Locator takeElemSnapshot(Locator locator, String name) {
if (! paused) {
Locator.ScreenshotOptions options = new Locator.ScreenshotOptions()
.setPath(mkPath(name));
.setPath(mkNameWithStep(name));

locator.screenshot(options);
}
Expand All @@ -39,7 +46,7 @@ public Locator takeElemSnapshot(Locator locator, String name) {
public Page takePageSnapshot(Page page, String name) {
if (! paused) {
Page.ScreenshotOptions options = new Page.ScreenshotOptions()
.setPath(mkPath(name));
.setPath(mkNameWithStep(name));

page.screenshot(options);
}
Expand All @@ -55,7 +62,7 @@ public Locator takePageSnapshot(Locator locator, String name) {
if (! paused) {
Page.ScreenshotOptions options = new Page
.ScreenshotOptions()
.setPath(mkPath(name));
.setPath(mkNameWithStep(name));

page.screenshot(options);
}
Expand All @@ -78,11 +85,34 @@ public ScreenshotHelper resume() {

// -- HELPER ---

private Path mkPath(String name) {
return Paths.get(StringUtilities.mkPath(
private Path mkNameWithStep(String name) {
String nameWithStep = format("%d_%s", counter.incrementAndGet(), name);
filenameMap.put(name, nameWithStep);
return Paths.get(mkPath(
"screenshots",
basePath,
format("%d_%s", counter.incrementAndGet(), name)));
nameWithStep));
}


public void prepareDocumentation() throws IOException {
String templatePath = mkPath(basePath, "template.md");
InputStream templateStream = this.getClass().getClassLoader().getResourceAsStream(templatePath);

assertNotNull(templateStream, String.format("Could not find template on classpath: %s", templatePath));

String templateStr = IOUtilities.readAsString(templateStream);
for (Map.Entry<String, String> entry : filenameMap.entrySet()) {
templateStr = templateStr.replaceAll(
format("\\{\\{%s\\}\\}", entry.getKey()),
format("![%s](%s \"%s\")", entry.getKey(), entry.getValue(), entry.getKey()));
}

System.out.println(templateStr);

String outputPath = mkPath("screenshots", basePath, "README.md");
FileWriter fw = new FileWriter(outputPath);
fw.write(templateStr);
fw.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setupAssessmentData() throws IOException {
public void searchForExactMatch() {
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/applications/search");
"applications/search");

startSiteSearch(
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setupAssessmentData() throws IOException {
public void exactSearch() {
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/databases/search");
"databases/search");

startSiteSearch(
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void add() throws InterruptedException {

ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/flow-classification-rule/create");
"flow-classification-rule/create");

Locator listLocator = page.getByTestId("flow-classification-rule-list");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public void setup() throws IOException {


@Test
public void createGrid() throws InsufficientPrivelegeException {
public void createGrid() throws InsufficientPrivelegeException, IOException {
String name = mkName("report-grid-create-grid");
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/report-grid/create-grid");
"report-grid/create-grid");

EntityReference appRef1 = appHelper.createNewApp(mkName("rg-app1"), 10L);
EntityReference appRef2 = appHelper.createNewApp(mkName("rg-app2"), 10L);
Expand Down Expand Up @@ -96,6 +96,8 @@ public void createGrid() throws InsufficientPrivelegeException {
screenshotHelper.takeElemSnapshot(grid, "grid_data.png");
assertThat(grid.locator("div.ui-grid-cell").getByTestId("entity-name").getByText(appRef1.name().get())).isVisible();
assertThat(grid.locator("div.ui-grid-cell").getByTestId("entity-name").getByText(appRef2.name().get())).isVisible();

screenshotHelper.prepareDocumentation();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void createTemplate() {
String name = mkName("surveys-create-template");
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/survey/create-template");
"survey/create-template");
createSurveyTemplate(screenshotHelper, name);
activateSurveyTemplate(screenshotHelper, name);
}
Expand All @@ -70,7 +70,7 @@ public void singleIssuance() {
String name = mkName("surveys-single-issuance");
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/survey/single-issuance");
"survey/single-issuance");

screenshotHelper.pause();

Expand Down Expand Up @@ -111,7 +111,7 @@ public void runIssuance() throws InsufficientPrivelegeException {
String name = mkName("surveys-run-issuance");
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"screenshots/survey/run-issuance");
"survey/run-issuance");

screenshotHelper.pause();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.finos.waltz.test_common.playwright.user_roles;

import com.microsoft.playwright.Locator;
import org.finos.waltz.test_common.playwright.BasePlaywrightIntegrationTest;
import org.finos.waltz.test_common.playwright.ScreenshotHelper;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static org.finos.waltz.common.StringUtilities.mkPath;
import static org.finos.waltz.test_common.helpers.NameHelper.mkName;
import static org.finos.waltz.test_common.playwright.PlaywrightUtilities.login;

public class UserRoleTests extends BasePlaywrightIntegrationTest {

public static final String HIGHLIGHT_ELEM_SCRIPT = "d => d.style.border = '2px solid red'";

@Test
public void registerUserViaUI() throws IOException {
ScreenshotHelper screenshotHelper = new ScreenshotHelper(
page,
"user/registration");

login(page, BASE);

page.navigate(mkPath(BASE, "system", "list"));

Locator userMgmtItem = page.getByTestId("Manage Users");
assertThat(userMgmtItem).isVisible();
userMgmtItem.evaluate(HIGHLIGHT_ELEM_SCRIPT);
screenshotHelper.takePageSnapshot(page, "admin_page.png");

userMgmtItem.locator("a").click();

Locator addUserBtn = page.getByTestId("add-user-btn");
addUserBtn.evaluate(HIGHLIGHT_ELEM_SCRIPT);
screenshotHelper.takePageSnapshot(page, "add_user_button.png");
addUserBtn.click();

screenshotHelper.takePageSnapshot(page, "blank_add_user_form.png");
Locator submitBtn = page.getByTestId("submit-new-user-btn");
assertThat(submitBtn).isDisabled();

String username = mkName("add_user");
String password = mkName("add_user_pwd");

page.fill("#username", username);
page.fill("#password", password);

assertThat(submitBtn).isEnabled();
screenshotHelper.takePageSnapshot(page, "completed_add_user_form.png");
submitBtn.click();

Locator header = page.locator("h4").getByText(username);
assertThat(header).isVisible();
screenshotHelper.takePageSnapshot(page, "user_registered.png");

screenshotHelper.prepareDocumentation();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Report Grid Creation

Report grids display information about whatever apps or change initiatives their parent page includes.
In this example we are going to use starting point of a simple application group with two apps.
We will then build up an example report pulling in some assessments, organisational and other data points.



## Open the Report Grid section

Report grids are accessible from any grouping page in Waltz and can be found on the left hand navigation menu.


| Step | Image |
|----------------------------------------------------|-----------------------------|
| First we need to open the "_Report Grids_" section | {{grid_section_opened.png}} |


## Create the basic grid

To create a grid we need to give it a name, optionally set a description and chose whether
the grid will display information about _Applications_ or _Change Initiatives_


| Step | Image |
|-----------------------------------------------------------------------------------------------------------------------|------------------------|
| Next, create a new grid using the "_Create a new report grid_" button | {{new_grid_form.png}} |
| Fill in a title and description, in this example the report will be about Applications so we will leave that selected | {{completed_form.png}} |
| When we submit the form we will be taken to the column editor to customise the grid | {{submitted_form.png}} |

## Customising the grid

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# User Registration


| Step | Image |
|--------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| Navigate to admin page and click on user management link | {{admin_page.png}} |
| Select the "_add a new user_ " link | {{add_user_button.png}} |
| Fill in the new user registration form, once completed the "_Register_" button will be enables | {{blank_add_user_form.png}} {{completed_add_user_form.png}} |
| When you submit the form the user will be created and you will be presented with the user roles screen | {{user_registered.png}} |

0 comments on commit b2e3f42

Please sign in to comment.