Skip to content

Commit c1acc82

Browse files
committed
feat: tests
1 parent 931d8d1 commit c1acc82

22 files changed

+206
-754
lines changed

.github/workflows/ci-packages.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ jobs:
7171
yarn install --immutable
7272
- name: Typecheck
7373
run: |
74-
yarn workspaces foreach -tv --from 'react-native-carplay' --since=origin/main --recursive run typecheck
74+
yarn workspaces foreach -tv --from 'react-native-carplay' --since=origin/master --recursive run typecheck
7575
- name: Linter
7676
run: |
77-
yarn workspaces foreach -tv --include 'react-native-carplay' --since=origin/main --recursive run lint --cache
77+
yarn workspaces foreach -tv --include 'react-native-carplay' --since=origin/master --recursive run lint --cache
7878
- name: Run build for changed packages
7979
run: |
80-
yarn workspaces foreach -tv --include 'react-native-carplay' --since=origin/main run build
80+
yarn workspaces foreach -tv --include 'react-native-carplay' --since=origin/master run build

apps/docs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"@docusaurus/core": "2.4.1",
1919
"@docusaurus/preset-classic": "2.4.1",
20+
"@docusaurus/theme-classic": "2.4.1",
2021
"@mdx-js/react": "^1.6.22",
2122
"clsx": "^1.1.1",
2223
"prism-react-renderer": "^1.3.5",

apps/docs/src/components/HomepageFeatures/index.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ type FeatureItem = {
1111
const FeatureList: FeatureItem[] = [
1212
{
1313
title: 'Easy to Use',
14-
Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default,
14+
Svg: require('../../../static/img/undraw_docusaurus_mountain.svg').default,
1515
description: (
1616
<>
17-
Docusaurus was designed from the ground up to be easily installed and
18-
used to get your website up and running quickly.
17+
Docusaurus was designed from the ground up to be easily installed and used to get your
18+
website up and running quickly.
1919
</>
2020
),
2121
},
2222
{
2323
title: 'Focus on What Matters',
24-
Svg: require('@site/static/img/undraw_docusaurus_tree.svg').default,
24+
Svg: require('../../../static/img/undraw_docusaurus_tree.svg').default,
2525
description: (
2626
<>
27-
Docusaurus lets you focus on your docs, and we&apos;ll do the chores. Go
28-
ahead and move your docs into the <code>docs</code> directory.
27+
Docusaurus lets you focus on your docs, and we&apos;ll do the chores. Go ahead and move your
28+
docs into the <code>docs</code> directory.
2929
</>
3030
),
3131
},
3232
{
3333
title: 'Powered by React',
34-
Svg: require('@site/static/img/undraw_docusaurus_react.svg').default,
34+
Svg: require('../../../static/img/undraw_docusaurus_react.svg').default,
3535
description: (
3636
<>
37-
Extend or customize your website layout by reusing React. Docusaurus can
38-
be extended while reusing the same header and footer.
37+
Extend or customize your website layout by reusing React. Docusaurus can be extended while
38+
reusing the same header and footer.
3939
</>
4040
),
4141
},
4242
];
4343

44-
function Feature({title, Svg, description}: FeatureItem) {
44+
function Feature({ title, Svg, description }: FeatureItem) {
4545
return (
4646
<div className={clsx('col col--4')}>
4747
<div className="text--center">

apps/docs/src/pages/index.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import React from 'react';
22
import clsx from 'clsx';
3-
import Layout from '@theme/Layout';
4-
import Link from '@docusaurus/Link';
5-
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
3+
import Layout from '@docusaurus/theme-classic/lib/theme/Layout';
4+
import Link from '@docusaurus/core/lib/client/exports/Link';
5+
import useDocusaurusContext from '@docusaurus/core/lib/client/exports/useDocusaurusContext';
66
import styles from './index.module.css';
7-
import HomepageFeatures from '@site/src/components/HomepageFeatures';
7+
import HomepageFeatures from '../components/HomepageFeatures';
88

99
function HomepageHeader() {
10-
const {siteConfig} = useDocusaurusContext();
10+
const { siteConfig } = useDocusaurusContext();
1111
return (
1212
<header className={clsx('hero hero--primary', styles.heroBanner)}>
1313
<div className="container">
1414
<h1 className="hero__title">{siteConfig.title}</h1>
1515
<p className="hero__subtitle">{siteConfig.tagline}</p>
1616
<div className={styles.buttons}>
17-
<Link
18-
className="button button--secondary button--lg"
19-
to="/api">
17+
<Link className="button button--secondary button--lg" to="/api">
2018
Get Started
2119
</Link>
2220
</div>
@@ -26,11 +24,12 @@ function HomepageHeader() {
2624
}
2725

2826
export default function Home(): JSX.Element {
29-
const {siteConfig} = useDocusaurusContext();
27+
const { siteConfig } = useDocusaurusContext();
3028
return (
3129
<Layout
3230
title={`Hello from ${siteConfig.title}`}
33-
description="Description will go into a meta tag in <head />">
31+
description="Description will go into a meta tag in <head />"
32+
>
3433
<HomepageHeader />
3534
<main>
3635
<HomepageFeatures />

apps/example/metro.config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*
55
* @format
66
*/
7-
const path = require("path");
7+
const path = require('path');
8+
const nm = ['node', 'modules'].join('_');
89

910
module.exports = {
1011
transformer: {
@@ -16,7 +17,7 @@ module.exports = {
1617
}),
1718
},
1819
watchFolders: [
19-
path.resolve(__dirname, '../../node_modules'),
20-
path.resolve(__dirname, '../../packages/react-native-carplay')
20+
path.resolve(__dirname, '../../', nm),
21+
path.resolve(__dirname, '../../packages/react-native-carplay'),
2122
],
22-
};
23+
};

apps/example/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@react-navigation/stack": "^6.3.16",
1515
"react": "18.2.0",
1616
"react-native": "0.71.8",
17-
"react-native-carplay": "workspace:^",
17+
"react-native-carplay": "workspace:*",
1818
"react-native-gesture-handler": "^2.10.1",
1919
"react-native-safe-area-context": "^4.5.3",
2020
"react-native-screens": "^3.20.0"
@@ -32,7 +32,7 @@
3232
"eslint": "^8.19.0",
3333
"jest": "^29.2.1",
3434
"metro-react-native-babel-preset": "0.73.9",
35-
"prettier": "^2.4.1",
35+
"prettier": "2.6.2",
3636
"react-test-renderer": "18.2.0",
3737
"typescript": "4.8.4"
3838
},
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "@react-native-community",
3+
"parserOptions": {
4+
"project": "tsconfig.json"
5+
},
6+
"ignorePatterns": ["node_modules", "lib", "ios", ".eslintrc"],
7+
"rules": {
8+
"no-void": "off"
9+
}
10+
}

packages/react-native-carplay/package.json

+6-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"podspecPath": "./react-native-carplay.podspec",
1515
"scripts": {
16-
"prepare": "yarn run build",
16+
"prepack": "yarn run build",
1717
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
1818
"typecheck": "tsc --noEmit",
1919
"build": "tsc",
@@ -50,21 +50,16 @@
5050
}
5151
},
5252
"devDependencies": {
53+
"@react-native-community/eslint-config": "3.2.0",
5354
"@tsconfig/react-native": "3.0.2",
5455
"@types/node": "17.0.25",
5556
"@types/react": "18.0.6",
5657
"@types/react-native": "0.67.5",
57-
"@typescript-eslint/eslint-plugin": "5.20.0",
58-
"@typescript-eslint/parser": "5.20.0",
58+
"babel-jest": "^29.2.1",
5959
"cross-env": "7.0.3",
6060
"docusaurus-plugin-typedoc": "0.19.2",
61-
"eslint": "8.13.0",
62-
"eslint-config-prettier": "8.5.0",
63-
"eslint-import-resolver-typescript": "2.7.1",
64-
"eslint-plugin-import": "2.26.0",
65-
"eslint-plugin-prettier": "4.0.0",
66-
"eslint-plugin-react": "7.29.4",
67-
"eslint-plugin-react-hooks": "4.4.0",
61+
"eslint": "^8.19.0",
62+
"jest": "29.5.0",
6863
"microbundle": "0.14.2",
6964
"prettier": "2.6.2",
7065
"rimraf": "3.0.2",
@@ -73,4 +68,4 @@
7368
"typedoc-plugin-markdown": "3.15.3",
7469
"typescript": "5.0.4"
7570
}
76-
}
71+
}

packages/react-native-carplay/src/CarPlay.ts

+63-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
1+
import { NativeEventEmitter, NativeModule, NativeModules, Platform } from 'react-native';
22
import { ActionSheetTemplate } from './templates/ActionSheetTemplate';
33
import { AlertTemplate } from './templates/AlertTemplate';
44
import { ContactTemplate } from './templates/ContactTemplate';
@@ -11,8 +11,69 @@ import { SearchTemplate } from './templates/SearchTemplate';
1111
import { TabBarTemplate } from './templates/TabBarTemplate';
1212
import { VoiceControlTemplate } from './templates/VoiceControlTemplate';
1313
import { NowPlayingTemplate } from './templates/NowPlayingTemplate';
14+
import { Maneuver } from './interfaces/Maneuver';
15+
import { TravelEstimates } from './interfaces/TravelEstimates';
16+
import { PauseReason } from './interfaces/PauseReason';
17+
import { TripConfig } from './navigation/Trip';
18+
import { TimeRemainingColor } from './interfaces/TimeRemainingColor';
19+
import { TextConfiguration } from './interfaces/TextConfiguration';
20+
21+
interface InternalCarPlay extends NativeModule {
22+
checkForConnection(): void;
23+
setRootTemplate(templateId: string, animated: boolean): void;
24+
pushTemplate(templateId: string, animated: boolean): void;
25+
popToTemplate(templateId: string, animated: boolean): void;
26+
popToRootTemplate(animated: boolean): void;
27+
popTemplate(animated: boolean): void;
28+
presentTemplate(templateId: string, animated: boolean): void;
29+
dismissTemplate(animated: boolean): void;
30+
enableNowPlaying(enabled: boolean): void;
31+
updateManeuversNavigationSession(id: string, x: Maneuver[]): void;
32+
updateTravelEstimatesNavigationSession(
33+
id: string,
34+
index: number,
35+
estimates: TravelEstimates,
36+
): void;
37+
cancelNavigationSession(id: string): void;
38+
finishNavigationSession(id: string): void;
39+
pauseNavigationSession(id: string, reason: PauseReason, description?: string): void;
40+
createTrip(id: string, config: TripConfig): void;
41+
updateInformationTemplateItems(id: string, config: unknown): void;
42+
updateInformationTemplateActions(id: string, config: unknown): void;
43+
createTemplate(id: string, config: unknown): void;
44+
startNavigationSession(
45+
id: string,
46+
tripId: string,
47+
): Promise<{
48+
tripId: string;
49+
navigationSessionId: string;
50+
}>;
51+
updateTravelEstimatesForTrip(
52+
id: string,
53+
tripId: string,
54+
travelEstimates: TravelEstimates,
55+
timeRemainingColor: TimeRemainingColor,
56+
): void;
57+
updateMapTemplateConfig(id: string, config: unknown): void;
58+
updateMapTemplateMapButtons(id: string, config: unknown): void;
59+
hideTripPreviews(id: string): void;
60+
showTripPreviews(id: string, previews: string[], config: TextConfiguration): void;
61+
showRouteChoicesPreviewForTrip(id: string, tripId: string, config: TextConfiguration): void;
62+
presentNavigationAlert(id: string, config: unknown, animated: boolean): void;
63+
dismissNavigationAlert(id: string, animated: boolean): void;
64+
showPanningInterface(id: string, animated: boolean): void;
65+
dismissPanningInterface(id: string, animated: boolean): void;
66+
getMaximumListSectionCount(id: string): Promise<number>;
67+
getMaximumListItemCount(id: string): Promise<number>;
68+
reactToSelectedResult(status: boolean): void;
69+
updateListTemplateSections(id: string, config: unknown): void;
70+
updateListTemplateItem(id: string, config: unknown): void;
71+
reactToUpdatedSearchText(items: unknown): void;
72+
updateTabBarTemplates(id: string, config: unknown): void;
73+
activateVoiceControlState(id: string, identifier: string): void;
74+
}
1475

15-
const { RNCarPlay } = NativeModules;
76+
const { RNCarPlay } = NativeModules as { RNCarPlay: InternalCarPlay };
1677

1778
type PushableTemplates =
1879
| MapTemplate

packages/react-native-carplay/src/interfaces/BarButton.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSourcePropType } from "react-native";
1+
import { ImageSourcePropType } from 'react-native';
22

33
interface BarButtonBase {
44
/**

packages/react-native-carplay/src/interfaces/GridButton.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSourcePropType } from "react-native";
1+
import { ImageSourcePropType } from 'react-native';
22

33
/**
44
* A menu item button displayed on a grid template.

packages/react-native-carplay/src/interfaces/ListItem.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSourcePropType } from "react-native";
1+
import { ImageSourcePropType } from 'react-native';
22

33
/**
44
* A list item that appears in a list template.

packages/react-native-carplay/src/interfaces/MapButton.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSourcePropType } from "react-native";
1+
import { ImageSourcePropType } from 'react-native';
22

33
/**
44
* A button representing an action that a map template displays on the CarPlay screen.

packages/react-native-carplay/src/interfaces/NavigationAlert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSourcePropType } from "react-native";
1+
import { ImageSourcePropType } from 'react-native';
22

33
export enum NavigationAlertActionStyle {
44
Default = 0,

packages/react-native-carplay/src/interfaces/VoiceControlState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSourcePropType } from "react-native";
1+
import { ImageSourcePropType } from 'react-native';
22

33
export interface VoiceControlState {
44
identifier: string;

packages/react-native-carplay/src/templates/GridTemplate.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { CarPlay } from '../CarPlay';
21
import { GridButton } from '../interfaces/GridButton';
32
import { BaseEvent, Template, TemplateConfig } from './Template';
43

packages/react-native-carplay/src/templates/ListTemplate.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface ListTemplateConfig extends TemplateConfig {
5151
* Option to hide back button
5252
* (defaults to false)
5353
*/
54-
backButtonHidden?: Boolean;
54+
backButtonHidden?: boolean;
5555

5656
/**
5757
* Assistant Configuration
@@ -88,10 +88,11 @@ export class ListTemplate extends Template<ListTemplateConfig> {
8888
constructor(public config: ListTemplateConfig) {
8989
super(config);
9090

91-
CarPlay.emitter.addListener('didSelectListItem', e => {
91+
CarPlay.emitter.addListener('didSelectListItem', (e: { templateId: string; index: number }) => {
9292
if (config.onItemSelect && e.templateId === this.id) {
93-
const x = config.onItemSelect(e);
94-
Promise.resolve(x).then(() => CarPlay.bridge.reactToSelectedResult(true));
93+
void Promise.resolve(config.onItemSelect(e)).then(() => {
94+
CarPlay.bridge.reactToSelectedResult(true);
95+
});
9596
}
9697
});
9798
}

packages/react-native-carplay/src/templates/MapTemplate.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface MapTemplateConfig extends TemplateConfig {
1616
* Your component to render inside CarPlay
1717
* Example `component: MyComponent`
1818
*/
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1920
component: React.ComponentType<any>;
2021
/**
2122
* An array of map buttons displayed on the trailing bottom corner of the map template.
@@ -42,7 +43,7 @@ export interface MapTemplateConfig extends TemplateConfig {
4243
onPanBeganWithDirection?(e: { direction: string }): void;
4344
onPanEndedWithDirection?(e: { direction: string }): void;
4445
onSelectedPreviewForTrip?(e: { tripId: string; routeIndex: number }): void;
45-
onDidCancelNavigation?(e: {}): void;
46+
onDidCancelNavigation?(): void;
4647
onStartedTrip?(e: { tripId: string; routeIndex: number }): void;
4748
}
4849

0 commit comments

Comments
 (0)