Skip to content

Commit

Permalink
feat: add raw tokens and semantic tokens for opacity (#29)
Browse files Browse the repository at this point in the history
THis commit updates when needed the values of raw tokens and semenatic tokens for opacity.
It brings also unit tests for theme overriding and raw tokens relationships.

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Aug 6, 2024
1 parent d960506 commit 6092834
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [Library] Add raw tokens and semantic tokens for opacity ([#29](https://github.com/Orange-OpenSource/ouds-ios/issues/29))
- [Showcase] Publication of comment on issues about new alpha build upload on TestFlight ([#56](https://github.com/Orange-OpenSource/ouds-ios/issues/56))
- [Library] Add raw tokens and semantic tokens for border ([#30](https://github.com/Orange-OpenSource/ouds-ios/issues/30))
- [Library] Define Swift Package architecture of library and tokens (raw and semantic) ([#33](https://github.com/Orange-OpenSource/ouds-ios/issues/33))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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 XCTest
@testable import OUDSThemesShared

/// 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 _opacity semantic tokens_.
/// These semantic tokens should be overriden by subclass like the `OrangeTheme` default theme.
/// **These tests checks if any _opacity semantic tokens_ can be surcharged by a child theme**
final class ThemeOverrideOfOpacitySemanticTokens: XCTestCase {

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

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

/// Test overriding of opacity width semantic tokens
func testInheritedThemeCanOverrideOpacitySemanticTokens() throws {
XCTAssertNotEqual(inheritedTheme.opacityTransparent, abstractTheme.opacityTransparent)
XCTAssertTrue(inheritedTheme.opacityTransparent == MockTheme.mockThemeOpacityRawToken)

XCTAssertNotEqual(inheritedTheme.opacityWeaker, abstractTheme.opacityWeaker)
XCTAssertTrue(inheritedTheme.opacityWeaker == MockTheme.mockThemeOpacityRawToken)

XCTAssertNotEqual(inheritedTheme.opacityWeak, abstractTheme.opacityWeak)
XCTAssertTrue(inheritedTheme.opacityWeak == MockTheme.mockThemeOpacityRawToken)

XCTAssertNotEqual(inheritedTheme.opacityMedum, abstractTheme.opacityMedum)
XCTAssertTrue(inheritedTheme.opacityMedum == MockTheme.mockThemeOpacityRawToken)

XCTAssertNotEqual(inheritedTheme.opacityEmphasis, abstractTheme.opacityEmphasis)
XCTAssertTrue(inheritedTheme.opacityEmphasis == MockTheme.mockThemeOpacityRawToken)

XCTAssertNotEqual(inheritedTheme.opacityOpaque, abstractTheme.opacityOpaque)
XCTAssertTrue(inheritedTheme.opacityOpaque == MockTheme.mockThemeOpacityRawToken)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// 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

extension MockTheme {

static let mockThemeOpacityRawToken: OpacityRawToken = 713

override var opacityTransparent: OpacitySemanticToken { Self.mockThemeOpacityRawToken }
override var opacityWeaker: OpacitySemanticToken { Self.mockThemeOpacityRawToken }
override var opacityWeak: OpacitySemanticToken { Self.mockThemeOpacityRawToken }
override var opacityMedum: OpacitySemanticToken { Self.mockThemeOpacityRawToken }
override var opacityEmphasis: OpacitySemanticToken { Self.mockThemeOpacityRawToken }
override var opacityOpaque: OpacitySemanticToken { Self.mockThemeOpacityRawToken }
}
5 changes: 5 additions & 0 deletions OUDS/Core/Tokens/RawTokens/Sources/OpacityRawTokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public typealias OpacityRawToken = Double

/// This is the group of all **raw tokens** related to **opacity**.
/// Primitive types such as `Double` must be used to as to allow to use `@objc` keywords in extensions for overriding.
/// Such tokens are packed in a _Swift struct_ so as to gather them in one object and avoid to have just constants in nothing else
/// (i.e. publicly accessible from everywhere) or _Swift enum_ which are too heavy (no needs to iterate on them, no needs to make switch/cases,
/// risks to have broken code if new values added breaking existing switch/cases).
///
/// In the future, generating tools like _Style Dictionary_ should either follow this file template and structure or just replace values or lines.
public struct OpacityRawTokens {

// MARK: Primitive token - Opacity
Expand Down
36 changes: 36 additions & 0 deletions OUDS/Core/Tokens/RawTokens/Tests/OpacityRawTokensTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// 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 XCTest
import OUDSTokensRaw

/// The aim of this tests class is to look for regressions in **opacity raw tokens**.
/// Because these values will be at least generated through an external tool, is it not relevant to test each token values.
/// Indeed, each future generation of Swift code may break theses tests because there are new values.
/// However, in the semantics of border raw tokens, there will be some unchanged things like relationships between tokens.
/// Thus this tests class just checks if such relationships are still here whatever the values at the end.
final class OpacityRawTokensTests: XCTestCase {

/// Whathever the values are, opacity raw tokens must keep their order relationships
func testOrderRelationshipForWidths() throws {
XCTAssertLessThan(OpacityRawTokens.opacity0, OpacityRawTokens.opacity100)
XCTAssertLessThan(OpacityRawTokens.opacity100, OpacityRawTokens.opacity200)
XCTAssertLessThan(OpacityRawTokens.opacity200, OpacityRawTokens.opacity300)
XCTAssertLessThan(OpacityRawTokens.opacity300, OpacityRawTokens.opacity400)
XCTAssertLessThan(OpacityRawTokens.opacity400, OpacityRawTokens.opacity500)
XCTAssertLessThan(OpacityRawTokens.opacity500, OpacityRawTokens.opacity600)
XCTAssertLessThan(OpacityRawTokens.opacity600, OpacityRawTokens.opacity700)
XCTAssertLessThan(OpacityRawTokens.opacity700, OpacityRawTokens.opacity800)
XCTAssertLessThan(OpacityRawTokens.opacity800, OpacityRawTokens.opacity900)
}
}

0 comments on commit 6092834

Please sign in to comment.