81 lines
2.3 KiB
Swift
81 lines
2.3 KiB
Swift
import Elementary
|
|
import Testing
|
|
|
|
@testable import WebsiteLibrary
|
|
|
|
@Suite(
|
|
"SiteHeader component",
|
|
.tags(.component)
|
|
)
|
|
struct SiteHeaderTests {
|
|
|
|
// MARK: Functional tests
|
|
|
|
@Test
|
|
func `renders the signed-out actions without a viewer`() {
|
|
let html = SiteHeader().render()
|
|
|
|
#expect(html.contains(#"href="/sign-in""#))
|
|
#expect(html.contains("Open a shop"))
|
|
#expect(!html.contains(#"href="/account""#))
|
|
#expect(!html.contains(#"href="/messages""#))
|
|
}
|
|
|
|
@Test
|
|
func `renders the signed-in actions for a viewer`() {
|
|
let html = SiteHeader(viewer: .init(
|
|
displayName: "Mara Visser",
|
|
newWantMatches: 2,
|
|
unreadMessages: 3
|
|
)).render()
|
|
|
|
#expect(html.contains(#"aria-label="Want list, 2 new matches""#))
|
|
#expect(html.contains(#"aria-label="Messages, 3 unread""#))
|
|
#expect(html.contains(#"href="/sell""#))
|
|
#expect(html.contains(">MV<"))
|
|
#expect(html.contains(">Mara<"))
|
|
#expect(html.contains(#"action="/sign-out" method="post""#))
|
|
#expect(!html.contains(#"href="/sign-in""#))
|
|
}
|
|
|
|
@Test
|
|
func `omits a badge that counts nothing`() {
|
|
let html = SiteHeader(viewer: .init(displayName: "Mara")).render()
|
|
|
|
#expect(html.contains(#"aria-label="Messages""#))
|
|
#expect(!html.contains("site-header__badge"))
|
|
}
|
|
|
|
@Test
|
|
func `links every format and marks none current by default`() {
|
|
let html = SiteHeader().render()
|
|
|
|
for format in Format.allCases {
|
|
#expect(html.contains(#"href="\#(format.path)""#))
|
|
}
|
|
|
|
#expect(!html.contains("aria-current"))
|
|
}
|
|
|
|
@Test(arguments: Format.allCases)
|
|
func `marks the active format alone as current`(
|
|
_ format: Format
|
|
) {
|
|
let html = SiteHeader(active: format).render()
|
|
|
|
#expect(html.components(separatedBy: #"aria-current="page""#).count - 1 == 1)
|
|
#expect(html.contains(#"href="\#(format.path)" aria-current="page""#))
|
|
}
|
|
|
|
@Test
|
|
func `searches through a plain GET form`() {
|
|
let html = SiteHeader().render()
|
|
|
|
#expect(html.contains(#"action="/search""#))
|
|
#expect(html.contains(#"method="get""#))
|
|
#expect(html.contains(#"name="q""#))
|
|
#expect(html.contains(#"for="site-search-query""#))
|
|
}
|
|
|
|
}
|