Skip to content

Commit

Permalink
refactor(review): improve sources
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
  • Loading branch information
pylapp committed Nov 20, 2024
1 parent 50d241d commit 3f8c1f9
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 60 deletions.
29 changes: 14 additions & 15 deletions .github/DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,34 @@ To run these UI tests follow some steps:
2. `bundle exec pod install`
3. Open *Showcase.xcworkspace*
4. Select *ShowcaseTests* scheme
5. Select some simulator (tests designed for *iPhone 16 Pro*)
5. Select *iPhone 16 Pro* simulator (the device used to tests and views rendering)
6. Run tests (Product -> Test)

Beware, if you add new UI tests using [swift-snapshot-testing](https://github.com/pointfreeco/swift-snapshot-testing) library, you may have new tests which fail at first time.
Indeed for new tests the tool makes snapshots of the views, thus for the first run no preview exist making the tests fail. You should run the tests twice for new tests.
Indeed for new tests the tool makes snapshots of the views, thus for the first run no previews exist making the tests fail. You should run the tests twice for new tests.

Such tests here are used to as to be sure the look and feel of any components and tokens rendering remaing the expected ones.
Such tests here are used to as to be sure the look and feel of any components and tokens rendering remain the expected ones.

Any interface modifications require regenerating the illustrations using the tool. The reference illustrations have already been saved within the project.
Any interface modifications require regenerating the illustrations using the tool, i.e. run the tests twice. The reference illustrations have already been saved within the project.

#### Steps to use swift-snapshot-testing
**Note today because the showcase app is hosted in the repository, the tests assets are versioned too, thus the _Swift Package_ will be heavy when being downloaded because Xcode downloads the entire repository. When the showcase app will be extracted to an internal repository, the _Swift Package_ will be lighter**.

1. Locate reference images:
#### How to use to use swift-snapshot-testing library

1. Locate where are the reference images:
- In the Package directory, you will find the reference screenshots for the Orange and Inverse themes (Light/Dark), which will serve as comparison baselines.
```text
OUDS -> Showcase -> ShowcaseTests -> __Snapshots__
```
2. Navigate to the project :
- Open your project in Xcode and go to the directory:
- Open your project in Xcode and go to a directory containing tests (e.g. here *OUDSTokensOpacityUITests*):
```shell
Showcase -> ShowcaseTests -> OUDSTokensBorderUITests -> OUDSTokensBorderUITests.swift
Showcase -> ShowcaseTests -> OUDSTokensOpacityUITests -> OUDSTokensOpacityUITests.swift
```
3. Open the test tile:
- Open the file `OUDSTokensBorderUITests.swift`.
3. Open a test file (e.g. here *OUDSTokensOpacityUITests*):
- Open the file `OUDSTokensOpacityUITests.swift`.
4. Run the snapshot test (success):
- Locate and execute the function `testAllOpacitiesOrangeThemeLight()`.
- Locate and execute some function like `testAllOpacitiesOrangeThemeLight()`.
<img width="897" alt="OrangeThemeLight_OpacityTest_Success" src="https://github.com/user-attachments/assets/550bed90-6bc9-4d68-aaf0-8e04de35d916">
Expand All @@ -166,13 +168,11 @@ The snapshot tool fetched the reference image to compare it against the current
<img width="897" alt="IntentionalUITestError" src="https://github.com/user-attachments/assets/0a6bb578-adba-42f1-abe8-e2f50ddba2a7">

The swift-snapshot-testing tool indicates that the issue originates from the transparent token illustration. We can observe that there are two paths: the first corresponds to our reference illustration (the one we intend to base our comparison on), while the second path is the illustration used for the current image of the application. You can open both paths and visually compare the differences.
The *swift-snapshot-testing tool* indicates that the issue originates from the transparent token illustration. We can observe that there are two paths: the first corresponds to our reference illustration (the one we intend to base our comparison on), while the second path is the illustration used for the current image of the application. You can open both paths and visually compare the differences.
7. Verify the output:
- It is recommended to use the `Show the Report Navigator` tool in Xcode :

<img width="512" alt="ShowReportNavigator_Xcode" src="https://github.com/user-attachments/assets/8d866d79-5dfc-46c7-934e-8d03ec1fc667">
- In Xcode go to :
Expand All @@ -183,7 +183,6 @@ The snapshot tool fetched the reference image to compare it against the current
<img width="1206" alt="TestResult_Failed_testAllOpacitiesOrangeThemeLight" src="https://github.com/user-attachments/assets/1793df83-ffc1-4226-8be2-fbd7e2b71deb">

8. Comparison (reference and failure):
**Reference:**
Expand Down
8 changes: 4 additions & 4 deletions Showcase/Showcase/Pages/Tokens/Border/BorderTokenPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ struct BorderTokenPage: View {
@Environment(\.theme) private var theme
@Environment(\.colorScheme) private var colorScheme

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?

init(forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil) {
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
forcedTheme = theme
forcedColorScheme = colorScheme
}

/// Computed property for colorScheme
Expand Down
8 changes: 4 additions & 4 deletions Showcase/Showcase/Pages/Tokens/Color/ColorTokenPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ struct ColorTokenPage: View {
@Environment(\.theme) private var theme
@Environment(\.colorScheme) private var colorScheme

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?

init(forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil) {
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
forcedTheme = theme
forcedColorScheme = colorScheme
}

/// Computed property for colorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ struct SizeTokenPage: View {
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(\.colorScheme) private var colorScheme

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?
/// A `HorizontalSizeClass` to force for this `View` whatever the environnement `horizontalSizeClass` is (for UI tests purposes)
/// A `HorizontalSizeClass` to force for this `View` whatever the environnement `horizontalSizeClass` is (for UI tests purposes)
private let forcedHorizontalSizeClass: UserInterfaceSizeClass?

init(forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil, horizontalSizeClass: UserInterfaceSizeClass? = nil) {
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
self.forcedHorizontalSizeClass = horizontalSizeClass
forcedTheme = theme
forcedColorScheme = colorScheme
forcedHorizontalSizeClass = horizontalSizeClass
}

/// Computed property for colorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ struct SpaceTokenPage: View {
@Environment(\.verticalSizeClass) private var verticalSizeClass
@Environment(\.colorScheme) private var colorScheme

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?
/// A `HorizontalSizeClass` to force for this `View` whatever the environnement `horizontalSizeClass` is (for UI tests purposes)
/// A `HorizontalSizeClass to force for this `View` whatever the environnement `horizontalSizeClass` is (for UI tests purposes)
private let forcedHorizontalSizeClass: UserInterfaceSizeClass?
/// A `VerticalSizeClass` to force for this `View` whatever the environnement `verticalSizeClass` is (for UI tests purposes)
/// A `VerticalSizeClass` to force for this `View` whatever the environnement `verticalSizeClass` is (for UI tests purposes)
private let forcedVerticalSizeClass: UserInterfaceSizeClass?

init(forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil, horizontalSizeClass: UserInterfaceSizeClass? = nil, verticalSizeClass: UserInterfaceSizeClass? = nil) {
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
self.forcedHorizontalSizeClass = horizontalSizeClass
self.forcedVerticalSizeClass = verticalSizeClass
init(forceTo theme: OUDSTheme? = nil,
colorScheme: ColorScheme? = nil,
horizontalSizeClass: UserInterfaceSizeClass? = nil,
verticalSizeClass: UserInterfaceSizeClass? = nil) {
forcedTheme = theme
forcedColorScheme = colorScheme
forcedHorizontalSizeClass = horizontalSizeClass
forcedVerticalSizeClass = verticalSizeClass
}

/// Computed property for colorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ struct ElevationTokenPage: View {
@Environment(\.theme) private var theme
@Environment(\.colorScheme) private var colorScheme

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?

init(forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil) {
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
forcedTheme = theme
forcedColorScheme = colorScheme
}

/// Computed property for colorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ struct TypographyTokenPage: View {
@Environment(\.colorScheme) private var colorScheme
@Environment(\.horizontalSizeClass) private var horizontalSizeClass

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?
/// A `HorizontalSizeClass` to force for this `View` whatever the environnement `horizontalSizeClass` is (for UI tests purposes)
/// A `HorizontalSizeClass` to force for this `View` whatever the environnement `horizontalSizeClass` is (for UI tests purposes)
private let forcedHorizontalSizeClass: UserInterfaceSizeClass?

init(forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil, horizontalSizeClass: UserInterfaceSizeClass? = nil) {
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
self.forcedHorizontalSizeClass = horizontalSizeClass
forcedTheme = theme
forcedColorScheme = colorScheme
forcedHorizontalSizeClass = horizontalSizeClass
}

/// Computed property for colorScheme
Expand Down
14 changes: 9 additions & 5 deletions Showcase/Showcase/Pages/Utils/ShowcaseTokenIllustration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ struct ShowcaseTokenIllustration<TokenIllustration>: View where TokenIllustratio
let tokenValue: String?
@ViewBuilder let tokenIllustration: () -> TokenIllustration

/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
/// A theme to force for this `View` whatever the environnement `theme` is (for UI tests purposes)
private let forcedTheme: OUDSTheme?
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
/// A `ColorScheme` to force for this `View` whatever the environnement `colorScheme` is (for UI tests purposes)
private let forcedColorScheme: ColorScheme?

// MARK: Initializer

init(tokenName: String, tokenValue: String? = nil, forceTo theme: OUDSTheme? = nil, colorScheme: ColorScheme? = nil, tokenIllustration: @escaping () -> TokenIllustration) {
init(tokenName: String,
tokenValue: String? = nil,
forceTo theme: OUDSTheme? = nil,
colorScheme: ColorScheme? = nil,
tokenIllustration: @escaping () -> TokenIllustration) {
self.tokenIllustration = tokenIllustration
self.forcedTheme = theme
self.forcedColorScheme = colorScheme
forcedTheme = theme
forcedColorScheme = colorScheme
self.tokenName = tokenName
self.tokenValue = tokenValue
}
Expand Down
4 changes: 2 additions & 2 deletions Showcase/ShowcaseTests/Snapshots/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ enum Snapshot {
assertSnapshot(
of: viewController,
as: .image(on: .iPhone13ProMax, traits: Self.darkStyleTraits),
file: file,
file: (file),
testName: testName,
line: line)

assertSnapshot(
of: viewController,
as: .image(on: .iPhone13ProMax, traits: Self.lightStyleTraits),
file: file,
file: (file),
testName: testName,
line: line)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class OUDSTokensBorderUITests: XCTestCase {

// Section Radius
for borderRadius in NamedBorderRadius.allCases {
/// Use the `illustration(for:)` method to test a single illustration
// Use the `illustration(for:)` method to test a single illustration
let illustration = borderPage.illustration(for: borderRadius)
.background(orangeTheme.colorBgPrimary.color(for: lightScheme))

Expand All @@ -71,7 +71,7 @@ final class OUDSTokensBorderUITests: XCTestCase {

// Section Style
for borderStyle in NamedBorderStyle.allCases {
/// Use the `illustration(for:)` method to test a single illustration
// Use the `illustration(for:)` method to test a single illustration
let illustration = borderPage.illustration(for: borderStyle)
.background(orangeTheme.colorBgPrimary.color(for: lightScheme))

Expand Down Expand Up @@ -147,7 +147,7 @@ final class OUDSTokensBorderUITests: XCTestCase {

// Section Width
for borderWidth in NamedBorderWidth.allCases {
/// Use the `illustration(for:)` method to test a single illustration
// Use the `illustration(for:)` method to test a single illustration
let illustration = borderPage.illustration(for: borderWidth)
.background(inverseTheme.colorBgPrimary.color(for: lightScheme))

Expand Down Expand Up @@ -213,7 +213,7 @@ final class OUDSTokensBorderUITests: XCTestCase {

// Section Radius
for borderRadius in NamedBorderRadius.allCases {
/// Use the `illustration(for:)` method to test a single illustration
// Use the `illustration(for:)` method to test a single illustration
let illustration = borderPage.illustration(for: borderRadius)
.background(inverseTheme.colorBgPrimary.color(for: darkScheme))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class OUDSTokensSizeUITests: XCTestCase {

// IconDecorative
for sizing in NamedSize.IconDecorative.allCases {
/// Use the `illustrationIconDecorative(for:)` method to test a single illustration
// Use the `illustrationIconDecorative(for:)` method to test a single illustration
let illustration = sizePage.illustrationIconDecorative(for: sizing)
.background(orangeTheme.colorBgPrimary.color(for: lightScheme))

Expand Down

0 comments on commit 3f8c1f9

Please sign in to comment.