From 17438989ec89ff3aa52f1554b6980f7f7f2cdc43 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Thu, 6 Nov 2025 19:28:48 +0100 Subject: [PATCH] Added InventoryPageTests --- .../InventoryPageTests.cs | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/Berufsschule_HAM.E2ETests/InventoryPageTests.cs diff --git a/tests/Berufsschule_HAM.E2ETests/InventoryPageTests.cs b/tests/Berufsschule_HAM.E2ETests/InventoryPageTests.cs new file mode 100644 index 0000000..dbd1568 --- /dev/null +++ b/tests/Berufsschule_HAM.E2ETests/InventoryPageTests.cs @@ -0,0 +1,144 @@ +using Berufsschule_HAM.E2ETests.Helper; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using System.Diagnostics; + +namespace Berufsschule_HAM.E2ETests; + +public class InventoryPageTests : IDisposable +{ + private readonly ChromeDriver _driver; + public Uri serverUri; + public string serverUrl; + public Process serverProcess; + + public InventoryPageTests() + { + serverUrl = AppHelper.ServerUrl; + serverUri = AppHelper.ServerUri; + Task app = AppHelper.StartApp(serverUrl); + _driver = AppHelper.GetChromeDriver(); + serverProcess = app.Result; + } + + [Fact] + public void InventoryPage_ShouldShowButtons() + { + AppHelper.Login(_driver); + _driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory")); + _driver.FindElement(By.CssSelector("a[href=\"/Home/Assets?CreateModal=true\"]")); + _driver.FindElement(By.Id("barcodeInput")); + _driver.FindElement(By.Id("enterAssetIdManuallyButton")); + _driver.FindElement(By.Id("scanBarcodeButton")); + } + + [Fact] + public void InventoryPage_ShouldShowCompleteViewModal() + { + AppHelper.Login(_driver); + _driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory")); + IWebElement assetIdInputField = _driver.FindElement(By.Id("barcodeInput")); + assetIdInputField.SendKeys("1"); + IWebElement scanBarcode = _driver.FindElement(By.Id("enterAssetIdManuallyButton")); + scanBarcode.Click(); + Thread.Sleep(500); + IWebElement viewModal = _driver.FindElement(By.Id("viewAssetModal")); + Assert.True(viewModal.Displayed); + Assert.True(_driver.FindElement(By.CssSelector("svg[class=\"form-control\"]")).Displayed); + Thread.Sleep(500); + + Assert.NotEmpty(_driver.FindElement(By.Id("detailName")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailLocation")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailOwner")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailSerialNumber")).GetAttribute("value") ?? ""); + + Assert.NotEmpty(_driver.FindElement(By.Id("detailType")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailMake")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailModel")).GetAttribute("value") ?? ""); + + Assert.NotEmpty(_driver.FindElement(By.Id("detailPurchaseDate")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailPurchaseValue")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailPurchaseAt")).GetAttribute("value") ?? ""); + Assert.NotEmpty(_driver.FindElement(By.Id("detailPurchaseBy")).GetAttribute("value") ?? ""); + } + + [Fact] + public void InventoryPage_ShouldShowSuccessToastOnInformationCorrect() + { + AppHelper.Login(_driver); + _driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory")); + IWebElement assetIdInputField = _driver.FindElement(By.Id("barcodeInput")); + assetIdInputField.SendKeys("1"); + IWebElement scanBarcode = _driver.FindElement(By.Id("enterAssetIdManuallyButton")); + scanBarcode.Click(); + Thread.Sleep(500); + IWebElement viewModal = _driver.FindElement(By.Id("viewAssetModal")); + Assert.True(viewModal.Displayed); + IWebElement okButton = _driver.FindElement(By.CssSelector("#viewAssetModal button.btn.btn-primary[data-bs-dismiss=\"modal\"]")); + okButton.Click(); + Thread.Sleep(500); + IWebElement successToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-success")); + Assert.True(successToast.Displayed); + try + { + IWebElement failToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-danger")); + Assert.False(failToast.Displayed); + } catch (Exception) {} + } + + [Fact] + public void InventoryPage_ShouldShowSuccessToastOnInformationUpdate() + { + AppHelper.Login(_driver); + _driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory")); + IWebElement assetIdInputField = _driver.FindElement(By.Id("barcodeInput")); + assetIdInputField.SendKeys("1"); + IWebElement scanBarcode = _driver.FindElement(By.Id("enterAssetIdManuallyButton")); + scanBarcode.Click(); + Thread.Sleep(500); + IWebElement viewModal = _driver.FindElement(By.Id("viewAssetModal")); + Assert.True(viewModal.Displayed); + IWebElement updateButton = _driver.FindElement(By.CssSelector("#viewAssetModal button.btn.btn-warning[data-bs-dismiss=\"modal\"]")); + updateButton.Click(); + Thread.Sleep(1000); + IWebElement okButton = _driver.FindElement(By.CssSelector("#updateAssetModal button.btn.btn-warning[type=\"submit\"]")); + okButton.Click(); + Thread.Sleep(500); + IWebElement successToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-success")); + Assert.True(successToast.Displayed); + try + { + IWebElement failToast = _driver.FindElement(By.CssSelector("#toastContainer div.bg-danger")); + Assert.False(failToast.Displayed); + } catch (Exception) {} + } + + [Fact] + public void InventoryPage_ShouldLeadToAssetPage() + { + AppHelper.Login(_driver); + _driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory")); + IWebElement link = _driver.FindElement(By.CssSelector("a[href=\"/Home/Assets?CreateModal=true\"]")); + link.Click(); + Thread.Sleep(500); + Assert.Contains("/Home/Assets", _driver.Url); + } + + [Fact] + public void InventoryPage_ShouldShowPrintModal() + { + AppHelper.Login(_driver); + _driver.Navigate().GoToUrl(new Uri(serverUri, "/Home/Inventory")); + IWebElement openPrintModalButton = _driver.FindElement(By.Id("openPrintModal")); + openPrintModalButton.Click(); + Thread.Sleep(500); + IWebElement printModal = _driver.FindElement(By.Id("printModal")); + Assert.True(printModal.Displayed); + } + + public void Dispose() + { + _driver.Quit(); + serverProcess.Kill(); + } +}