This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Get window size #125
Open
SebastienBoisard
wants to merge
2
commits into
sclevine:master
Choose a base branch
from
SebastienBoisard:get_window_size
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Get window size #125
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,17 @@ func (w *Window) SetSize(width, height int) error { | |
|
||
return w.Send("POST", "size", request, nil) | ||
} | ||
|
||
func (w *Window) GetSize() (width int, height int, err error) { | ||
request := struct { | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
}{} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove newline |
||
if err := w.Send("GET", "size", nil, &request); err != nil { | ||
return 0, 0 , err | ||
} | ||
|
||
return request.Width, request.Height, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,23 @@ var _ = Describe("Window", func() { | |
}) | ||
}) | ||
}) | ||
|
||
Describe("#GetSize", func() { | ||
It("should successfully send a GET request to the size endpoint", func() { | ||
width, height, err := window.GetSize() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setup and test return values using the mock bus (ideally in a separate test) |
||
Expect(err).To(Succeed()) | ||
Expect(width).To(BeNumerically(">=", 0)) | ||
Expect(height).To(BeNumerically(">=", 0)) | ||
Expect(bus.SendCall.Method).To(Equal("GET")) | ||
Expect(bus.SendCall.Endpoint).To(Equal("window/some-id/size")) | ||
}) | ||
|
||
Context("when the bus indicates a failure", func() { | ||
It("should return an error", func() { | ||
bus.SendCall.Err = errors.New("some error") | ||
_, _, err := window.GetSize() | ||
Expect(err).To(MatchError("some error")) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,7 +336,7 @@ var _ = Describe("Page", func() { | |
}) | ||
}) | ||
|
||
Context("when the window fails to retrieve its size", func() { | ||
Context("when the window fails to set its size", func() { | ||
It("should return an error", func() { | ||
session.GetWindowCall.ReturnWindow = window | ||
bus.SendCall.Err = errors.New("some error") | ||
|
@@ -345,6 +345,43 @@ var _ = Describe("Page", func() { | |
}) | ||
}) | ||
|
||
Describe("#GetSize", func() { | ||
var ( | ||
bus *mocks.Bus | ||
window *api.Window | ||
) | ||
|
||
BeforeEach(func() { | ||
bus = &mocks.Bus{} | ||
window = &api.Window{Session: &api.Session{Bus: bus}} | ||
}) | ||
|
||
It("should get the window width and height", func() { | ||
session.GetWindowCall.ReturnWindow = window | ||
width, height, err := page.GetSize() | ||
Expect(err).To(Succeed()) | ||
Expect(width).To(BeNumerically(">=", 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setup return values using the mock bus |
||
Expect(height).To(BeNumerically(">=", 0)) | ||
}) | ||
|
||
Context("when the session fails to retrieve a window", func() { | ||
It("should return an error", func() { | ||
session.GetWindowCall.Err = errors.New("some error") | ||
_, _, err := page.GetSize() | ||
Expect(err).To(MatchError("failed to retrieve window: some error")) | ||
}) | ||
}) | ||
|
||
Context("when the window fails to retrieve its size", func() { | ||
It("should return an error", func() { | ||
session.GetWindowCall.ReturnWindow = window | ||
bus.SendCall.Err = errors.New("some error") | ||
_, _, err := page.GetSize() | ||
Expect(err).To(MatchError("failed to get window size: some error")) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("#Screenshot", func() { | ||
It("should successfully saves the screenshot", func() { | ||
session.GetScreenshotCall.ReturnImage = []byte("some-image") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct does not represent a request