Added the ImageWidth enumeration to the Website library target.

This commit is contained in:
2026-08-25 17:23:29 +02:00
parent c09ac657ab
commit 3358946e3d
4 changed files with 135 additions and 0 deletions
@@ -0,0 +1,24 @@
import Testing
@testable import WebsiteLibrary
@Suite(
"ImageWidth enumeration",
.tags(.enumeration)
)
struct ImageWidthTests {
// MARK: Computed tests
@Test(arguments: zip(
ImageWidth.allCases,
[480, 800, 1200]
))
func `width`(
for imageWidth: ImageWidth,
expects width: Int
) {
#expect(imageWidth.width == width)
}
}
@@ -33,6 +33,49 @@ struct StaticFileTests {
#expect(font.urlPath(for: .woff2) == "/font/a-font-400.woff2")
}
/// Imagery sits in a folder per page, so a declared folder replaces the extension's own for every extension the file has.
@Test
func `declared folder paths`() {
let portrait = File("portrait", in: "img/about", as: .jpg, .webp)
#expect(portrait.relativePath(for: .jpg) == "img/about/portrait.jpg")
#expect(portrait.relativePath(for: .webp) == "img/about/portrait.webp")
}
// MARK: Methods tests
@Test(arguments: zip(
[AssetExtension.jpg, .webp],
["jpg", "webp"]
))
func `srcset offers every rendition narrowest first`(
for fileExtension: AssetExtension,
expects suffix: String
) {
let srcSet = File.srcSet(for: fileExtension) { width in
File(
width == .large ? "portrait" : "portrait-\(width.width)",
in: "img/about",
as: .jpg, .webp
)
}
#expect(srcSet == [
"/img/about/portrait-480.\(suffix) 480w",
"/img/about/portrait-800.\(suffix) 800w",
"/img/about/portrait.\(suffix) 1200w"
].joined(separator: ", "))
}
@Test
func `srcset versions every rendition when given a version`() {
let srcSet = File.srcSet(for: .jpg, version: "0123456789abcdef") { _ in
File("portrait", in: "img/about", as: .jpg)
}
#expect(srcSet.components(separatedBy: "?v=0123456789abcdef").count - 1 == ImageWidth.allCases.count)
}
// MARK: Constants tests
@Test