Skip to content

Commit

Permalink
fix: Address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Squidonomics committed Feb 24, 2024
1 parent 639ffdb commit 443f3af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
11 changes: 4 additions & 7 deletions Sources/WebDriver/Requests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ public enum Requests {
public var orientation: ScreenOrientation

public var pathComponents: [String] { ["session", session, "orientation"] }
public var method: HTTPMethod {.post}
public var body: Body {.init(orientation: orientation)}
public var method: HTTPMethod { .post }
public var body: Body { .init(orientation: orientation) }

public struct Body: Codable {
public var orientation: ScreenOrientation
Expand All @@ -583,12 +583,9 @@ public enum Requests {
public var session: String

public var pathComponents: [String] { ["session", session, "orientation"] }
public var method: HTTPMethod {.get}
public var method: HTTPMethod { .get }

public typealias Response = ResponseWithValue<ResponseValue>
public struct ResponseValue: Codable {
public var screenOrientation: String
}
public typealias Response = ResponseWithValue<ScreenOrientation>
}
}
}
25 changes: 10 additions & 15 deletions Sources/WebDriver/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public class Session {
}
}
}

public var orientation: ScreenOrientation {
get throws {
let response = try webDriver.send(Requests.SessionOrientation.Get(session: id))
return response.value
}
}

/// Sets a a timeout value on this session.
public func setTimeout(type: String, duration: TimeInterval) throws {
Expand Down Expand Up @@ -321,23 +328,11 @@ public class Session {
try webDriver.send(Requests.SessionWindowSize.Post(session: id, windowHandle: handle, width: width, height: height))
}

/// - Parameter orientation: Orientation the window will flip to {LANDSCAPE|PORTRAIT}
public func portraitOrientation(orientation: ScreenOrientation = .portrait) throws {
try webDriver.send(Requests.SessionOrientation.Post(session: id, orientation: orientation))
}

/// - Parameter orientation: Orientation the window will flip to {LANDSCAPE|PORTRAIT}
public func landscapeOrientation(orientation: ScreenOrientation = .landscape) throws {
try webDriver.send(Requests.SessionOrientation.Post(session: id, orientation: orientation))
}

/// - Parameter orientation: Orientation the window is oriented to {LANDSCAPE|PORTRAIT}
public func orientation() throws -> String {
let response = try webDriver.send(Requests.SessionOrientation.Get(session: id))
return response.value.screenOrientation
/// - Prarmeter: Orientation the window will flip to {LANDSCAPE|PORTRAIT}
public func setOrientation(_ value: ScreenOrientation) throws {
try webDriver.send(Requests.SessionOrientation.Post(session: id, orientation: value))
}


/// - Returns: The current page source.
public func source() throws -> String {
let response = try webDriver.send(Requests.SessionSource(session: id))
Expand Down
12 changes: 6 additions & 6 deletions Tests/UnitTests/APIToRequestMappingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@ class APIToRequestMappingTests: XCTestCase {
let mockWebDriver: MockWebDriver = MockWebDriver()
let session = Session(webDriver: mockWebDriver, existingId: "mySession")
mockWebDriver.expect(path: "session/mySession/orientation", method: .post)
try session.portraitOrientation()
try session.setOrientation(.portrait)

mockWebDriver.expect(path: "session/mySession/orientation", method: .get, type: Requests.SessionOrientation.Get.self) {
ResponseWithValue(.init(screenOrientation: "PORTRAIT"))
ResponseWithValue(.portrait)
}
XCTAssert(try session.orientation() == "PORTRAIT")
XCTAssert(try session.orientation == .portrait)

mockWebDriver.expect(path: "session/mySession/orientation", method: .post)
try session.landscapeOrientation()
try session.setOrientation(.landscape)

mockWebDriver.expect(path: "session/mySession/orientation", method: .get, type: Requests.SessionOrientation.Get.self) {
ResponseWithValue(.init(screenOrientation: "LANDSCAPE"))
ResponseWithValue(.landscape)
}
XCTAssert(try session.orientation() == "LANDSCAPE")
XCTAssert(try session.orientation == .landscape)
}


Expand Down

0 comments on commit 443f3af

Please sign in to comment.