mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Merge pull request #292 from LD-Reborn/289-e2e-tests---groups
289 e2e tests groups
This commit is contained in:
@@ -324,7 +324,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="updateGroupForm">
|
<form id="updateGroupForm">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="row g-3 justify-content-center">
|
<div class="row g-3 justify-content-center">
|
||||||
<!-- Basic Info -->
|
<!-- Basic Info -->
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
@@ -383,10 +383,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const updateButtons = document.querySelectorAll('.btn-update');
|
const updateButtons = document.querySelectorAll('.btn-update');
|
||||||
const updateModal = document.getElementById('updateGroupModal');
|
const updateModal = document.getElementById('updateGroupModal');
|
||||||
const updateForm = document.getElementById('updateGroupForm');
|
const updateForm = document.getElementById('updateGroupForm');
|
||||||
|
var groupId;
|
||||||
updateModal.addEventListener('show.bs.modal', async event => {
|
updateModal.addEventListener('show.bs.modal', async event => {
|
||||||
const button = event.relatedTarget;
|
const button = event.relatedTarget;
|
||||||
const groupId = button.getAttribute('data-group-id');
|
groupId = button.getAttribute('data-group-id');
|
||||||
|
|
||||||
updateForm.reset();
|
updateForm.reset();
|
||||||
|
|
||||||
@@ -441,6 +441,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
jsonData.Description.Permissions = permissions;
|
jsonData.Description.Permissions = permissions;
|
||||||
jsonData.Description.DisplayName = jsonData.DisplayName;
|
jsonData.Description.DisplayName = jsonData.DisplayName;
|
||||||
jsonData.DisplayName = null;
|
jsonData.DisplayName = null;
|
||||||
|
jsonData.NewCn = jsonData.Cn;
|
||||||
|
jsonData.Cn = groupId;
|
||||||
|
buttons = $(`button[data-group-id=\"${jsonData.Cn}\"]`);
|
||||||
|
buttons.each(i => buttons[i].setAttribute("data-group-id", jsonData.NewCn));
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/Groups/Update', {
|
const response = await fetch('/Groups/Update', {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
|
|||||||
58
tests/Berufsschule_HAM.E2ETests/GroupsPageTests.cs
Normal file
58
tests/Berufsschule_HAM.E2ETests/GroupsPageTests.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using Berufsschule_HAM.E2ETests.Helper;
|
||||||
|
using OpenQA.Selenium;
|
||||||
|
using OpenQA.Selenium.Chrome;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Berufsschule_HAM.E2ETests;
|
||||||
|
|
||||||
|
public class GroupsPageTests : IDisposable
|
||||||
|
{
|
||||||
|
private readonly ChromeDriver _driver;
|
||||||
|
public Uri serverUri;
|
||||||
|
public string serverUrl;
|
||||||
|
public Process serverProcess;
|
||||||
|
|
||||||
|
public GroupsPageTests()
|
||||||
|
{
|
||||||
|
serverUrl = AppHelper.ServerUrl;
|
||||||
|
serverUri = AppHelper.ServerUri;
|
||||||
|
Task<Process> app = AppHelper.StartApp(serverUrl);
|
||||||
|
_driver = AppHelper.GetChromeDriver();
|
||||||
|
serverProcess = app.Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GroupsPage_ShouldShowButton()
|
||||||
|
{
|
||||||
|
AppHelper.Login(_driver);
|
||||||
|
GroupsHelper.NavigateToGroupsPage(_driver);
|
||||||
|
_driver.FindElement(By.CssSelector("button[data-bs-target=\"#createGroupModal\"]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GroupsPage_ShouldShowCreateViewModal()
|
||||||
|
{
|
||||||
|
AppHelper.Login(_driver);
|
||||||
|
GroupsHelper.NavigateToGroupsPage(_driver);
|
||||||
|
List<string> ids = ["cn", "displayname", "canInventorize", "canManageAssets", "canManageUsers", "canManageGroups", "canManageLocations", "canManageSettings"];
|
||||||
|
List<string> css = ["#createGroupForm .btn-primary", "#createGroupForm .btn-secondary"];
|
||||||
|
ids.ForEach(id => _driver.FindElement(By.Id(id)));
|
||||||
|
css.ForEach(selector => _driver.FindElement(By.CssSelector(selector)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GroupsPage_ShouldCreateAndUpdateAndDeleteGroup()
|
||||||
|
{
|
||||||
|
AppHelper.Login(_driver);
|
||||||
|
GroupsHelper.NavigateToGroupsPage(_driver);
|
||||||
|
GroupsHelper.CreateGroup(_driver, "RESERVED_TEST", "TEST GROUP", true, true, true, true, true, true);
|
||||||
|
GroupsHelper.UpdateGroup(_driver, "RESERVED_TEST", "RESERVED_TEST2", "TEST GROUP", false, false, false, false, false, false);
|
||||||
|
GroupsHelper.UpdateGroup(_driver, "RESERVED_TEST2", "RESERVED_TEST", "TEST GROUP", true, true, true, true, true, true);
|
||||||
|
GroupsHelper.DeleteGroup(_driver, "RESERVED_TEST");
|
||||||
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_driver.Quit();
|
||||||
|
serverProcess.Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,4 +65,40 @@ public static class AppHelper
|
|||||||
submit.Click();
|
submit.Click();
|
||||||
Thread.Sleep(250);
|
Thread.Sleep(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool TryRetryFindSuccessToast(ChromeDriver driver)
|
||||||
|
{
|
||||||
|
int retryCounter = 0;
|
||||||
|
retry:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
IWebElement successToast = driver.FindElement(By.CssSelector("#toastContainer div.bg-success"));
|
||||||
|
if (successToast.Displayed)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IWebElement failToast = driver.FindElement(By.CssSelector("#toastContainer div.bg-danger"));
|
||||||
|
if (failToast.Displayed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
if (++retryCounter < 5)
|
||||||
|
{
|
||||||
|
Thread.Sleep(250);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool CheckboxGetState(IWebElement webElement)
|
||||||
|
{
|
||||||
|
return webElement.GetAttribute("checked") == "true";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
83
tests/Berufsschule_HAM.E2ETests/Helper/GroupsHelper.cs
Normal file
83
tests/Berufsschule_HAM.E2ETests/Helper/GroupsHelper.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net;
|
||||||
|
using OpenQA.Selenium;
|
||||||
|
using OpenQA.Selenium.Chrome;
|
||||||
|
using OpenQA.Selenium.Support.UI;
|
||||||
|
|
||||||
|
namespace Berufsschule_HAM.E2ETests.Helper;
|
||||||
|
|
||||||
|
public static class GroupsHelper
|
||||||
|
{
|
||||||
|
public static void CreateGroup(ChromeDriver driver, string cn, string displayName, bool canInventorize, bool canManageAssets, bool canManageUsers, bool canManageGroups, bool canManageLocations, bool canManageSettings)
|
||||||
|
{
|
||||||
|
NavigateToGroupsPage(driver);
|
||||||
|
IWebElement createGroupButton = driver.FindElement(By.CssSelector("button[data-bs-target=\"#createGroupModal\"]"));
|
||||||
|
createGroupButton.Click();
|
||||||
|
Thread.Sleep(500);
|
||||||
|
driver.FindElement(By.Id("cn")).SendKeys(cn);
|
||||||
|
driver.FindElement(By.Id("displayname")).SendKeys(displayName);
|
||||||
|
if (canInventorize) driver.FindElement(By.Id("canInventorize")).Click();
|
||||||
|
if (canManageAssets) driver.FindElement(By.Id("canManageAssets")).Click();
|
||||||
|
if (canManageUsers) driver.FindElement(By.Id("canManageUsers")).Click();
|
||||||
|
if (canManageGroups) driver.FindElement(By.Id("canManageGroups")).Click();
|
||||||
|
if (canManageLocations) driver.FindElement(By.Id("canManageLocations")).Click();
|
||||||
|
if (canManageSettings) driver.FindElement(By.Id("canManageSettings")).Click();
|
||||||
|
IWebElement createButton = driver.FindElement(By.CssSelector("#createGroupForm .btn-primary"));
|
||||||
|
createButton.Click();
|
||||||
|
Assert.True(AppHelper.TryRetryFindSuccessToast(driver));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateGroup(ChromeDriver driver, string cn, string newCn, string displayName, bool canInventorize, bool canManageAssets, bool canManageUsers, bool canManageGroups, bool canManageLocations, bool canManageSettings)
|
||||||
|
{
|
||||||
|
NavigateToGroupsPage(driver);
|
||||||
|
IWebElement updateGroupButton = driver.FindElement(By.CssSelector($"button[data-group-id=\"{cn}\"].btn-update"));
|
||||||
|
updateGroupButton.Click();
|
||||||
|
Thread.Sleep(500);
|
||||||
|
var cnInput = driver.FindElement(By.CssSelector("input#groupId"));
|
||||||
|
cnInput.Click();
|
||||||
|
cnInput.Clear();
|
||||||
|
cnInput.SendKeys(newCn);
|
||||||
|
|
||||||
|
IWebElement displayNameInput = driver.FindElement(By.Id("dn"));
|
||||||
|
displayNameInput.Click();
|
||||||
|
displayNameInput.Clear();
|
||||||
|
displayNameInput.SendKeys(displayName);
|
||||||
|
Dictionary<string, bool> selectors = new()
|
||||||
|
{
|
||||||
|
["#updateGroupForm #canInventorize"] = canInventorize,
|
||||||
|
["#updateGroupForm #canManageAssets"] = canManageAssets,
|
||||||
|
["#updateGroupForm #canManageUsers"] = canManageUsers,
|
||||||
|
["#updateGroupForm #canManageGroups"] = canManageGroups,
|
||||||
|
["#updateGroupForm #canManageLocations"] = canManageLocations,
|
||||||
|
["#updateGroupForm #canManageSettings"] = canManageSettings
|
||||||
|
};
|
||||||
|
selectors.ToList().ForEach(kvp =>
|
||||||
|
{
|
||||||
|
string name = kvp.Key;
|
||||||
|
bool value = kvp.Value;
|
||||||
|
IWebElement input = driver.FindElement(By.CssSelector(name));
|
||||||
|
if (value != AppHelper.CheckboxGetState(input)) input.Click();
|
||||||
|
});
|
||||||
|
IWebElement updateButton = driver.FindElement(By.CssSelector("#updateGroupForm .btn-warning"));
|
||||||
|
updateButton.Click();
|
||||||
|
Assert.True(AppHelper.TryRetryFindSuccessToast(driver));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void DeleteGroup(ChromeDriver driver, string cn)
|
||||||
|
{
|
||||||
|
NavigateToGroupsPage(driver);
|
||||||
|
IWebElement deleteButton = driver.FindElement(By.CssSelector($"button[data-group-id=\"{cn}\"].btn-delete"));
|
||||||
|
deleteButton.Click();
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
driver.FindElement(By.Id("deleteModal"));
|
||||||
|
IWebElement deleteConfirmButton = driver.FindElement(By.CssSelector("#deleteModal .btn-danger"));
|
||||||
|
deleteConfirmButton.Click();
|
||||||
|
Assert.True(AppHelper.TryRetryFindSuccessToast(driver));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NavigateToGroupsPage(ChromeDriver driver)
|
||||||
|
{
|
||||||
|
driver.Navigate().GoToUrl(new Uri(AppHelper.ServerUri, "/Home/Groups"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,13 +77,7 @@ public class InventoryPageTests : IDisposable
|
|||||||
IWebElement okButton = _driver.FindElement(By.CssSelector("#viewAssetModal button.btn.btn-primary[data-bs-dismiss=\"modal\"]"));
|
IWebElement okButton = _driver.FindElement(By.CssSelector("#viewAssetModal button.btn.btn-primary[data-bs-dismiss=\"modal\"]"));
|
||||||
okButton.Click();
|
okButton.Click();
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
IWebElement successToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-success"));
|
Assert.True(AppHelper.TryRetryFindSuccessToast(_driver));
|
||||||
Assert.True(successToast.Displayed);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IWebElement failToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-danger"));
|
|
||||||
Assert.False(failToast.Displayed);
|
|
||||||
} catch (Exception) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -104,13 +98,7 @@ public class InventoryPageTests : IDisposable
|
|||||||
IWebElement okButton = _driver.FindElement(By.CssSelector("#updateAssetModal button.btn.btn-warning[type=\"submit\"]"));
|
IWebElement okButton = _driver.FindElement(By.CssSelector("#updateAssetModal button.btn.btn-warning[type=\"submit\"]"));
|
||||||
okButton.Click();
|
okButton.Click();
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
IWebElement successToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-success"));
|
Assert.True(AppHelper.TryRetryFindSuccessToast(_driver));
|
||||||
Assert.True(successToast.Displayed);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IWebElement failToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-danger"));
|
|
||||||
Assert.False(failToast.Displayed);
|
|
||||||
} catch (Exception) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user