-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { renderHook, waitFor } from 'test/test-utils'; | ||
|
||
import { usePlatform } from '../usePlatform'; | ||
|
||
describe('usePlatform', () => { | ||
it('should return platform details', async () => { | ||
// ARRANGE | ||
const { result } = renderHook(() => usePlatform()); | ||
await waitFor(() => expect(result.current).not.toBeNull()); | ||
|
||
// ASSERT | ||
expect(result.current).toBeDefined(); | ||
expect(result.current.isNativePlatform).toBe(false); | ||
expect(result.current.platforms.length).toBeGreaterThan(0); | ||
}); | ||
}); |
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,35 @@ | ||
import { Capacitor } from '@capacitor/core'; | ||
import { getPlatforms } from '@ionic/react'; | ||
|
||
/** | ||
* The `Platform` type has attributes which describe the platform on which the | ||
* application is running. | ||
* @param {boolean} isNativePlatform - Returns `true` if the application is | ||
* running as a native mobile application; otherwise returns `false`. | ||
* @param {string[]} platforms - An array of platforms describing the runtime | ||
* environment. | ||
* @see {@link https://ionicframework.com/docs/react/platform#platforms} | ||
*/ | ||
type Platform = { | ||
isNativePlatform: boolean; | ||
platforms: string[]; | ||
}; | ||
|
||
/** | ||
* The `usePlatform` hook provides details about the `Platform` on which the | ||
* application is running. | ||
* | ||
* @see {@link https://ionicframework.com/docs/react/platform} | ||
* @returns {Platform} A `Platform` object. | ||
*/ | ||
export const usePlatform = (): Platform => { | ||
const isNativePlatform = Capacitor.isNativePlatform(); | ||
console.log(`usePlatform::isNativePlatform::${isNativePlatform}`); | ||
const platforms = getPlatforms(); | ||
console.log(`usePlatform::platforms::${platforms}`); | ||
|
||
return { | ||
isNativePlatform, | ||
platforms, | ||
}; | ||
}; |