213 lines
7.7 KiB
Swift
213 lines
7.7 KiB
Swift
//
|
|
// MVMCoreUITests.swift
|
|
// MVMCoreUITests
|
|
//
|
|
// Created by Kyle Hedden on 5/16/24.
|
|
// Copyright © 2024 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
import MVMCoreUI
|
|
import MVMCore
|
|
|
|
enum TestError: Error {
|
|
case resoureNotFound
|
|
}
|
|
|
|
final class MVMCoreUITests: XCTestCase {
|
|
|
|
override class func setUp() {
|
|
super.setUp()
|
|
CoreUIModelMapping.registerObjects()
|
|
}
|
|
|
|
override func setUpWithError() throws {
|
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
}
|
|
|
|
override func tearDownWithError() throws {
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
}
|
|
|
|
//func testExample() throws {
|
|
// This is an example of a functional test case.
|
|
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
// Any test you write for XCTest can be annotated as throws and async.
|
|
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
|
|
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
|
|
//}
|
|
|
|
func testModelShallowEquality() throws {
|
|
let model1 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
)
|
|
])
|
|
|
|
let model2 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
)
|
|
])
|
|
|
|
let model3 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Moon")
|
|
)
|
|
])
|
|
|
|
XCTAssertTrue(model1.isVisuallyEquivalent(to: model2))
|
|
XCTAssertTrue(model1.isVisuallyEquivalent(to: model3))
|
|
|
|
XCTAssertTrue(LabelModel(text: "Hello World").isEqual(to: LabelModel(text: "Hello World")))
|
|
XCTAssertFalse(LabelModel(text: "Hello World").isEqual(to: LabelModel(text: "Hello Moon")))
|
|
}
|
|
|
|
func testFindFirstCompare() throws {
|
|
|
|
let model1 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
)
|
|
])
|
|
|
|
let model2 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Moon")
|
|
)
|
|
])
|
|
|
|
let result = model1.findFirst(in: model2) { model1, model2 in
|
|
model1.isEqual(to: model2)
|
|
}
|
|
XCTAssertTrue(result.matched)
|
|
XCTAssertEqual((result.theirs as? LabelModel)?.text, "Hello Moon")
|
|
}
|
|
|
|
func testDeepCompare() throws {
|
|
|
|
let model1 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
)
|
|
])
|
|
|
|
let model2 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Moon")
|
|
)
|
|
])
|
|
|
|
let attributedLabel = LabelModel(text: "Hello World")
|
|
attributedLabel.attributes = [LabelAttributeActionModel(0, 5, action: ActionNoopModel())]
|
|
let model3 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
attributedLabel
|
|
)
|
|
])
|
|
|
|
let attributedLabel2 = LabelModel(text: "Hello World")
|
|
attributedLabel2.attributes = [LabelAttributeActionModel(0, 5, action: ActionBackModel())]
|
|
let model4 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
attributedLabel2
|
|
)
|
|
])
|
|
|
|
let results = model1.findAllNotEqual(against: model2)
|
|
XCTAssertEqual(results.count, 1)
|
|
XCTAssertEqual((results.first?.theirs as? LabelModel)?.text, "Hello Moon")
|
|
XCTAssertFalse(model1.deepEquals(to: model2))
|
|
XCTAssertFalse(model1.isDeeplyVisuallyEquivalent(to: model2))
|
|
XCTAssertFalse(model1.deepEquals(to: model3))
|
|
|
|
let visualResults = model3.findFirst(in: model4, failing: { mine, theirs in
|
|
guard let mine = mine as? MoleculeModelComparisonProtocol, let theirs = theirs as? MoleculeModelComparisonProtocol else { return false }
|
|
return mine.isVisuallyEquivalent(to: theirs)
|
|
})
|
|
XCTAssertFalse(visualResults.matched)
|
|
XCTAssertTrue(model3.isDeeplyVisuallyEquivalent(to: model4))
|
|
}
|
|
|
|
func testDeepCompareReturnsAllResults() {
|
|
let model1 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
),
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Moon")
|
|
),
|
|
MoleculeStackItemModel(with:
|
|
StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Stars")
|
|
)
|
|
])
|
|
)
|
|
])
|
|
|
|
let model2 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Stars")
|
|
),
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
),
|
|
MoleculeStackItemModel(with:
|
|
StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Moon")
|
|
)
|
|
])
|
|
)
|
|
])
|
|
|
|
let model3 = StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Stars")
|
|
),
|
|
MoleculeStackItemModel(with:
|
|
StackModel(molecules: [
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello Moon")
|
|
)
|
|
])
|
|
),
|
|
MoleculeStackItemModel(with:
|
|
LabelModel(text: "Hello World")
|
|
)
|
|
])
|
|
|
|
var results = model1.findAllNotEqual(against: model2)
|
|
XCTAssertEqual(results.count, 3)
|
|
|
|
results = model1.findAllNotEqual(against: model3)
|
|
XCTAssertEqual(results.count, 3)
|
|
}
|
|
|
|
func testPageEquality() throws {
|
|
let listTemplateModel1 = try JSONDecoder().decode(ListPageTemplateModel.self, from: getFileData("UAD_page_model"))
|
|
let listTemplateModel2 = try JSONDecoder().decode(ListPageTemplateModel.self, from: getFileData("UAD_page_model"))
|
|
let listTemplateModel3 = try JSONDecoder().decode(ListPageTemplateModel.self, from: getFileData("UAD_page_model_2"))
|
|
|
|
let results = listTemplateModel1.findFirst(in: listTemplateModel2, failing: { $0.isEqual(to: $1) })
|
|
XCTAssertFalse(results.matched)
|
|
XCTAssertTrue(listTemplateModel1.deepEquals(to: listTemplateModel2))
|
|
XCTAssertTrue(listTemplateModel1.isDeeplyVisuallyEquivalent(to: listTemplateModel2))
|
|
|
|
let results2 = listTemplateModel1.findFirst(in: listTemplateModel3, failing: { $0.isEqual(to: $1) })
|
|
XCTAssertTrue(results2.matched)
|
|
XCTAssertFalse(listTemplateModel1.deepEquals(to: listTemplateModel3))
|
|
XCTAssertTrue(listTemplateModel1.isDeeplyVisuallyEquivalent(to: listTemplateModel3))
|
|
}
|
|
|
|
func testPageEqualityPerformance() throws {
|
|
let listTemplateModel1 = try JSONDecoder().decode(ListPageTemplateModel.self, from: getFileData("UAD_page_model"))
|
|
let listTemplateModel2 = try JSONDecoder().decode(ListPageTemplateModel.self, from: getFileData("UAD_page_model_2"))
|
|
measure {
|
|
XCTAssertFalse(listTemplateModel1.deepEquals(to: listTemplateModel2))
|
|
}
|
|
}
|
|
|
|
}
|