generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new avatar colors + tests * better docs * the init can actually be public * Apply suggestions from code review Co-authored-by: Doug <[email protected]> * code improvement * Create tests.yml * changed the name to Tests * better naming of the workflow * running tests using xcodebuild * not specifying minor version * tests are OS independent * using the same runner of el-x --------- Co-authored-by: Doug <[email protected]>
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This workflow will build a Swift project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift | ||
|
||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
tests: | ||
|
||
runs-on: macos-13 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run tests | ||
run: xcodebuild test -scheme 'Compound' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Mauro Romito on 31/08/23. | ||
// | ||
|
||
import Foundation | ||
|
||
@testable import Compound | ||
import SwiftUI | ||
import XCTest | ||
|
||
final class AvatarColorsTests: XCTestCase { | ||
struct TestCase { | ||
let input: String | ||
private let webOutput: Int | ||
|
||
// remember that web starts the index from 1 while we start from 0 | ||
var output: Int { | ||
webOutput - 1 | ||
} | ||
|
||
init(input: String, webOutput: Int) { | ||
self.input = input | ||
self.webOutput = webOutput | ||
} | ||
} | ||
|
||
func testAvatarColorHash() { | ||
// Match the tests with the web ones for consistency between the two platforms | ||
// https://github.com/vector-im/compound-web/blob/5dda11aa9733462fb8422968181275bc3e9b35e3/src/components/Avatar/Avatar.test.tsx#L62 | ||
let testCases: [TestCase] = [ | ||
.init(input: "@bob:example.org", webOutput: 8), | ||
.init(input: "@alice:example.org", webOutput: 3), | ||
.init(input: "@charlie:example.org", webOutput: 5), | ||
.init(input: "@dan:example.org", webOutput: 8), | ||
.init(input: "@elena:example.org", webOutput: 2), | ||
.init(input: "@fanny:example.org", webOutput: 1) | ||
] | ||
|
||
for testCase in testCases { | ||
XCTAssertEqual(Color.compound.avatarColor(for: testCase.input), Color.compound.avatarColors[testCase.output]) | ||
} | ||
} | ||
} |