Skip to content

Commit

Permalink
Tests for display orientation detection (#4875)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozyx committed May 9, 2022
1 parent 9df06ef commit cc4cd6c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/utils/agent/AgentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("The Agent", function () {
expect(agent.isTablet()).toBeTruthy();
});

it("detects display orientation", function () {
it("detects display orientation by innerHeight and innerWidth", function () {
agent = new Agent(testWindow);
testWindow.innerWidth = 1024;
testWindow.innerHeight = 400;
Expand All @@ -80,6 +80,34 @@ describe("The Agent", function () {
expect(agent.isLandscape()).toBeFalsy();
});

it("detects display orientation by screen.orientation", function () {
agent = new Agent(testWindow);
testWindow.screen = {
orientation: {
type: "landscape-primary"
}
};
expect(agent.isPortrait()).toBeFalsy();
expect(agent.isLandscape()).toBeTruthy();
testWindow.screen = {
orientation: {
type: "portrait-primary"
}
};
expect(agent.isPortrait()).toBeTruthy();
expect(agent.isLandscape()).toBeFalsy();
});

it("detects display orientation by window.orientation", function () {
agent = new Agent(testWindow);
testWindow.orientation = 90;
expect(agent.isPortrait()).toBeFalsy();
expect(agent.isLandscape()).toBeTruthy();
testWindow.orientation = 0;
expect(agent.isPortrait()).toBeTruthy();
expect(agent.isLandscape()).toBeFalsy();
});

it("detects touch support", function () {
testWindow.ontouchstart = null;
expect(new Agent(testWindow).isTouch()).toBe(true);
Expand Down

0 comments on commit cc4cd6c

Please sign in to comment.