Skip to content

Commit 3a0d63e

Browse files
authored
Fix summary and legend tags (#42)
* Fix summary and legend tags * Require as first element * Fix * More tests
1 parent 59272c4 commit 3a0d63e

File tree

5 files changed

+117
-34
lines changed

5 files changed

+117
-34
lines changed

Sources/Html/Elements.swift

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,34 @@ extension Node {
157157
return .element("del", attributes: attributes, .fragment(content))
158158
}
159159

160-
// TODO: required first child element "summary"
161160
/// The `<details>` element represents a disclosure widget from which the user can obtain additional information or controls.
162161
///
163162
/// - Parameters:
164163
/// - attributes: Attributes.
164+
/// - summary: A summary.
165165
/// - content: Child nodes.
166-
public static func details(attributes: [Attribute<Tag.Details>] = [], _ content: Node...) -> Node {
167-
return .element("details", attributes: attributes, .fragment(content))
166+
public static func details(
167+
attributes: [Attribute<Tag.Details>] = [],
168+
_ summary: ChildOf<Tag.Details>,
169+
_ content: Node...
170+
)
171+
-> Node {
172+
173+
return details(attributes: attributes, summary.rawValue, .fragment(content))
174+
}
175+
176+
/// The `<details>` element represents a disclosure widget from which the user can obtain additional information or controls.
177+
///
178+
/// - Parameters:
179+
/// - attributes: Attributes.
180+
/// - content: Child nodes.
181+
public static func details(
182+
attributes: [Attribute<Tag.Details>] = [],
183+
_ content: Node...
184+
)
185+
-> Node {
186+
187+
return .element("details", attributes: attributes, .fragment(content))
168188
}
169189

170190
/// The `<dfn>` element represents the defining instance of a term. The term-description group, `<p>`, `<li>` or `<section>` element that is the nearest ancestor of the `<dfn>` element must also contain the definition(s) for the term given by the `<dfn>` element.
@@ -214,9 +234,30 @@ extension Node {
214234
///
215235
/// - Parameters:
216236
/// - attributes: Attributes.
237+
/// - legend: A legend.
217238
/// - content: Child nodes.
218-
public static func fieldset(attributes: [Attribute<Tag.Fieldset>] = [], _ content: Node...) -> Node {
219-
return .element("fieldset", attributes: attributes, .fragment(content))
239+
public static func fieldset(
240+
attributes: [Attribute<Tag.Fieldset>] = [],
241+
_ legend: ChildOf<Tag.Fieldset>,
242+
_ content: Node...
243+
)
244+
-> Node {
245+
246+
return .fieldset(attributes: attributes, legend.rawValue, .fragment(content))
247+
}
248+
249+
/// The `<fieldset>` element represents a set of form controls optionally grouped under a common name.
250+
///
251+
/// - Parameters:
252+
/// - attributes: Attributes.
253+
/// - content: Child nodes.
254+
public static func fieldset(
255+
attributes: [Attribute<Tag.Fieldset>] = [],
256+
_ content: Node...
257+
)
258+
-> Node {
259+
260+
return .element("fieldset", attributes: attributes, .fragment(content))
220261
}
221262

222263
/// The `<figure>` element represents some flow content, optionally with a caption, that is self-contained (like a complete sentence) and is typically referenced as a single unit from the main flow of the document.

Tests/HtmlSnapshotTestingTests/HtmlSnapshotTestingTests.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,16 @@ final class SnapshotTestingTests: SnapshotTestCase {
444444
.cite(),
445445
.code(),
446446
.del(),
447+
.details(),
447448
.details(
448-
// TODO: `summary` returns ChildOf<FieldSet> but `details` only wants Node. is that correct?
449-
// .summary(),
449+
.summary()
450+
),
451+
.details(
452+
.summary(),
453+
.div()
454+
),
455+
.details(
456+
.div()
450457
),
451458
.dfn(),
452459
.div(),
@@ -456,9 +463,16 @@ final class SnapshotTestingTests: SnapshotTestCase {
456463
),
457464
.em(),
458465
.embed(),
466+
.fieldset(),
467+
.fieldset(
468+
.legend()
469+
),
470+
.fieldset(
471+
.legend(),
472+
.div()
473+
),
459474
.fieldset(
460-
// TODO: `legend` returns ChildOf<FieldSet> but `fieldset` only wants Node. is that correct?
461-
// .legend(),
475+
.div()
462476
),
463477
.figure(
464478
.figcaption()
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import XCTest
22

33
extension SnapshotTestingTests {
4-
static let __allTests = [
5-
("testComplexHtml", testComplexHtml),
6-
("testSnapshots", testSnapshots),
4+
static let __allTests = [
5+
("testComplexHtml", testComplexHtml),
6+
("testSnapshots", testSnapshots),
77
]
88
}
99

10-
#if !os(macOS)
10+
#if os(Linux)
1111
public func __allTests() -> [XCTestCaseEntry] {
12-
return [
13-
testCase(SnapshotTestingTests.__allTests),
14-
]
12+
return [
13+
testCase(SnapshotTestingTests.__allTests),
14+
]
1515
}
1616
#endif

Tests/HtmlSnapshotTestingTests/__Snapshots__/HtmlSnapshotTestingTests/testSnapshots.1.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@
3737
</del>
3838
<details>
3939
</details>
40+
<details>
41+
<summary>
42+
</summary>
43+
</details>
44+
<details>
45+
<summary>
46+
</summary>
47+
<div>
48+
</div>
49+
</details>
50+
<details>
51+
<div>
52+
</div>
53+
</details>
4054
<dfn>
4155
</dfn>
4256
<div>
@@ -52,6 +66,20 @@
5266
<embed>
5367
<fieldset>
5468
</fieldset>
69+
<fieldset>
70+
<legend>
71+
</legend>
72+
</fieldset>
73+
<fieldset>
74+
<legend>
75+
</legend>
76+
<div>
77+
</div>
78+
</fieldset>
79+
<fieldset>
80+
<div>
81+
</div>
82+
</fieldset>
5583
<figure>
5684
<figcaption>
5785
</figcaption>
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import XCTest
22

33
extension AriaTests {
4-
static let __allTests = [
5-
("testAriaAttributes", testAriaAttributes),
4+
static let __allTests = [
5+
("testAriaAttributes", testAriaAttributes),
66
]
77
}
88

99
extension AttributesTests {
10-
static let __allTests = [
11-
("testAttributes", testAttributes),
10+
static let __allTests = [
11+
("testAttributes", testAttributes),
1212
]
1313
}
1414

1515
extension ElementsTests {
16-
static let __allTests = [
17-
("testBase64Snapshot", testBase64Snapshot),
16+
static let __allTests = [
17+
("testBase64Snapshot", testBase64Snapshot),
1818
]
1919
}
2020

2121
extension EventsTests {
22-
static let __allTests = [
23-
("testEventsSnapshot", testEventsSnapshot),
22+
static let __allTests = [
23+
("testEventsSnapshot", testEventsSnapshot),
2424
]
2525
}
2626

2727
extension MediaTypeTests {
28-
static let __allTests = [
29-
("testMediaType", testMediaType),
28+
static let __allTests = [
29+
("testMediaType", testMediaType),
3030
]
3131
}
3232

33-
#if !os(macOS)
33+
#if os(Linux)
3434
public func __allTests() -> [XCTestCaseEntry] {
35-
return [
36-
testCase(AriaTests.__allTests),
37-
testCase(AttributesTests.__allTests),
38-
testCase(ElementsTests.__allTests),
39-
testCase(EventsTests.__allTests),
40-
testCase(MediaTypeTests.__allTests),
41-
]
35+
return [
36+
testCase(AriaTests.__allTests),
37+
testCase(AttributesTests.__allTests),
38+
testCase(ElementsTests.__allTests),
39+
testCase(EventsTests.__allTests),
40+
testCase(MediaTypeTests.__allTests),
41+
]
4242
}
4343
#endif

0 commit comments

Comments
 (0)