import Elementary
import NIOCore
import Persistence
import Testing
@testable import WebsiteLibrary
@Suite(
"Selling pages",
.tags(.page)
)
struct SellingPagesTests {
// MARK: GradingGuidePage tests
@Test
func `grading guide prints the whole scale and defines every defect`() {
let html = GradingGuidePage().render()
for step in Grading.scale {
#expect(html.contains("\(step.grade.oneDecimal)\(step.code)"))
}
for defect in Grading.Defect.allCases {
#expect(html.contains(defect.label))
#expect(html.contains(defect.definition))
}
#expect(html.contains("Not at this grade"))
#expect(html.contains("/css/guide.css"))
#expect(!html.contains("noindex"))
#expect(!html.contains("style="))
}
// MARK: NewListingPage tests
@Test
func `new-listing form posts as multipart and offers the guide's vocabulary`() {
let html = NewListingPage(shop: .stub()).render()
#expect(html.contains(#"action="/sell/new" method="post" enctype="multipart/form-data""#))
#expect(html.contains(#"type="file" name="photos" accept="image/jpeg,image/png,image/webp" multiple"#))
#expect(html.contains(#"name="format" value="single-issues" checked"#))
#expect(html.contains(#"name="grading" value="slabbed" checked"#))
#expect(html.contains(#""#))
#expect(html.contains(#"name="defects" value="crease""#))
#expect(html.contains(#"data-scope="collected""#))
#expect(html.contains(#"href="/grading-guide""#))
#expect(html.contains("Ships from Amsterdam, NL"))
#expect(!html.contains(#"role="alert""#))
#expect(!html.contains("style="))
}
@Test
func `new-listing form gives back what was typed, with each problem tied to its field`() {
let html = NewListingPage(
shop: .stub(),
form: ListingFormTests.form(["grading": ["raw"], "grade": ["9.4"], "defects": ["crease"], "notes": ["Light "]]),
problems: [.defects: "A colour-breaking crease caps a raw book at 7.0.", .price: "Enter the asking price in whole euros."]
).render()
#expect(html.contains("2 things to fix before publishing."))
#expect(html.contains("Photos have to be picked again"))
#expect(html.contains(#"name="series" value="Nightward""#))
#expect(html.contains(#"