-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: get screen and window info #7
Closed
Closed
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './browser-info'; | ||
export * from './web-capabilities'; | ||
export * from './cpu-info'; | ||
export * from './window-info'; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { windowInfo } from './window-info'; | ||
|
||
describe('windowInfo', () => { | ||
it('returns the correct screen width and height when accessed', () => { | ||
expect.hasAssertions(); | ||
|
||
jest.spyOn(window.screen, 'width', 'get').mockReturnValue(1280); | ||
jest.spyOn(window.screen, 'height', 'get').mockReturnValue(720); | ||
|
||
expect(windowInfo.getScreenWidth()).toBe(1280); | ||
expect(windowInfo.getScreenHeight()).toBe(720); | ||
}); | ||
it('returns undefined for screen width and height when the properties are not defined', () => { | ||
expect.hasAssertions(); | ||
|
||
jest.spyOn(window.screen, 'height', 'get').mockImplementation(); | ||
jest.spyOn(window.screen, 'width', 'get').mockImplementation(); | ||
|
||
expect(windowInfo.getScreenWidth()).toBeUndefined(); | ||
expect(windowInfo.getScreenHeight()).toBeUndefined(); | ||
}); | ||
it('returns the correct window width and height when accessed', () => { | ||
expect.hasAssertions(); | ||
|
||
Object.defineProperty(window, 'innerWidth', { | ||
value: 1080, | ||
}); | ||
Object.defineProperty(window, 'innerHeight', { | ||
value: 480, | ||
}); | ||
|
||
expect(windowInfo.getWindowWidth()).toBe(1080); | ||
expect(windowInfo.getWindowHeight()).toBe(480); | ||
}); | ||
it('returns undefined for window width and height when the properties are not defined', () => { | ||
expect.hasAssertions(); | ||
|
||
Object.defineProperty(window, 'innerWidth', { | ||
value: undefined, | ||
}); | ||
Object.defineProperty(window, 'innerHeight', { | ||
value: undefined, | ||
}); | ||
|
||
expect(windowInfo.getWindowWidth()).toBeUndefined(); | ||
expect(windowInfo.getWindowHeight()).toBeUndefined(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Provides information about the screen dimensions. | ||
*/ | ||
export class windowInfo { | ||
/** | ||
* Retrieves the width of the screen. | ||
* | ||
* @returns The width of the screen in pixels, or undefined if not available. | ||
*/ | ||
static getScreenWidth(): number | undefined { | ||
return window.screen.width; | ||
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.
though, when using only |
||
} | ||
|
||
/** | ||
* Retrieves the height of the screen. | ||
* | ||
* @returns The height of the screen in pixels, or undefined if not available. | ||
*/ | ||
static getScreenHeight(): number | undefined { | ||
return window.screen.height; | ||
} | ||
|
||
/** | ||
* Retrieves the width of the browser window's content area. | ||
* | ||
* @returns The width of the content area in pixels, or undefined if not available. | ||
*/ | ||
static getWindowWidth(): number | undefined { | ||
return window.innerWidth; | ||
} | ||
|
||
/** | ||
* Retrieves the height of the browser window's content area. | ||
* | ||
* @returns The height of the content area in pixels, or undefined if not available. | ||
*/ | ||
static getWindowHeight(): number | undefined { | ||
return window.innerHeight; | ||
} | ||
} |
Oops, something went wrong.
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.
innerWidth
andinnerHeight
do not have a get property, so they couldn't be spied on.