mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added Groups E2E tests
This commit is contained in:
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user