Skip to content

Commit

Permalink
Fix summary and legend tags (#42)
Browse files Browse the repository at this point in the history
* Fix summary and legend tags

* Require as first element

* Fix

* More tests
  • Loading branch information
stephencelis authored Feb 19, 2019
1 parent 5a30da6 commit b0c827a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 34 deletions.
51 changes: 46 additions & 5 deletions Sources/Html/Elements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,34 @@ extension Node {
return .element("del", attributes: attributes, .fragment(content))
}

// TODO: required first child element "summary"
/// The `<details>` element represents a disclosure widget from which the user can obtain additional information or controls.
///
/// - Parameters:
/// - attributes: Attributes.
/// - summary: A summary.
/// - content: Child nodes.
public static func details(attributes: [Attribute<Tag.Details>] = [], _ content: Node...) -> Node {
return .element("details", attributes: attributes, .fragment(content))
public static func details(
attributes: [Attribute<Tag.Details>] = [],
_ summary: ChildOf<Tag.Details>,
_ content: Node...
)
-> Node {

return details(attributes: attributes, summary.rawValue, .fragment(content))
}

/// The `<details>` element represents a disclosure widget from which the user can obtain additional information or controls.
///
/// - Parameters:
/// - attributes: Attributes.
/// - content: Child nodes.
public static func details(
attributes: [Attribute<Tag.Details>] = [],
_ content: Node...
)
-> Node {

return .element("details", attributes: attributes, .fragment(content))
}

/// 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.
Expand Down Expand Up @@ -214,9 +234,30 @@ extension Node {
///
/// - Parameters:
/// - attributes: Attributes.
/// - legend: A legend.
/// - content: Child nodes.
public static func fieldset(attributes: [Attribute<Tag.Fieldset>] = [], _ content: Node...) -> Node {
return .element("fieldset", attributes: attributes, .fragment(content))
public static func fieldset(
attributes: [Attribute<Tag.Fieldset>] = [],
_ legend: ChildOf<Tag.Fieldset>,
_ content: Node...
)
-> Node {

return .fieldset(attributes: attributes, legend.rawValue, .fragment(content))
}

/// The `<fieldset>` element represents a set of form controls optionally grouped under a common name.
///
/// - Parameters:
/// - attributes: Attributes.
/// - content: Child nodes.
public static func fieldset(
attributes: [Attribute<Tag.Fieldset>] = [],
_ content: Node...
)
-> Node {

return .element("fieldset", attributes: attributes, .fragment(content))
}

/// 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.
Expand Down
22 changes: 18 additions & 4 deletions Tests/HtmlSnapshotTestingTests/HtmlSnapshotTestingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,16 @@ final class SnapshotTestingTests: SnapshotTestCase {
.cite(),
.code(),
.del(),
.details(),
.details(
// TODO: `summary` returns ChildOf<FieldSet> but `details` only wants Node. is that correct?
// .summary(),
.summary()
),
.details(
.summary(),
.div()
),
.details(
.div()
),
.dfn(),
.div(),
Expand All @@ -456,9 +463,16 @@ final class SnapshotTestingTests: SnapshotTestCase {
),
.em(),
.embed(),
.fieldset(),
.fieldset(
.legend()
),
.fieldset(
.legend(),
.div()
),
.fieldset(
// TODO: `legend` returns ChildOf<FieldSet> but `fieldset` only wants Node. is that correct?
// .legend(),
.div()
),
.figure(
.figcaption()
Expand Down
14 changes: 7 additions & 7 deletions Tests/HtmlSnapshotTestingTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import XCTest

extension SnapshotTestingTests {
static let __allTests = [
("testComplexHtml", testComplexHtml),
("testSnapshots", testSnapshots),
static let __allTests = [
("testComplexHtml", testComplexHtml),
("testSnapshots", testSnapshots),
]
}

#if !os(macOS)
#if os(Linux)
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(SnapshotTestingTests.__allTests),
]
return [
testCase(SnapshotTestingTests.__allTests),
]
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
</del>
<details>
</details>
<details>
<summary>
</summary>
</details>
<details>
<summary>
</summary>
<div>
</div>
</details>
<details>
<div>
</div>
</details>
<dfn>
</dfn>
<div>
Expand All @@ -52,6 +66,20 @@
<embed>
<fieldset>
</fieldset>
<fieldset>
<legend>
</legend>
</fieldset>
<fieldset>
<legend>
</legend>
<div>
</div>
</fieldset>
<fieldset>
<div>
</div>
</fieldset>
<figure>
<figcaption>
</figcaption>
Expand Down
36 changes: 18 additions & 18 deletions Tests/HtmlTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import XCTest

extension AriaTests {
static let __allTests = [
("testAriaAttributes", testAriaAttributes),
static let __allTests = [
("testAriaAttributes", testAriaAttributes),
]
}

extension AttributesTests {
static let __allTests = [
("testAttributes", testAttributes),
static let __allTests = [
("testAttributes", testAttributes),
]
}

extension ElementsTests {
static let __allTests = [
("testBase64Snapshot", testBase64Snapshot),
static let __allTests = [
("testBase64Snapshot", testBase64Snapshot),
]
}

extension EventsTests {
static let __allTests = [
("testEventsSnapshot", testEventsSnapshot),
static let __allTests = [
("testEventsSnapshot", testEventsSnapshot),
]
}

extension MediaTypeTests {
static let __allTests = [
("testMediaType", testMediaType),
static let __allTests = [
("testMediaType", testMediaType),
]
}

#if !os(macOS)
#if os(Linux)
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(AriaTests.__allTests),
testCase(AttributesTests.__allTests),
testCase(ElementsTests.__allTests),
testCase(EventsTests.__allTests),
testCase(MediaTypeTests.__allTests),
]
return [
testCase(AriaTests.__allTests),
testCase(AttributesTests.__allTests),
testCase(ElementsTests.__allTests),
testCase(EventsTests.__allTests),
testCase(MediaTypeTests.__allTests),
]
}
#endif

0 comments on commit b0c827a

Please sign in to comment.