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:
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