Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Aug 29, 2024
1 parent 48ad9bb commit 624d280
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/common/hooks/__tests__/usePlatform.test.ts
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);
});
});
35 changes: 35 additions & 0 deletions src/common/hooks/usePlatform.ts
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,
};
};

0 comments on commit 624d280

Please sign in to comment.