Add a new screen

Add Tests
This commit is contained in:
2018-07-10 14:22:28 +08:00
parent 65582f0842
commit b81cebe334
12 changed files with 682 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,80 @@
import XCTest
@testable import StudyCK
class StudyCKTests: XCTestCase {
var loginModel: LoginViewModel! = nil
override func setUp() {
super.setUp()
loginModel = LoginViewModel()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
loginModel = nil
super.tearDown()
}
func testStartLogin() {
let startExpectation = expectation(description: "login state changed to true")
let endExpectation = expectation(description: "login state changed to false")
loginModel.loginStateChanged = {(state: Bool) in
if state {
startExpectation.fulfill()
} else {
endExpectation.fulfill()
}
}
loginModel.login()
wait(for: [startExpectation, endExpectation], timeout: 10.0)
}
func testNoUsernameLogin() {
loginModel.password = "aa"
let expectation = XCTestExpectation(description: "no username")
loginModel.showLoginFailedAlert = {(title: String, message: String) in
if title == "錯誤" && message == "帳號不存在" {
expectation.fulfill()
}
}
loginModel.login()
wait(for: [expectation], timeout: 10.0)
}
func testNoPasswordLogin() {
loginModel.username = "ck1060535"
let expectation = XCTestExpectation(description: "no password")
loginModel.showLoginFailedAlert = {(title: String, message: String) in
if title == "錯誤" && message.contains("密碼錯誤") {
expectation.fulfill()
}
}
loginModel.login()
wait(for: [expectation], timeout: 10.0)
}
func testWrongPasswordLogin() {
loginModel.username = "ck1060535"
loginModel.password = "aa"
let expectation = XCTestExpectation(description: "wrong password")
loginModel.showLoginFailedAlert = {(title: String, message: String) in
if title == "錯誤" && message.contains("密碼錯誤") {
expectation.fulfill()
}
}
loginModel.login()
wait(for: [expectation], timeout: 10.0)
}
func testSuccessfulLogin() {
loginModel.username = "tUsername"
loginModel.password = "tPassword"
let expectation = XCTestExpectation(description: "login successful")
loginModel.loginSuccessfully = {
expectation.fulfill()
}
loginModel.login()
wait(for: [expectation], timeout: 10.0)
}
}