Skip to content

Commit

Permalink
Use constant test values in annotation tests (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
evil159 committed Jun 6, 2024
1 parent ab51c71 commit 6d685c1
Show file tree
Hide file tree
Showing 14 changed files with 1,547 additions and 1,535 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ final class AnnotationImagesManagerTests: XCTestCase {

func testAnnotationImagesAddedToStyleIfNotExist() throws {
// given
let imageID = UUID().uuidString, sdf = Bool.random(), contentInsets = UIEdgeInsets.random()
let imageID = UUID().uuidString
let sdf = true
let contentInsets = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)

// when
sut.addImage(UIImage(), id: imageID, sdf: sdf, contentInsets: contentInsets)
Expand All @@ -42,10 +44,12 @@ final class AnnotationImagesManagerTests: XCTestCase {

func testAnnotationImagesRemovedFromStyleIfOwned() throws {
// given
let imageIDs = Array.random(withLength: 10) { UUID().uuidString }
for imageID in imageIDs {
sut.addImage(UIImage(), id: imageID, sdf: .random(), contentInsets: .random())
for _ in 0...10 {
sut.addImage(UIImage(), id: UUID().uuidString, sdf: true, contentInsets: .zero)
}
let imageId = "image-id"
sut.addImage(UIImage(), id: imageId, sdf: false, contentInsets: .zero)

mockStyle.imageExistsStub.defaultReturnValue = true

// when
Expand All @@ -54,41 +58,41 @@ final class AnnotationImagesManagerTests: XCTestCase {
XCTAssertTrue(mockStyle.removeImageStub.invocations.isEmpty)

// when
let imageToRemove = try XCTUnwrap(imageIDs.randomElement())
sut.removeImage(imageToRemove)
sut.removeImage(imageId)
// then
XCTAssertEqual(try XCTUnwrap(mockStyle.removeImageStub.invocations.last?.parameters), imageToRemove)
XCTAssertEqual(try XCTUnwrap(mockStyle.removeImageStub.invocations.last?.parameters), imageId)
}

func testAnnotationImagesRemovedFromStyleIfNoConsumers() throws {
// given
let consumer = MockAnnotationImagesConsumer()
sut.register(imagesConsumer: consumer)

let imageIDs = Array.random(withLength: 10) { UUID().uuidString }
for imageID in imageIDs {
sut.addImage(UIImage(), id: imageID, sdf: .random(), contentInsets: .random())
for _ in 0...10 {
sut.addImage(UIImage(), id: UUID().uuidString, sdf: false, contentInsets: .zero)
}
let imageId = "image-id"
sut.addImage(UIImage(), id: imageId, sdf: false, contentInsets: .zero)

mockStyle.imageExistsStub.defaultReturnValue = true

// when
let imageToRemove = try XCTUnwrap(imageIDs.randomElement())
consumer.isUsingStyleImageStub.defaultReturnValue = true
sut.removeImage(imageToRemove)
sut.removeImage(imageId)
// then
XCTAssertTrue(mockStyle.removeImageStub.invocations.isEmpty)

// when
consumer.isUsingStyleImageStub.defaultReturnValue = false
sut.removeImage(imageToRemove)
sut.removeImage(imageId)
// then
XCTAssertEqual(try XCTUnwrap(mockStyle.removeImageStub.invocations.last?.parameters), imageToRemove)
XCTAssertEqual(try XCTUnwrap(mockStyle.removeImageStub.invocations.last?.parameters), imageId)

// when
sut.unregister(imagesConsumer: consumer)
sut.removeImage(imageToRemove)
sut.removeImage(imageId)
// then
XCTAssertEqual(try XCTUnwrap(mockStyle.removeImageStub.invocations.last?.parameters), imageToRemove)
XCTAssertEqual(try XCTUnwrap(mockStyle.removeImageStub.invocations.last?.parameters), imageId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class AnnotationManagerFactoryTests: XCTestCase {
// test return values for factory
func testReturnedPointAnnotationManager() {
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition = .at(50)
let clusterOptions = ClusterOptions()

//when
Expand All @@ -55,7 +55,7 @@ final class AnnotationManagerFactoryTests: XCTestCase {

func testReturnedPolygonAnnotationManager() {
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition? = .at(81)

//when
let manager = factory.makePolygonAnnotationManager(id: id, layerPosition: layerPosition)
Expand All @@ -67,7 +67,7 @@ final class AnnotationManagerFactoryTests: XCTestCase {

func testReturnedPolylineAnnotationManager() {
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition? = .at(56)

//when
let manager = factory.makePolylineAnnotationManager(id: id, layerPosition: layerPosition)
Expand All @@ -80,7 +80,7 @@ final class AnnotationManagerFactoryTests: XCTestCase {
func testReturnedCircleAnnotationManager() {
//given
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition? = .at(18)

//when
let manager = factory.makeCircleAnnotationManager(id: id, layerPosition: layerPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class AnnotationOrchestratorImplTests: XCTestCase {
func testMakePointAnnotationManagers() {
//given
let annotationManagerId = UUID().uuidString
let clusterOptions: ClusterOptions? = .random(ClusterOptions())
let clusterOptions: ClusterOptions? = ClusterOptions()

//when
let manager = impl.makePointAnnotationManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class AnnotationOrchestratorTests: XCTestCase {
func testPointAnnotationnManagerInit() throws {
//given
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let clusterOptions: ClusterOptions? = .random(.init())
let layerPosition: LayerPosition? = .at(38)
let clusterOptions: ClusterOptions? = .init()

//when
_ = annotationOrchestrator.makePointAnnotationManager(id: id, layerPosition: layerPosition, clusterOptions: clusterOptions)
Expand All @@ -40,7 +40,7 @@ final class AnnotationOrchestratorTests: XCTestCase {
func testPolygonAnnotationManagerInit() throws {
//given
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition? = .at(81)

//when
_ = annotationOrchestrator.makePolygonAnnotationManager(id: id, layerPosition: layerPosition) as AnnotationManagerInternal
Expand All @@ -55,7 +55,7 @@ final class AnnotationOrchestratorTests: XCTestCase {
func testPolylineAnnotationManagerInit() throws {
//given
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition? = .at(48)

//when
_ = annotationOrchestrator.makePolylineAnnotationManager(id: id, layerPosition: layerPosition)
Expand All @@ -70,7 +70,7 @@ final class AnnotationOrchestratorTests: XCTestCase {
func testCircleAnnotationManagerInit() throws {
//given
let id = "managerId"
let layerPosition: LayerPosition? = .random(.at(.random(in: 0...10)))
let layerPosition: LayerPosition? = .at(91)

//when
_ = annotationOrchestrator.makeCircleAnnotationManager(id: id, layerPosition: layerPosition)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6d685c1

Please sign in to comment.