From 94f0c660ffe7a9856259f03e60f982b16d8d0c25 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Fri, 24 Jan 2025 08:16:51 -0500 Subject: [PATCH] feat: Adds purchase order view tests. --- .../ViewControllerTests.swift | 70 +++++++++++++++---- .../purchaseOrderViews.1.html | 68 ++++++++++++++++++ .../purchaseOrderViews.2.html | 32 +++++++++ .../purchaseOrderViews.3.html | 11 +++ .../purchaseOrderViews.4.html | 37 ++++++++++ .../purchaseOrderViews.5.html | 11 +++ .../purchaseOrderViews.6.html | 67 ++++++++++++++++++ .../purchaseOrderViews.7.html | 65 +++++++++++++++++ .../purchaseOrderViews.8.html | 67 ++++++++++++++++++ 9 files changed, 414 insertions(+), 14 deletions(-) create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.1.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.2.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.3.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.4.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.5.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.6.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.7.html create mode 100644 Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.8.html diff --git a/Tests/ViewControllerTests/ViewControllerTests.swift b/Tests/ViewControllerTests/ViewControllerTests.swift index f6b85a6..600e1ee 100644 --- a/Tests/ViewControllerTests/ViewControllerTests.swift +++ b/Tests/ViewControllerTests/ViewControllerTests.swift @@ -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)) + } +} diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.1.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.1.html new file mode 100644 index 0000000..aedb260 --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.1.html @@ -0,0 +1,68 @@ + + + + Purchase Orders + + + + + + + +
+ + + +
+
+

Purchase Orders

+
+

+
+
+
+
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
POWork OrderCustomerVendorMaterialsCreated For + +
112245Testy McTestfaceTest - MockfooTesty Mctestface + +
+
+ + \ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.2.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.2.html new file mode 100644 index 0000000..f65a86d --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.2.html @@ -0,0 +1,32 @@ +
+
+ +
+
+
+ + + Work Order: + +
+
+ + + Vendor: +
+ +
+
+
+ +
+ +
+ Truck Stock: + +
+
+ +
+
+
\ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.3.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.3.html new file mode 100644 index 0000000..a91976e --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.3.html @@ -0,0 +1,11 @@ + + 1 + 12245 + Testy McTestface + Test - Mock + foo + Testy Mctestface + + + + \ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.4.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.4.html new file mode 100644 index 0000000..bb7e881 --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.4.html @@ -0,0 +1,37 @@ +
+
+ +
+

Note:Vendor and Employee can not be changed once a purchase order has been created.

+
+
+ + + Work Order: + +
+
+ + + Vendor: + +
+
+ + + Truck Stock: + +
+
+ +

2/13/09

+
+ Updated: +

2/13/09

+
+
+ + +
+
+
\ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.5.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.5.html new file mode 100644 index 0000000..a91976e --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.5.html @@ -0,0 +1,11 @@ + + 1 + 12245 + Testy McTestface + Test - Mock + foo + Testy Mctestface + + + + \ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.6.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.6.html new file mode 100644 index 0000000..c987e63 --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.6.html @@ -0,0 +1,67 @@ + + + + Purchase Orders + + + + + + + +
+ + + +
+
+

Purchase Orders

+
+

+
+
+
+ + + + +
+ + + + + + + + + + + + +
POWork OrderCustomerVendorMaterialsCreated For
+
+ + \ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.7.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.7.html new file mode 100644 index 0000000..77bd1bf --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.7.html @@ -0,0 +1,65 @@ + + + + Purchase Orders + + + + + + + +
+ + + +
+
+

Purchase Orders

+
+

+
+
+
+ + + + +
+ + + + + + + + + + + + +
POWork OrderCustomerVendorMaterialsCreated For
+
+ + \ No newline at end of file diff --git a/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.8.html b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.8.html new file mode 100644 index 0000000..8c4160c --- /dev/null +++ b/Tests/ViewControllerTests/__Snapshots__/ViewControllerTests/purchaseOrderViews.8.html @@ -0,0 +1,67 @@ + + + + Purchase Orders + + + + + + + +
+ + + +
+
+

Purchase Orders

+
+

+
+
+
+ + + + +
+ + + + + + + + + + + + +
POWork OrderCustomerVendorMaterialsCreated For
+
+ + \ No newline at end of file