Add a new screen
Add Tests
This commit is contained in:
22
StudyCK/StudyCKTests/Info.plist
Normal file
22
StudyCK/StudyCKTests/Info.plist
Normal 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>
|
||||
80
StudyCK/StudyCKTests/StudyCKTests.swift
Normal file
80
StudyCK/StudyCKTests/StudyCKTests.swift
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user