Skip to content

Commit

Permalink
Rename ScenarioKind and ScenarioName (#70)
Browse files Browse the repository at this point in the history
* Rename ScenarioKind to ScenarioCategory, ScenarioName to ScenarioTitle

* Format
  • Loading branch information
ra1028 committed May 20, 2024
1 parent 138b644 commit 782364d
Show file tree
Hide file tree
Showing 33 changed files with 168 additions and 168 deletions.
40 changes: 20 additions & 20 deletions Playbook.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Sources/Playbook/Playbook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ open class Playbook {
Array(storage)
}

private var storage = OrderedStorage<ScenarioKind, ScenarioStore>()
private var storage = OrderedStorage<ScenarioCategory, ScenarioStore>()

/// Initialize a new `Playbook`.
public init() {}

/// Returns a store identified by specified kind.
/// Returns a store identified by specified category.
///
/// If there is no store yet, add and return it.
///
/// - Parameters:
/// - kind: A unique identifier that stores a set of scenarios.
/// - category: A unique identifier that stores a set of scenarios.
///
/// - Returns: A store identified by specified kind.
public func scenarios(of kind: ScenarioKind) -> ScenarioStore {
storage.element(for: kind, default: ScenarioStore(kind: kind))
/// - Returns: A store identified by specified category.
public func scenarios(of category: ScenarioCategory) -> ScenarioStore {
storage.element(for: category, default: ScenarioStore(category: category))
}

/// Adds a set scenarios defined in specified provider.
Expand All @@ -57,13 +57,13 @@ open class Playbook {
/// Adds a set of scenarios passed by function builder.
///
/// - Parameters:
/// - kind: A unique identifier that stores a set of scenarios.
/// - category: A unique identifier that stores a set of scenarios.
/// - scenarios: A function builder that create a set of scenarios.
///
/// - Returns: A instance of `self`.
@discardableResult
public func addScenarios<S: ScenariosBuildable>(of kind: ScenarioKind, @ScenariosBuilder _ scenarios: () -> S) -> Self {
let store = self.scenarios(of: kind)
public func addScenarios<S: ScenariosBuildable>(of category: ScenarioCategory, @ScenariosBuilder _ scenarios: () -> S) -> Self {
let store = self.scenarios(of: category)

for scenario in scenarios().buildScenarios() {
store.add(scenario)
Expand Down
28 changes: 14 additions & 14 deletions Sources/Playbook/Scenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import UIKit

/// Represents part of the component state.
public struct Scenario {
/// A unique name of scenario that describes component and its state.
public var name: ScenarioName
/// A unique title of scenario that describes component and its state.
public var title: ScenarioTitle

/// Represents how the component should be laid out.
public var layout: ScenarioLayout
Expand All @@ -20,19 +20,19 @@ public struct Scenario {
/// Creates a new scenario.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - title: A unique title of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content with passed context.
public init(
_ name: ScenarioName,
_ title: ScenarioTitle,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping (ScenarioContext) -> UIViewController
) {
self.name = name
self.title = title
self.layout = layout
self.file = file
self.line = line
Expand All @@ -42,20 +42,20 @@ public struct Scenario {
/// Creates a new scenario.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - title: A unique title of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content with passed context.
public init(
_ name: ScenarioName,
_ title: ScenarioTitle,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping (ScenarioContext) -> UIView
) {
self.init(
name,
title,
layout: layout,
file: file,
line: line,
Expand All @@ -68,20 +68,20 @@ public struct Scenario {
/// Creates a new scenario.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - title: A unique title of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content.
public init(
_ name: ScenarioName,
_ title: ScenarioTitle,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping () -> UIViewController
) {
self.init(
name,
title,
layout: layout,
file: file,
line: line,
Expand All @@ -92,20 +92,20 @@ public struct Scenario {
/// Creates a new scenario.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - title: A unique title of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content.
public init(
_ name: ScenarioName,
_ title: ScenarioTitle,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
content: @escaping () -> UIView
) {
self.init(
name,
title,
layout: layout,
file: file,
line: line,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/// Represents a unique identifier of the set of scenarios.
public struct ScenarioKind: Hashable, RawRepresentable, ExpressibleByStringLiteral, CustomStringConvertible, ExpressibleByStringInterpolation {
public struct ScenarioCategory: Hashable, RawRepresentable, ExpressibleByStringLiteral, CustomStringConvertible, ExpressibleByStringInterpolation {
/// The raw string value.
public var rawValue: String

/// A textual representation of this instance.
public var description: String { rawValue }

/// Creates a new kind with given raw string value.
/// Creates a new category with given raw string value.
///
/// - Parameters:
/// - rawValue: The raw string value.
public init(rawValue: String) {
self.rawValue = rawValue
}

/// Creates a new kind with given raw string value.
/// Creates a new category with given raw string value.
///
/// - Parameters:
/// - value: The raw string value.
Expand Down
16 changes: 8 additions & 8 deletions Sources/Playbook/ScenarioStore.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/// The class for managing a set of scenarios identified by the arbitrary kind.
/// The class for managing a set of scenarios identified by the arbitrary category.
public final class ScenarioStore {
/// A unique identifier of the secenarios managed by this instance.
public let kind: ScenarioKind
public let category: ScenarioCategory

private var storage = OrderedStorage<ScenarioName, Scenario>()
private var storage = OrderedStorage<ScenarioTitle, Scenario>()

/// The set of scenarios managed by this store.
public var scenarios: [Scenario] {
Array(storage)
}

/// Initialize a new store with given kind.
/// Initialize a new store with given category.
///
/// - Parameters:
/// - kind: A unique identifier of the secenarios managed by this instance.
public init(kind: ScenarioKind) {
self.kind = kind
/// - category: A unique identifier of the secenarios managed by this instance.
public init(category: ScenarioCategory) {
self.category = category
}

/// Adds a scenario to this store instance.
Expand All @@ -26,7 +26,7 @@ public final class ScenarioStore {
/// - Returns: A instance of `self`.
@discardableResult
public func add(_ scenario: Scenario) -> Self {
storage.append(scenario, for: scenario.name)
storage.append(scenario, for: scenario.title)
return self
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/// Represents a unique name of the scenario.
public struct ScenarioName: Hashable, RawRepresentable, ExpressibleByStringLiteral, CustomStringConvertible, ExpressibleByStringInterpolation {
/// Represents a unique title of the scenario.
public struct ScenarioTitle: Hashable, RawRepresentable, ExpressibleByStringLiteral, CustomStringConvertible, ExpressibleByStringInterpolation {
/// The raw string value.
public var rawValue: String

/// A textual representation of this instance.
public var description: String { rawValue }

/// Creates a new name with given raw string value.
/// Creates a new title with given raw string value.
///
/// - Parameters:
/// - rawValue: The raw string value.
public init(rawValue: String) {
self.rawValue = rawValue
}

/// Creates a new name with given raw string value.
/// Creates a new title with given raw string value.
///
/// - Parameters:
/// - rawValue: The raw string value.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Playbook/ScenarioViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private extension ScenarioViewController {
return contentViewController = nil
}

if let previous = previous, scenario.name == previous.name {
if let previous = previous, scenario.title == previous.title {
return
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Playbook/SnapshotSupport/SnapshotSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ private extension SnapshotSupport {

window.prepareForSnapshot {
if contentView.bounds.size.width <= 0 {
fatalError("The view was laid out with zero width in scenario - \(scenario.name)", file: scenario.file, line: scenario.line)
fatalError("The view was laid out with zero width in scenario - \(scenario.title)", file: scenario.file, line: scenario.line)
}

if contentView.bounds.size.height <= 0 {
fatalError("The view was laid out with zero height in scenario - \(scenario.name)", file: scenario.file, line: scenario.line)
fatalError("The view was laid out with zero height in scenario - \(scenario.title)", file: scenario.file, line: scenario.line)
}

let format = UIGraphicsImageRendererFormat(for: device.traitCollection)
Expand Down
12 changes: 6 additions & 6 deletions Sources/Playbook/SwiftUISupport/ScenarioSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ public extension Scenario {
/// Creates a new scenario with SwiftUI view.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - title: A unique title of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content with passed context.
init<Content: View>(
_ name: ScenarioName,
_ title: ScenarioTitle,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
@ViewBuilder content: @escaping (ScenarioContext) -> Content
) {
self.init(name, layout: layout, file: file, line: line) { context in
self.init(title, layout: layout, file: file, line: line) { context in
let content = content(context).transaction { transaction in
if context.isSnapshot {
transaction.disablesAnimations = true
Expand All @@ -32,20 +32,20 @@ public extension Scenario {
/// Creates a new scenario with SwiftUI view.
///
/// - Parameters:
/// - name: A unique name of this scenario.
/// - title: A unique title of this scenario.
/// - layout: Represents how the component should be laid out.
/// - file: A file path where defined this scenario.
/// - line: A line number where defined this scenario in file.
/// - content: A closure that make a new content.
init<Content: View>(
_ name: ScenarioName,
_ title: ScenarioTitle,
layout: ScenarioLayout,
file: StaticString = #file,
line: UInt = #line,
@ViewBuilder content: @escaping () -> Content
) {
self.init(
name,
title,
layout: layout,
file: file,
line: line,
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlaybookSnapshot/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public struct Snapshot: TestTool {
let directoryURL =
directoryURL
.appendingPathComponent(device.name, isDirectory: true)
.appendingPathComponent(normalize(store.kind.rawValue), isDirectory: true)
.appendingPathComponent(normalize(store.category.rawValue), isDirectory: true)

try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)

func attemptToWrite(data: Data, scenario: Scenario) {
let fileURL =
directoryURL
.appendingPathComponent(normalize(scenario.name.rawValue))
.appendingPathComponent(normalize(scenario.title.rawValue))
.appendingPathExtension(format.fileExtension)

do {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PlaybookUI/Internal/Entities/SearchResult.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
internal struct SearchResult {
let count: Int
let total: Int
let kinds: [SearchedKindData]
let categories: [SearchedCategoryData]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Playbook

internal struct SearchedKindData {
let kind: ScenarioKind
internal struct SearchedCategoryData {
let category: ScenarioCategory
let highlightRange: Range<String.Index>?
let scenarios: [SearchedData]
}
2 changes: 1 addition & 1 deletion Sources/PlaybookUI/Internal/Entities/SearchedData.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Playbook

internal struct SearchedData {
let kind: ScenarioKind
let category: ScenarioCategory
let scenario: Scenario
let highlightRange: Range<String.Index>?
}
8 changes: 4 additions & 4 deletions Sources/PlaybookUI/Internal/Entities/SelectData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Playbook

internal struct SelectData: Identifiable {
struct ID: Hashable {
let kind: ScenarioKind
let name: ScenarioName
let category: ScenarioCategory
let title: ScenarioTitle
}

var id: ID {
ID(kind: kind, name: scenario.name)
ID(category: category, title: scenario.title)
}

let kind: ScenarioKind
let category: ScenarioCategory
let scenario: Scenario
}
Loading

0 comments on commit 782364d

Please sign in to comment.