Skip to content

Commit b0d8224

Browse files
Tayebsed93pylapp
andauthored
test: add UI-based unit tests of tokens using demo application (#154) (#197)
Reviewed-by-by: Pierre-Yves Lapersonne <[email protected]> Signed-off-by: Pierre-Yves Lapersonne <[email protected]> Co-authored-by: Pierre-Yves Lapersonne <[email protected]> Co-authored-by: Tayeb Sedraia <[email protected]>
1 parent b2c5ce3 commit b0d8224

File tree

1,569 files changed

+2171
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,569 files changed

+2171
-167
lines changed

.github/DEVELOP.md

+63-3
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,73 @@ To run these UI tests follow some steps:
127127
2. `bundle exec pod install`
128128
3. Open *Showcase.xcworkspace*
129129
4. Select *ShowcaseTests* scheme
130-
5. Select some simulator (tests designed for *iPhone 13 Pro Max* and *iPhone 14 Pro Max* but works elsewhere)
130+
5. Select *iPhone 16 Pro* simulator (the device used to tests and views rendering)
131131
6. Run tests (Product -> Test)
132132

133133
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.
134-
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.
134+
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.
135+
136+
Such tests here are used to as to be sure the look and feel of any components and tokens rendering remain the expected ones.
137+
138+
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.
139+
140+
**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**.
141+
142+
#### How to use to use swift-snapshot-testing library
143+
144+
1. Locate where are the reference images:
145+
- In the Package directory, you will find the reference screenshots for the Orange and Inverse themes (Light/Dark), which will serve as comparison baselines.
146+
```text
147+
OUDS -> Showcase -> ShowcaseTests -> __Snapshots__
148+
```
149+
2. Navigate to the project :
150+
- Open your project in Xcode and go to a directory containing tests (e.g. here *OUDSTokensOpacityUITests*):
151+
```shell
152+
Showcase -> ShowcaseTests -> OUDSTokensOpacityUITests -> OUDSTokensOpacityUITests.swift
153+
```
154+
3. Open a test file (e.g. here *OUDSTokensOpacityUITests*):
155+
- Open the file `OUDSTokensOpacityUITests.swift`.
156+
4. Run the snapshot test (success):
157+
- Locate and execute some function like `testAllOpacitiesOrangeThemeLight()`.
158+
159+
<img width="897" alt="OrangeThemeLight_OpacityTest_Success" src="https://github.com/user-attachments/assets/550bed90-6bc9-4d68-aaf0-8e04de35d916">
160+
161+
The snapshot tool fetched the reference image to compare it against the current screen and detected no differences, resulting in a success
162+
163+
5. Run the snapshot test (failure):
164+
- We will deliberately change the image by setting the `OpacityOpaque` token to `OpacityTransparent` in class `OpacityTokenPage.swift`
165+
166+
<img width="561" alt="IntentionalTokenModification" src="https://github.com/user-attachments/assets/1d138b7b-2998-40b7-bf39-d9a597ced6c0">
167+
- Test result failure :
168+
169+
<img width="897" alt="IntentionalUITestError" src="https://github.com/user-attachments/assets/0a6bb578-adba-42f1-abe8-e2f50ddba2a7">
170+
171+
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.
172+
173+
7. Verify the output:
174+
- It is recommended to use the `Show the Report Navigator` tool in Xcode :
175+
176+
<img width="512" alt="ShowReportNavigator_Xcode" src="https://github.com/user-attachments/assets/8d866d79-5dfc-46c7-934e-8d03ec1fc667">
177+
178+
- In Xcode go to :
179+
180+
```shell
181+
ShowcaseTests -> ShowcaseTests/ShowcaseTests
182+
```
183+
184+
<img width="1206" alt="TestResult_Failed_testAllOpacitiesOrangeThemeLight" src="https://github.com/user-attachments/assets/1793df83-ffc1-4226-8be2-fbd7e2b71deb">
185+
186+
8. Comparison (reference and failure):
187+
188+
**Reference:**
189+
190+
<img width="1307" alt="OpacityReferenceImage" src="https://github.com/user-attachments/assets/493dabde-4139-468f-a57b-10ee5a5269c1">
191+
192+
193+
**Failure:**
194+
195+
<img width="1364" alt="OpacityFailureImage" src="https://github.com/user-attachments/assets/03cfe17f-3752-4aba-a482-f89d3b89f53d">
135196
136-
Such tests here are used to as to be sure the look and feel of any components and tokens rendering remaing the expected ones.
137197
138198
## Build phases
139199

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased](https://github.com/Orange-OpenSource/ouds-ios/compare/0.6.0...develop)
88

9+
### Added
10+
11+
- [DemoApp] Add more UI tests on demo app ([#154](https://github.com/Orange-OpenSource/ouds-ios/issues/154))
12+
13+
### Fixed
14+
15+
- [Library] Warning issues for DocC catalogs ([#293](https://github.com/Orange-OpenSource/ouds-ios/issues/293))
16+
917
### Changed
1018

1119
- [Tool] Use `macos-15` runner for GitHub Actions builds ([#296](https://github.com/Orange-OpenSource/ouds-ios/issues/296))

0 commit comments

Comments
 (0)