Implemented phase 1 for the POC prototype in the Website service.

This commit is contained in:
javier committed 2026-09-21 11:16:52 +02:00
1 parent 6d7ab4bcba
commit ea89ea892a
37 files changed
+4173 -43

No files matched your search

@@ -0,0 +1,99 @@
import Elementary
import Persistence
import Testing
@testable import WebsiteLibrary
@Suite(
"Catalogue components",
.tags(.component)
)
struct CatalogueComponentsTests {
// MARK: Cover tests
@Test
func `letters a cover line by line on its tone`() {
let html = Cover(Listing.stub().cover, modifier: "cover--hero").render()
#expect(html.contains(#"class="cover cover--navy cover--hero""#))
#expect(html.contains("<span>NIGHT</span><span>WARD</span>"))
#expect(html.contains(#"class="cover__number">1<"#))
#expect(html.contains(#"aria-hidden="true""#))
}
@Test
func `sets a volume marker smaller than an issue number`() {
let html = Cover(.init(tone: "plum", title: "HOLLOW\nCOMET", imprint: "SŌKAI BOOKS", number: "VOL 4")).render()
#expect(html.contains(#"class="cover__number cover__number--text">VOL 4<"#))
}
// MARK: Chip tests
@Test
func `checks a certified chip`() {
#expect(Chip("CGC 9.8", tone: .good, isCertified: true).render().hasPrefix(#"<span class="chip chip--good"><svg"#))
#expect(Chip("Raw · NM").render() == #"<span class="chip">Raw · NM</span>"#)
}
// MARK: ListingCard tests
@Test
func `links a card to its listing and gates saving behind the sign-in`() {
let html = ListingCard(.stub()).render()
#expect(html.contains(#"href="/listing/nightward-1">Nightward #1</a>"#))
#expect(html.contains(#"href="/sign-in?return=/listing/nightward-1""#))
#expect(html.contains("€240"))
#expect(html.contains("CGC 9.8"))
}
@Test
func `names the shop by the card's context`() {
#expect(ListingCard(.stub(), context: .browse).render().contains(">Kestrel Row Comics</a>"))
#expect(ListingCard(.stub(), context: .search).render().contains(">Kestrel Row Comics · NL · ship €6</a>"))
#expect(!ListingCard(.stub(), context: .shop).render().contains("/shop/kestrel-row-comics"))
}
// MARK: Pagination tests
@Test
func `renders no page links for a single page`() {
#expect(Pagination(current: 1, total: 1) { "/?page=\($0)" }.render().isEmpty)
}
@Test
func `marks the current page and offers the next until the last`() {
let middle = Pagination(current: 2, total: 3) { "/?page=\($0)" }.render()
let last = Pagination(current: 3, total: 3) { "/?page=\($0)" }.render()
#expect(middle.contains(#"href="/?page=2" aria-current="page""#))
#expect(middle.contains(#"href="/?page=3">Next</a>"#))
#expect(!last.contains("Next"))
}
@Test(arguments: zip(
[1, 2, 3, 9, -1],
[[1, 2], [3, 4], [5], [5], [1, 2]]
))
func `slices a page out of a list, clamping the page`(
page: Int,
expects items: [Int]
) {
let slice = Pagination.slice([1, 2, 3, 4, 5], page: page, size: 2)
#expect(slice.items == items)
#expect(slice.total == 3)
}
@Test
func `counts one page for an empty list`() {
let slice = Pagination.slice([Int](), page: 1, size: 12)
#expect(slice.items.isEmpty)
#expect(slice.current == 1)
#expect(slice.total == 1)
}
}