Skip to content

Commit

Permalink
Add missing BallonMarker missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Aug 25, 2024
1 parent 4a641be commit 8ceaed2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ open class BalloonMarker: MarkerImage {

var size = size

if size.width == 0.0, image != nil {
size.width = image?.size.width ?? 0.0
if size.width == 0.0, let image {
size.width = image.size.width
}
if size.height == 0.0, image != nil {
size.height = image?.size.height ?? 0.0
if size.height == 0.0, let image {
size.height = image.size.height
}

let width = size.width
Expand Down Expand Up @@ -216,7 +216,9 @@ open class BalloonMarker: MarkerImage {
_drawAttributes[NSAttributedString.Key.paragraphStyle] = _paragraphStyle
_drawAttributes[NSAttributedString.Key.foregroundColor] = textColor

_labelSize = labelns?.size(withAttributes: _drawAttributes) ?? CGSize.zero
if let labelns {
_labelSize = labelns.size(withAttributes: _drawAttributes)
}

var size = CGSize()
size.width = _labelSize.width + insets.left + insets.right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,21 @@ final class BalloonMarkerTests: XCTestCase {
UIGraphicsEndImageContext()
}

func test_draw_with_backgroundColor() {
func test_draw_noLabel_doesNotDraw() {
UIGraphicsBeginImageContext(CGSize(width: 100, height: 100))
let context = UIGraphicsGetCurrentContext()!

let initialImage = UIGraphicsGetImageFromCurrentImageContext()

sut.draw(context: context, point: CGPoint(x: 50, y: 50))

let drawnImage = UIGraphicsGetImageFromCurrentImageContext()

XCTAssertEqual(drawnImage?.pngData(), initialImage?.pngData())
UIGraphicsEndImageContext()
}

func test_drawBackground_drawDownwardArrow() {
UIGraphicsBeginImageContext(CGSize(width: 100, height: 100))
let context = UIGraphicsGetCurrentContext()!

Expand All @@ -113,4 +127,26 @@ final class BalloonMarkerTests: XCTestCase {
XCTAssertNotNil(drawnImage)
UIGraphicsEndImageContext()
}

func test_drawBackground_upwardArrow() {
UIGraphicsBeginImageContext(CGSize(width: 100, height: 100))
let context = UIGraphicsGetCurrentContext()!

let point = CGPoint(x: 50, y: 10)
sut.size = CGSize(width: 40, height: 30)

let chartView = ChartViewBase()
sut.chartView = chartView

sut.setLabel("Test Label")
sut.color = .blue

let offset = sut.offsetForDrawing(atPoint: point)

sut.draw(context: context, point: point)

let drawnImage = UIGraphicsGetImageFromCurrentImageContext()
XCTAssertNotNil(drawnImage)
UIGraphicsEndImageContext()
}
}

0 comments on commit 8ceaed2

Please sign in to comment.