feat: Adds purchase order view tests.

This commit is contained in:
2025-01-24 08:16:51 -05:00
parent 5695d0e13c
commit 94f0c660ff
9 changed files with 414 additions and 14 deletions

View File

@@ -63,20 +63,41 @@ struct ViewControllerTests {
}
}
// @Test
// func purchaseOrderViews() async throws {
// try await withSnapshotTesting(record: record) {
// try await withDependencies {
// $0.database.purchaseOrders = .mock
// $0.viewController = .liveValue
// } operation: {
// @Dependency(\.viewController) var viewController
//
// let htmlString = try await viewController.render(.login(.index(next: "/purchase-orders")))
// assertSnapshot(of: htmlString, as: .html)
// }
// }
// }
@Test
func purchaseOrderViews() async throws {
try await withSnapshotTesting(record: record) {
try await withDependencies {
$0.dateFormatter = .liveValue
$0.database.purchaseOrders = .mock
$0.viewController = .liveValue
} operation: {
@Dependency(\.viewController) var viewController
var htmlString = try await viewController.render(.purchaseOrder(.index))
assertSnapshot(of: htmlString, as: .html)
htmlString = try await viewController.render(.purchaseOrder(.form))
assertSnapshot(of: htmlString, as: .html)
htmlString = try await viewController.render(.purchaseOrder(.create(.mock)))
assertSnapshot(of: htmlString, as: .html)
htmlString = try await viewController.render(.purchaseOrder(.get(id: 1)))
assertSnapshot(of: htmlString, as: .html)
htmlString = try await viewController.render(.purchaseOrder(.page(page: 1, limit: 25)))
assertSnapshot(of: htmlString, as: .html)
for context in ViewRoute.PurchaseOrderRoute.Search.Context.allCases {
htmlString = try await viewController.render(.purchaseOrder(.search(.index(
context: context,
table: true
))))
assertSnapshot(of: htmlString, as: .html)
}
}
}
}
@Test
func userViews() async throws {
@@ -183,6 +204,21 @@ extension DatabaseClient.Employees {
}
}
extension DatabaseClient.PurchaseOrders {
static var mock: Self {
.init(
create: { _ in .mock },
fetchAll: { [.mock] },
fetchPage: { _ in .init(items: [.mock], metadata: .init(page: 1, per: 1, total: 1)) },
get: { _ in .mock },
delete: { _ in },
search: { _, _ in .init(items: [.mock], metadata: .init(page: 1, per: 1, total: 1)) }
)
}
}
extension DatabaseClient.Users {
static var mock: Self {
.init(
@@ -341,3 +377,9 @@ extension PurchaseOrder {
)
}
}
extension PurchaseOrder.Create {
static var mock: Self {
.init(materials: "bar", customer: "Testy McTestface", createdByID: UUID(0), createdForID: UUID(0), vendorBranchID: UUID(0))
}
}

View File

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purchase Orders</title>
<meta charset="UTF-8">
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="/js/main.js"></script>
<link rel="stylesheet" href="/css/main.css">
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
</head>
<body>
<header class="header">
<div id="logo">HHE - Purchase Orders</div>
<div class="sidepanel" id="sidepanel">
<a href="javascript:void(0)" class="closebtn" onclick="closeSidepanel()">x</a><a hx-get="/purchase-orders?page=1&amp;limit=50" hx-target="body" hx-push-url="true">Purchase Orders</a><a hx-get="/users" hx-target="body" hx-push-url="true">Users</a><a hx-get="/employees" hx-target="body" hx-push-url="true">Employees</a><a hx-get="/vendors" hx-target="body" hx-push-url="true">Vendors</a>
<div style="border-bottom: 1px solid grey; margin-bottom: 5px;"></div>
Logout<a hx-post="/logout" hx-target="#content" hx-swap="outerHTML" hx-trigger="click"></a>
</div>
<button class="openbtn" onclick="openSidepanel()">
<img src="/images/menu.svg" style="width: 30px;, height: 30px;">
</button>
</header>
<div class="container" style="padding: 20px 20px;">
<h1>Purchase Orders</h1>
<br>
<p class="secondary"><i></i></p>
<br>
</div>
<div class="container" id="purchase-order-content">
<div id="float" class="" style="display: hidden;"></div>
<table id="purchase-order">
<thead>
<tr>
<div class="btn-row">
<button id="btn-search" class="btn-primary" style="position: absolute; top: 80px; right: 20px;" hx-get="/purchase-orders/search?table=true" hx-target="body" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true">
<img src="/images/search.svg" width="30" height="30">
</button>
</div>
</tr>
<tr>
<th>PO</th>
<th>Work Order</th>
<th>Customer</th>
<th>Vendor</th>
<th>Materials</th>
<th>Created For</th>
<th>
<button class="btn btn-add" hx-get="/purchase-orders/create" hx-target="#float" hx-swap="outerHTML" hx-push-url="true">+</button>
</th>
</tr>
</thead>
<tbody id="purchase-order-table">
<tr id="purchase-order-1">
<td>1</td>
<td>12245</td>
<td>Testy McTestface</td>
<td>Test - Mock</td>
<td>foo</td>
<td>Testy Mctestface</td>
<td>
<button class="btn-detail" hx-get="/purchase-orders/1" hx-target="#float" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true"></button>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

View File

@@ -0,0 +1,32 @@
<div id="float" class="float" style="display: block;">
<div class="btn-row">
<button class="btn-close" onclick="toggleContent('float'); window.location.href='/purchase-orders';">x</button>
</div>
<form hx-post="/purchase-orders" hx-target="#purchase-order-table" hx-swap="afterbegin" hx-on::after-request="if(event.detail.successful) toggleContent('float');">
<div class="row">
<label for="customer" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;">Customer:</label>
<input type="text" class="col-3" name="customer" placeholder="Customer" value="" required autofocus>
Work Order:<label for="workOrder" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;"></label>
<input type="text" class="col-4" name="workOrder" placeholder="Work Order: (12345)" value="">
</div>
<div class="row">
<label for="materials" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;">Materials:</label>
<input type="text" class="col-3" name="materials" placeholder="Materials" value="" required>
Vendor:<label for="vendorBranchID" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;"></label>
<div hx-get="/vendors/branches/select?context=purchaseOrderForm" hx-target="this" hx-swap="outerHTML transition:true swap:0.5s" hx-indicator="next .hx-indicator" hx-trigger="revealed" style="display: inline;">
<img src="/images/spinner.svg" width="30" height="30" class="hx-indicator">
</div>
</div>
<div class="row">
<label for="createdForID" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;">Employee:</label>
<div hx-get="/employees/select?context=purchaseOrderForm" hx-target="this" hx-swap="outerHTML transition:true swap:0.5s" hx-indicator="next .hx-indicator" hx-trigger="revealed" style="display: inline;">
<img src="/images/spinner.svg" width="30" height="30" class="hx-indicator">
</div>
Truck Stock:<label for="truckStock" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;"></label>
<input type="checkbox" class="col-2" name="truckStock" style="margin-top: 20px;">
</div>
<div class="btn-row">
<button class="btn-primary" type="submit">Create</button>
</div>
</form>
</div>

View File

@@ -0,0 +1,11 @@
<tr id="purchase-order-1">
<td>1</td>
<td>12245</td>
<td>Testy McTestface</td>
<td>Test - Mock</td>
<td>foo</td>
<td>Testy Mctestface</td>
<td>
<button class="btn-detail" hx-get="/purchase-orders/1" hx-target="#float" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true"></button>
</td>
</tr>

View File

@@ -0,0 +1,37 @@
<div id="float" class="float" style="display: block;">
<div class="btn-row">
<button class="btn-close" onclick="toggleContent('float'); window.location.href='/purchase-orders';">x</button>
</div>
<p><span class="label" style="margin-right: 15px;">Note:</span><span><i style="font-size: 1em;">Vendor and Employee can not be changed once a purchase order has been created.</i></span></p>
<form hx-post="/purchase-orders" hx-target="#purchase-order-table" hx-swap="afterbegin" hx-on::after-request="if(event.detail.successful) toggleContent('float');">
<div class="row">
<label for="customer" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;">Customer:</label>
<input type="text" class="col-3" name="customer" placeholder="Customer" value="Testy McTestface" required autofocus>
Work Order:<label for="workOrder" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;"></label>
<input type="text" class="col-4" name="workOrder" placeholder="Work Order: (12345)" value="12245">
</div>
<div class="row">
<label for="materials" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;">Materials:</label>
<input type="text" class="col-3" name="materials" placeholder="Materials" value="foo" required>
Vendor:<label for="vendorBranchID" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;"></label>
<input type="text" class="col-4" name="vendorBranchID" value="Test - Mock" disabled>
</div>
<div class="row">
<label for="createdForID" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;">Employee:</label>
<input type="text" class="col-3" value="Testy Mctestface" disabled>
Truck Stock:<label for="truckStock" class="label col-2" style="margin-right: 15px; margin-bottom: 5px;"></label>
<input type="checkbox" class="col-2" name="truckStock" style="margin-top: 20px;" checked>
</div>
<div class="row">
<label class="label col-2">Created:</label>
<h3 class="col-2">2/13/09</h3>
<div class="col-1"></div>
Updated:<label class="label col-2"></label>
<h3 class="col-2">2/13/09</h3>
</div>
<div class="btn-row">
<button class="btn-primary" type="submit">Update</button>
<button class="danger">Delete</button>
</div>
</form>
</div>

View File

@@ -0,0 +1,11 @@
<tr id="purchase-order-1">
<td>1</td>
<td>12245</td>
<td>Testy McTestface</td>
<td>Test - Mock</td>
<td>foo</td>
<td>Testy Mctestface</td>
<td>
<button class="btn-detail" hx-get="/purchase-orders/1" hx-target="#float" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true"></button>
</td>
</tr>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purchase Orders</title>
<meta charset="UTF-8">
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="/js/main.js"></script>
<link rel="stylesheet" href="/css/main.css">
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
</head>
<body>
<header class="header">
<div id="logo">HHE - Purchase Orders</div>
<div class="sidepanel" id="sidepanel">
<a href="javascript:void(0)" class="closebtn" onclick="closeSidepanel()">x</a><a hx-get="/purchase-orders?page=1&amp;limit=50" hx-target="body" hx-push-url="true">Purchase Orders</a><a hx-get="/users" hx-target="body" hx-push-url="true">Users</a><a hx-get="/employees" hx-target="body" hx-push-url="true">Employees</a><a hx-get="/vendors" hx-target="body" hx-push-url="true">Vendors</a>
<div style="border-bottom: 1px solid grey; margin-bottom: 5px;"></div>
Logout<a hx-post="/logout" hx-target="#content" hx-swap="outerHTML" hx-trigger="click"></a>
</div>
<button class="openbtn" onclick="openSidepanel()">
<img src="/images/menu.svg" style="width: 30px;, height: 30px;">
</button>
</header>
<div class="container" style="padding: 20px 20px;">
<h1>Purchase Orders</h1>
<br>
<p class="secondary"><i></i></p>
<br>
</div>
<div class="container" id="purchase-order-content">
<form id="purchase-order-search" hx-post="/purchase-orders/search" hx-target="#purchase-order" hx-swap="outerHTML">
<div class="btn-row">
<button class="btn-secondary" style="position: absolute; top: 80px; right: 20px;" hx-get="/purchase-orders" hx-push-url="true" hx-target="body">x</button>
</div>
<div class="row">
<select name="context" class="col-3" hx-get="/purchase-orders/search" hx-target="#purchase-order-search" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true">
<option value="employee" selected>Employee</option>
<option value="customer">Customer</option>
<option value="vendor">Vendor</option>
</select>
<div hx-get="/employees/select?context=purchaseOrderSearch" hx-target="this" hx-swap="outerHTML transition:true swap:0.5s" hx-indicator="next .hx-indicator" hx-trigger="revealed" style="display: inline;">
<img src="/images/spinner.svg" width="30" height="30" class="hx-indicator">
</div>
</div>
<div class="btn-row">
<button type="submit" class="btn-primary">Search</button>
</div>
</form>
<table id="purchase-order">
<thead>
<tr>
<div class="btn-row"></div>
</tr>
<tr>
<th>PO</th>
<th>Work Order</th>
<th>Customer</th>
<th>Vendor</th>
<th>Materials</th>
<th>Created For</th>
<th></th>
</tr>
</thead>
<tbody id="purchase-order-table"></tbody>
</table>
</div>
</body>
</html>

View File

@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purchase Orders</title>
<meta charset="UTF-8">
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="/js/main.js"></script>
<link rel="stylesheet" href="/css/main.css">
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
</head>
<body>
<header class="header">
<div id="logo">HHE - Purchase Orders</div>
<div class="sidepanel" id="sidepanel">
<a href="javascript:void(0)" class="closebtn" onclick="closeSidepanel()">x</a><a hx-get="/purchase-orders?page=1&amp;limit=50" hx-target="body" hx-push-url="true">Purchase Orders</a><a hx-get="/users" hx-target="body" hx-push-url="true">Users</a><a hx-get="/employees" hx-target="body" hx-push-url="true">Employees</a><a hx-get="/vendors" hx-target="body" hx-push-url="true">Vendors</a>
<div style="border-bottom: 1px solid grey; margin-bottom: 5px;"></div>
Logout<a hx-post="/logout" hx-target="#content" hx-swap="outerHTML" hx-trigger="click"></a>
</div>
<button class="openbtn" onclick="openSidepanel()">
<img src="/images/menu.svg" style="width: 30px;, height: 30px;">
</button>
</header>
<div class="container" style="padding: 20px 20px;">
<h1>Purchase Orders</h1>
<br>
<p class="secondary"><i></i></p>
<br>
</div>
<div class="container" id="purchase-order-content">
<form id="purchase-order-search" hx-post="/purchase-orders/search" hx-target="#purchase-order" hx-swap="outerHTML">
<div class="btn-row">
<button class="btn-secondary" style="position: absolute; top: 80px; right: 20px;" hx-get="/purchase-orders" hx-push-url="true" hx-target="body">x</button>
</div>
<div class="row">
<select name="context" class="col-3" hx-get="/purchase-orders/search" hx-target="#purchase-order-search" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true">
<option value="employee">Employee</option>
<option value="customer" selected>Customer</option>
<option value="vendor">Vendor</option>
</select>
<input type="text" class="col-6" style="margin-left: 60px; margin-top: 18px;" name="customerSearch" placeholder="Search" required>
</div>
<div class="btn-row">
<button type="submit" class="btn-primary">Search</button>
</div>
</form>
<table id="purchase-order">
<thead>
<tr>
<div class="btn-row"></div>
</tr>
<tr>
<th>PO</th>
<th>Work Order</th>
<th>Customer</th>
<th>Vendor</th>
<th>Materials</th>
<th>Created For</th>
<th></th>
</tr>
</thead>
<tbody id="purchase-order-table"></tbody>
</table>
</div>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purchase Orders</title>
<meta charset="UTF-8">
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
<script src="/js/main.js"></script>
<link rel="stylesheet" href="/css/main.css">
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
</head>
<body>
<header class="header">
<div id="logo">HHE - Purchase Orders</div>
<div class="sidepanel" id="sidepanel">
<a href="javascript:void(0)" class="closebtn" onclick="closeSidepanel()">x</a><a hx-get="/purchase-orders?page=1&amp;limit=50" hx-target="body" hx-push-url="true">Purchase Orders</a><a hx-get="/users" hx-target="body" hx-push-url="true">Users</a><a hx-get="/employees" hx-target="body" hx-push-url="true">Employees</a><a hx-get="/vendors" hx-target="body" hx-push-url="true">Vendors</a>
<div style="border-bottom: 1px solid grey; margin-bottom: 5px;"></div>
Logout<a hx-post="/logout" hx-target="#content" hx-swap="outerHTML" hx-trigger="click"></a>
</div>
<button class="openbtn" onclick="openSidepanel()">
<img src="/images/menu.svg" style="width: 30px;, height: 30px;">
</button>
</header>
<div class="container" style="padding: 20px 20px;">
<h1>Purchase Orders</h1>
<br>
<p class="secondary"><i></i></p>
<br>
</div>
<div class="container" id="purchase-order-content">
<form id="purchase-order-search" hx-post="/purchase-orders/search" hx-target="#purchase-order" hx-swap="outerHTML">
<div class="btn-row">
<button class="btn-secondary" style="position: absolute; top: 80px; right: 20px;" hx-get="/purchase-orders" hx-push-url="true" hx-target="body">x</button>
</div>
<div class="row">
<select name="context" class="col-3" hx-get="/purchase-orders/search" hx-target="#purchase-order-search" hx-swap="outerHTML transition:true swap:0.5s" hx-push-url="true">
<option value="employee">Employee</option>
<option value="customer">Customer</option>
<option value="vendor" selected>Vendor</option>
</select>
<div hx-get="/vendors/branches/select?context=purchaseOrderSearch" hx-target="this" hx-swap="outerHTML transition:true swap:0.5s" hx-indicator="next .hx-indicator" hx-trigger="revealed" style="display: inline;">
<img src="/images/spinner.svg" width="30" height="30" class="hx-indicator">
</div>
</div>
<div class="btn-row">
<button type="submit" class="btn-primary">Search</button>
</div>
</form>
<table id="purchase-order">
<thead>
<tr>
<div class="btn-row"></div>
</tr>
<tr>
<th>PO</th>
<th>Work Order</th>
<th>Customer</th>
<th>Vendor</th>
<th>Materials</th>
<th>Created For</th>
<th></th>
</tr>
</thead>
<tbody id="purchase-order-table"></tbody>
</table>
</div>
</body>
</html>