Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions __tests__/applicationListHeight.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Keeps the application list as tall as its cards.
*
* A board offering one application left an empty band under its card when the
* list stretched to fill the screen down to Device Status. The list must only
* shrink, and scroll, when its cards do not fit.
*
* @format
*/

import React from 'react';
import { ScrollView, StyleSheet } from 'react-native';
import { Provider as PaperProvider } from 'react-native-paper';
import ReactTestRenderer from 'react-test-renderer';

jest.mock('@react-navigation/native', () => ({
useNavigation: () => ({ navigate: jest.fn(), goBack: jest.fn() }),
useRoute: () => ({
params: { deviceId: 'AA:BB:CC:DD:EE:01', deviceName: 'AkidaTag' },
}),
useNavigationState: (
select: (state: { routes: { name: string }[]; index: number }) => string,
) => select({ routes: [{ name: 'DeviceApplications' }], index: 0 }),
}));

jest.mock(
'react-native-safe-area-context',
() => require('react-native-safe-area-context/jest/mock').default,
);

jest.mock('../src/services/ble/bleManager', () => ({
__esModule: true,
default: {
sendCommand: jest.fn(async () => {}),
subscribeToNotifications: jest.fn(() => ({ remove: jest.fn() })),
removeSubscription: jest.fn(),
},
}));

// Required rather than imported so the mocks above are in place before the
// screen and store are loaded.
const DeviceApplicationsScreen =
require('../src/app/screens/Device/DeviceApplicationScreen').default;
const { useBleCommandStore } = require('../src/app/store/useBleCommandStore');

/**
* Render the application list for a board offering only keyword spotting.
*
* @returns The list's scroll view and the bordered frame around it.
*/
const renderOneApplication = async () => {
useBleCommandStore.setState({
appsList: [
{
id: 'keyword',
name: 'Keyword Spotting',
description: '-',
size: '-',
processor: '-',
modelName: '-',
modelVersion: '-',
modelSize: '-',
inputShape: '-',
noOfClasses: '-',
nodes: '-',
powerConsumption: '-',
keywords: [],
},
],
activeApp: null,
});
let renderer!: ReactTestRenderer.ReactTestRenderer;
await ReactTestRenderer.act(() => {
renderer = ReactTestRenderer.create(
<PaperProvider>
<DeviceApplicationsScreen />
</PaperProvider>,
);
});
const list = renderer.root.findByType(ScrollView);
const styles = {
listStyle: StyleSheet.flatten(list.props.style),
frameStyle: StyleSheet.flatten(list.parent!.props.style),
};
await ReactTestRenderer.act(() => renderer.unmount());
return styles;
};

describe('the application list', () => {
afterEach(() => {
useBleCommandStore.setState({ appsList: [] });
});

it('does not grow past its cards to fill the screen', async () => {
const { listStyle, frameStyle } = await renderOneApplication();

expect(frameStyle.flex).toBeUndefined();
expect(frameStyle.flexGrow ?? 0).toBe(0);
expect(listStyle.flex).toBeUndefined();
expect(listStyle.flexGrow).toBe(0);
});

it('shrinks to scroll its cards when they do not fit', async () => {
const { listStyle, frameStyle } = await renderOneApplication();

expect(frameStyle.flexShrink).toBe(1);
expect(listStyle.flexShrink ?? 1).toBe(1);
});
});
7 changes: 4 additions & 3 deletions src/app/screens/Device/DeviceApplicationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,15 @@ const DeviceApplicationsScreen: React.FC = () => {
{/* Scrollable App Cards ONLY */}
<View style={styles.scrollSection}>
<ScrollView
style={{ flex: 1 }}
style={styles.appList}
showsVerticalScrollIndicator={true}
contentContainerStyle={{ gap: 12 }}
>
{appList.map(app => renderAppCard(app))}
</ScrollView>
</View>

{/* Device Status - FIXED at bottom */}
{/* Device Status - FIXED below the list */}
<Text style={styles.statusTitle}>Device Status</Text>
{batteryError ? (
<View
Expand Down Expand Up @@ -608,12 +608,13 @@ const styles = StyleSheet.create({
paddingBottom: 16,
},
scrollSection: {
flex: 1,
flexShrink: 1,
position: 'relative',
borderWidth: 1,
borderColor: `${Colors.border.light}`,
backgroundColor: `${Colors.background}`,
},
appList: { flexGrow: 0 },
appCard: { padding: 15, borderWidth: 1 },
appHeader: { flexDirection: 'row', gap: 16 },
iconBox: {
Expand Down
Loading