1 // Copyright 2018-present 650 Industries. All rights reserved. 2 3 import CoreGraphics 4 import ExpoModulesTestCore 5 6 @testable import ExpoModulesCore 7 8 class FunctionWithConvertiblesSpec: ExpoSpec { 9 override func spec() { 10 let appContext = AppContext() 11 let functionName = "function" 12 13 it("converts arguments to CoreGraphics types") { 14 let x = 18.3 15 let y = -4.1 16 let width = 734.6 17 let height = 592.1 18 19 mockModuleHolder(appContext) { 20 AsyncFunction(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in 21 expect(point.x) == x 22 expect(point.y) == y 23 expect(size.width) == width 24 expect(size.height) == height 25 expect(vector.dx) == x 26 expect(vector.dy) == y 27 expect(rect.origin.x) == x 28 expect(rect.origin.y) == y 29 expect(rect.width) == width 30 expect(rect.height) == height 31 } 32 } 33 .callSync(function: functionName, args: [ 34 [x, y], // point 35 ["width": width, "height": height], // size 36 ["dx": x, "dy": y], // vector 37 [x, y, width, height] // rect 38 ]) 39 } 40 41 it("converts arguments to CGColor") { 42 func testColorComponents(_ color: CGColor, _ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat) { 43 expect(color.components?[0]) == red / 255.0 44 expect(color.components?[1]) == green / 255.0 45 expect(color.components?[2]) == blue / 255.0 46 expect(color.components?[3]) == alpha / 255.0 47 } 48 49 mockModuleHolder(appContext) { 50 AsyncFunction(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in 51 testColorComponents(color1, 0x2A, 0x4B, 0x5D, 0xFF) 52 testColorComponents(color2, 0x11, 0xFF, 0x00, 0xDD) 53 testColorComponents(color3, 0x66, 0x00, 0xCC, 0xAA) 54 testColorComponents(color4, 0x00, 0x00, 0x00, 0x00) 55 } 56 } 57 .callSync(function: functionName, args: [ 58 "#2A4B5D", 59 0xDD11FF00, 60 "60CA", 61 0 62 ]) 63 } 64 } 65 } 66