Skip to content

Commit

Permalink
refactor: use of multiple type for space semantic tokens (#279)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Nov 20, 2024
1 parent 282f96d commit 93dbd3f
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import OUDSTokensSemantic
// swiftlint:disable identifier_name
// swiftlint:disable file_length

/// Defines wrapper objects for `MultipleColorTokenss`.
/// Defines wrapper objects for `ColorSemanticToken`.
/// These values can be overriden inside `OUDSTheme` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
/// Some tokens do not have values assigned in the design system, and must be overriden.
/// Some tokens must be overiden in `OrangeTheme` side because they rely on Orange brand colors.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import Foundation
import OUDSTokensRaw
import OUDSTokensSemantic

// [File not generated by the tokenator]
// WARNING: Not synchronized with the Figjam / Figma by developers team
// Create an issue for update https://github.com/Orange-OpenSource/ouds-ios/issues/new?template=token_update.yml

/// Defines wrapper objects for space semantic tokens (i.e. in the end `DimensionRawToken`).
/// These values can be overriden inside `OUDSTheme` subclasses (in extensions or not, in the same module or not) thanks to the `@objc open` combination.
extension OUDSTheme: SpaceMultipleSemanticTokens {

// MARK: Semantic token - Spacing - Layout fluid

@objc open var spaceScaledNone: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledNoneMobile, regular: spaceScaledNoneTablet) }
@objc open var spaceScaledSmash: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledSmashMobile, regular: spaceScaledSmashTablet) }
@objc open var spaceScaledShortest: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledShortestMobile, regular: spaceScaledShortestTablet) }
@objc open var spaceScaledShorter: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledShorterMobile, regular: spaceScaledShorterTablet) }
@objc open var spaceScaledShort: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledShortMobile, regular: spaceScaledShortTablet) }
@objc open var spaceScaledMedium: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledMediumMobile, regular: spaceScaledMediumTablet) }
@objc open var spaceScaledTall: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledTallMobile, regular: spaceScaledTallTablet) }
@objc open var spaceScaledTaller: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledTallerMobile, regular: spaceScaledTallerTablet) }
@objc open var spaceScaledTallest: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledTallestMobile, regular: spaceScaledTallerTablet) }
@objc open var spaceScaledSpacious: MultipleSpaceTokens { MultipleSpaceTokens(compact: spaceScaledSpaciousMobile, regular: spaceScaledSpaciousTablet) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ extension OUDSTheme: SpaceSemanticTokens {

// MARK: Semantic token - Spacing - Layout fluid

@objc open var spaceScaledNone: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension0, regular: DimensionRawTokens.dimension0) }
@objc open var spaceScaledSmash: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension25, regular: DimensionRawTokens.dimension50) }
@objc open var spaceScaledShortest: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension50, regular: DimensionRawTokens.dimension100) }
@objc open var spaceScaledShorter: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension100, regular: DimensionRawTokens.dimension150) }
@objc open var spaceScaledShort: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension150, regular: DimensionRawTokens.dimension200) }
@objc open var spaceScaledMedium: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension200, regular: DimensionRawTokens.dimension300) }
@objc open var spaceScaledTall: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension300, regular: DimensionRawTokens.dimension400) }
@objc open var spaceScaledTaller: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension400, regular: DimensionRawTokens.dimension500) }
@objc open var spaceScaledTallest: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension500, regular: DimensionRawTokens.dimension600) }
@objc open var spaceScaledSpacious: MultipleSpaceTokens { MultipleSpaceTokens(compact: DimensionRawTokens.dimension600, regular: DimensionRawTokens.dimension700) }
@objc open var spaceScaledNoneMobile: SpaceSemanticToken { DimensionRawTokens.dimension0 }
@objc open var spaceScaledNoneTablet: SpaceSemanticToken { DimensionRawTokens.dimension0 }
@objc open var spaceScaledSmashMobile: SpaceSemanticToken { DimensionRawTokens.dimension25 }
@objc open var spaceScaledSmashTablet: SpaceSemanticToken { DimensionRawTokens.dimension50 }
@objc open var spaceScaledShortestMobile: SpaceSemanticToken { DimensionRawTokens.dimension50 }
@objc open var spaceScaledShortestTablet: SpaceSemanticToken { DimensionRawTokens.dimension100 }
@objc open var spaceScaledShorterMobile: SpaceSemanticToken { DimensionRawTokens.dimension100 }
@objc open var spaceScaledShorterTablet: SpaceSemanticToken { DimensionRawTokens.dimension150 }
@objc open var spaceScaledShortMobile: SpaceSemanticToken { DimensionRawTokens.dimension150 }
@objc open var spaceScaledShortTablet: SpaceSemanticToken { DimensionRawTokens.dimension200 }
@objc open var spaceScaledMediumMobile: SpaceSemanticToken { DimensionRawTokens.dimension200 }
@objc open var spaceScaledMediumTablet: SpaceSemanticToken { DimensionRawTokens.dimension300 }
@objc open var spaceScaledTallMobile: SpaceSemanticToken { DimensionRawTokens.dimension300 }
@objc open var spaceScaledTallTablet: SpaceSemanticToken { DimensionRawTokens.dimension400 }
@objc open var spaceScaledTallerMobile: SpaceSemanticToken { DimensionRawTokens.dimension400 }
@objc open var spaceScaledTallerTablet: SpaceSemanticToken { DimensionRawTokens.dimension500}
@objc open var spaceScaledTallestMobile: SpaceSemanticToken { DimensionRawTokens.dimension500 }
@objc open var spaceScaledTallestTablet: SpaceSemanticToken { DimensionRawTokens.dimension600 }
@objc open var spaceScaledSpaciousMobile: SpaceSemanticToken { DimensionRawTokens.dimension600 }
@objc open var spaceScaledSpaciousTablet: SpaceSemanticToken { DimensionRawTokens.dimension700 }

// MARK: Semantic token - Spacing - Layout fix

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension MockTheme {
static let mockThemeSpaceRawToken: DimensionRawToken = 911
static let mockThemeSpaceSemanticToken = MultipleSpaceTokens(compact: 1, regular: 151)

// MARK: Semantic token - Spacing - Layout fluid
// MARK: Semantic token - Spacing - Layout fluid (multiple)

override open var spaceScaledNone: MultipleSpaceTokens { Self.mockThemeSpaceSemanticToken }
override open var spaceScaledSmash: MultipleSpaceTokens { Self.mockThemeSpaceSemanticToken }
Expand All @@ -32,6 +32,29 @@ extension MockTheme {
override open var spaceScaledTallest: MultipleSpaceTokens { Self.mockThemeSpaceSemanticToken }
override open var spaceScaledSpacious: MultipleSpaceTokens { Self.mockThemeSpaceSemanticToken }

// MARK: Semantic token - Spacing - Layout fluid (pure semantic)

override open var spaceScaledNoneMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledNoneTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledSmashMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledSmashTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledShortestMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledShortestTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledShorterMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledShorterTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledShortMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledShortTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledMediumMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledMediumTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledTallMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledTallTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledTallerMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledTallerTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledTallestMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledTallestTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledSpaciousMobile: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
override open var spaceScaledSpaciousTablet: SpaceSemanticToken { Self.mockThemeSpaceRawToken }

// MARK: Semantic token - Spacing - Layout fix

override open var spaceFixedNone: SpaceSemanticToken { Self.mockThemeSpaceRawToken }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import OUDS
import XCTest

// swiftlint:disable required_deinit
// swiftlint:disable implicitly_unwrapped_optional
// swiftlint:disable type_name

/// The architecture of _OUDS iOS_ _Swift package_ library is based on _object oriented paradigm_ and overriding of classes.
/// In factn the `OUDSTheme` object is a class, which can be seens as an _asbtract class_, exposing through its extensions and protocols _spacing semantic tokens_.
/// These semantic tokens should be overriden by subclass like the `OrangeTheme` default theme.

/// **These tests checks if any _space multiple semantic tokens_ can be surcharged by a child theme**
/// **Also, it can help to find removed or renamed tokens by having tests no more compilable**
final class TestThemeOverrideOfSpaceMultipleSemanticTokens: XCTestCase {

private var abstractTheme: OUDSTheme!
private var inheritedTheme: OUDSTheme!

override func setUp() async throws {
abstractTheme = OUDSTheme()
inheritedTheme = MockTheme()
}

// MARK: - Semantic token - Spacing - Layout fluid

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledNone() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledNone, abstractTheme.spaceScaledNone)
XCTAssertTrue(inheritedTheme.spaceScaledNone.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledSmash() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledSmash, abstractTheme.spaceScaledSmash)
XCTAssertTrue(inheritedTheme.spaceScaledSmash.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledShortest() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledShortest, abstractTheme.spaceScaledShortest)
XCTAssertTrue(inheritedTheme.spaceScaledShortest.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledShorter() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledShorter, abstractTheme.spaceScaledShorter)
XCTAssertTrue(inheritedTheme.spaceScaledShorter.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledShort() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledShort, abstractTheme.spaceScaledShort)
XCTAssertTrue(inheritedTheme.spaceScaledShort.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledMedium() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledMedium, abstractTheme.spaceScaledMedium)
XCTAssertTrue(inheritedTheme.spaceScaledMedium.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledTall() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledTall, abstractTheme.spaceScaledTall)
XCTAssertTrue(inheritedTheme.spaceScaledTall.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledTaller() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledTaller, abstractTheme.spaceScaledTaller)
XCTAssertTrue(inheritedTheme.spaceScaledTaller.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledTallest() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledTallest, abstractTheme.spaceScaledTallest)
XCTAssertTrue(inheritedTheme.spaceScaledTallest.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}

func testInheritedThemeCanOverrideSemanticTokenSpaceScaledSpacious() throws {
XCTAssertNotEqual(inheritedTheme.spaceScaledSpacious, abstractTheme.spaceScaledSpacious)
XCTAssertTrue(inheritedTheme.spaceScaledSpacious.isEqual(MockTheme.mockThemeSpaceSemanticToken))
}
}

// swiftlint:enable required_deinit
// swiftlint:enable implicitly_unwrapped_optional
// swiftlint:enable type_name
Loading

0 comments on commit 93dbd3f

Please sign in to comment.