* Copyright (c) 2025 Huawei Technologies Co., Ltd.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {Platform} from 'react-native';
import {TestSuite} from '@rnoh/testerino';
import {TestCase} from '../components';
import {useEnvironment} from '../contexts';
export function PlatformConstantsTest() {
const {
env: {driver},
} = useEnvironment();
return (
<TestSuite name="PlatformConstants">
<TestCase.Logical
skip={{android: true, harmony: false}}
itShould="use 'harmony' as platform name"
fn={({expect}) => {
expect(Platform.OS).to.be.eq('harmony');
}}
/>
<TestCase.Logical
skip={{android: true, harmony: false}}
itShould="specify platform version"
fn={async ({expect}) => {
expect(Platform.Version.toString()).to.match(
/^OpenHarmony-\d+\.\d+\.\d+\.\d+(?:\(Beta\d+\))?$/,
);
}}
/>
<TestCase.Logical
itShould="not be running in tv mode"
fn={({expect}) => {
expect(Platform.isTV).to.be.false;
}}
/>
<TestCase.Logical
skip={{android: true, harmony: false}}
itShould="select Platform properly"
fn={({expect}) => {
expect(
Platform.select({
android: 'a',
ios: 'i',
native: 'n',
harmony: 'h',
}),
).to.be.eq('h');
}}
/>
<TestCase.Logical
itShould="provide some RN version"
fn={({expect}) => {
expect(Platform.constants.reactNativeVersion).to.be.not.undefined;
expect(Platform.constants.reactNativeVersion.major).to.be.not
.undefined;
expect(Platform.constants.reactNativeVersion.minor).to.be.not
.undefined;
expect(Platform.constants.reactNativeVersion.patch).to.be.not
.undefined;
}}
/>
<TestCase.Logical
itShould="provide some value for isTesting"
fn={({expect}) => {
expect(typeof Platform.constants.isTesting).to.be.eq('boolean');
}}
/>
<TestCase.Logical
itShould="specify product model"
skip={{android: true, harmony: !driver}}
fn={async ({expect}) => {
if (Platform.OS === 'harmony') {
expect(await driver?.getDeviceModel()).to.eq(
Platform.constants.Model,
);
}
}}
/>
</TestSuite>
);
}