Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding presets for following viewports: 1) iPhone-XR, 2) iPhone-X, 3)… #4967

Merged
merged 8 commits into from
Aug 26, 2019
2 changes: 1 addition & 1 deletion cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4364,7 +4364,7 @@ declare namespace Cypress {

type Encodings = 'ascii' | 'base64' | 'binary' | 'hex' | 'latin1' | 'utf8' | 'utf-8' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-16le'
type PositionType = "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight"
type ViewportPreset = 'macbook-15' | 'macbook-13' | 'macbook-11' | 'ipad-2' | 'ipad-mini' | 'iphone-6+' | 'iphone-6' | 'iphone-5' | 'iphone-4' | 'iphone-3'
type ViewportPreset = 'macbook-15' | 'macbook-13' | 'macbook-11' | 'ipad-2' | 'ipad-mini' | 'iphone-xr' | 'iphone-x' | 'iphone-6+' | 'iphone-6' | 'iphone-5' | 'iphone-4' | 'iphone-3' | 'samsung-s10' | 'samsung-note9'
interface Offset {
top: number,
left: number
Expand Down
4 changes: 4 additions & 0 deletions packages/driver/src/cy/commands/window.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ viewports = {
"macbook-11" : "1366x768"
"ipad-2" : "768x1024"
"ipad-mini" : "768x1024"
"iphone-xr" : "414x896"
"iphone-x" : "375x812"
"iphone-6+" : "414x736"
"iphone-6" : "375x667"
"iphone-5" : "320x568"
"iphone-4" : "320x480"
"iphone-3" : "320x480"
"samsung-s10" : "360x760"
"samsung-note9" : "414x846"
}

validOrientations = ["landscape", "portrait"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,20 @@ describe "src/cy/commands/window", ->

cy.viewport("ipad-mini")

it "iphone-xr", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 414, viewportHeight: 896}
done()

cy.viewport("iphone-xr")

it "iphone-x", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 375, viewportHeight: 812}
done()

cy.viewport("iphone-x")

it "iphone-6+", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 414, viewportHeight: 736}
Expand Down Expand Up @@ -581,6 +595,20 @@ describe "src/cy/commands/window", ->

cy.viewport("iphone-5", "portrait")

it "samsung-s10", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 360, viewportHeight: 760}
done()

cy.viewport("samsung-s10")

it "samsung-note9", (done) ->
cy.on "viewport:changed", (viewport) ->
expect(viewport).to.deep.eq {viewportWidth: 414, viewportHeight: 846}
done()

cy.viewport("samsung-note9")

context "errors", ->
beforeEach ->
Cypress.config("defaultCommandTimeout", 50)
Expand All @@ -596,7 +624,7 @@ describe "src/cy/commands/window", ->
it "throws with passed invalid preset", (done) ->
cy.on "fail", (err) =>
expect(@logs.length).to.eq(1)
expect(err.message).to.eq "cy.viewport() could not find a preset for: 'foo'. Available presets are: macbook-15, macbook-13, macbook-11, ipad-2, ipad-mini, iphone-6+, iphone-6, iphone-5, iphone-4, iphone-3"
expect(err.message).to.match /^cy.viewport\(\) could not find a preset for: 'foo'. Available presets are: /
done()

cy.viewport("foo")
Expand Down