mirror of
https://github.com/jellyfin/jellyfin-expo.git
synced 2024-11-27 00:00:26 +00:00
Add DownloadListItem tests
This commit is contained in:
parent
e9c023dbec
commit
f4492ef57a
@ -18,16 +18,22 @@ const DownloadListItem = ({ item, index, onSelect, onPlay, isEditMode = false, i
|
||||
>
|
||||
{isEditMode &&
|
||||
<ListItem.CheckBox
|
||||
testID='select-checkbox'
|
||||
onPress={() => onSelect(item)}
|
||||
checked={isSelected}
|
||||
/>
|
||||
}
|
||||
<ListItem.Content>
|
||||
<ListItem.Title>{item.title}</ListItem.Title>
|
||||
<ListItem.Subtitle>{item.localFilename}</ListItem.Subtitle>
|
||||
<ListItem.Title testID='title'>
|
||||
{item.title}
|
||||
</ListItem.Title>
|
||||
<ListItem.Subtitle testID='subtitle'>
|
||||
{item.localFilename}
|
||||
</ListItem.Subtitle>
|
||||
</ListItem.Content>
|
||||
{item.isComplete ?
|
||||
<Button
|
||||
testID='play-button'
|
||||
type='clear'
|
||||
icon={{
|
||||
name: getIconName('play'),
|
||||
@ -35,7 +41,8 @@ const DownloadListItem = ({ item, index, onSelect, onPlay, isEditMode = false, i
|
||||
}}
|
||||
disabled={isEditMode}
|
||||
onPress={() => onPlay(item)}
|
||||
/> : <ActivityIndicator />
|
||||
/> :
|
||||
<ActivityIndicator testID='loading-indicator' />
|
||||
}
|
||||
</ListItem>
|
||||
);
|
||||
|
95
components/__tests__/DownloadListItem.test.js
Normal file
95
components/__tests__/DownloadListItem.test.js
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { fireEvent, render } from '@testing-library/react-native';
|
||||
import React from 'react';
|
||||
|
||||
import DownloadModel from '../../models/DownloadModel';
|
||||
import DownloadListItem from '../DownloadListItem';
|
||||
|
||||
const TEST_MODEL = new DownloadModel(
|
||||
'item-id',
|
||||
'server-id',
|
||||
'https://example.com/',
|
||||
'api-key',
|
||||
'title',
|
||||
'file name.mkv',
|
||||
'https://example.com/download'
|
||||
);
|
||||
|
||||
describe('DownloadListItem', () => {
|
||||
it('should render correctly', () => {
|
||||
const { getByTestId, queryByTestId } = render(
|
||||
<DownloadListItem
|
||||
item={TEST_MODEL}
|
||||
index={0}
|
||||
onSelect={() => { /* no-op */ }}
|
||||
onPlay={() => { /* no-op */ }}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(queryByTestId('select-checkbox')).toBeNull();
|
||||
|
||||
expect(getByTestId('title')).toHaveTextContent('title');
|
||||
expect(getByTestId('subtitle')).toHaveTextContent('file name.mp4');
|
||||
|
||||
expect(queryByTestId('play-button')).toBeNull();
|
||||
expect(queryByTestId('loading-indicator')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should display the play button and handle presses', () => {
|
||||
const onPlay = jest.fn();
|
||||
|
||||
TEST_MODEL.isComplete = true;
|
||||
|
||||
const { getByTestId, queryByTestId } = render(
|
||||
<DownloadListItem
|
||||
item={TEST_MODEL}
|
||||
index={0}
|
||||
onSelect={() => { /* no-op */ }}
|
||||
onPlay={onPlay}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(queryByTestId('select-checkbox')).toBeNull();
|
||||
|
||||
expect(getByTestId('title')).toHaveTextContent('title');
|
||||
expect(getByTestId('subtitle')).toHaveTextContent('file name.mp4');
|
||||
|
||||
expect(queryByTestId('play-button')).not.toBeNull();
|
||||
expect(queryByTestId('loading-indicator')).toBeNull();
|
||||
|
||||
expect(onPlay).not.toHaveBeenCalled();
|
||||
fireEvent.press(getByTestId('play-button'));
|
||||
expect(onPlay).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should display the select checkbox and handle presses', () => {
|
||||
const onSelect = jest.fn();
|
||||
|
||||
const { getByTestId, queryByTestId } = render(
|
||||
<DownloadListItem
|
||||
item={TEST_MODEL}
|
||||
index={0}
|
||||
onSelect={onSelect}
|
||||
onPlay={() => { /* no-op */ }}
|
||||
isEditMode={true}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(queryByTestId('select-checkbox')).not.toBeNull();
|
||||
|
||||
expect(getByTestId('title')).toHaveTextContent('title');
|
||||
expect(getByTestId('subtitle')).toHaveTextContent('file name.mp4');
|
||||
|
||||
expect(queryByTestId('play-button')).not.toBeNull();
|
||||
expect(queryByTestId('loading-indicator')).toBeNull();
|
||||
|
||||
expect(onSelect).not.toHaveBeenCalled();
|
||||
fireEvent.press(getByTestId('select-checkbox'));
|
||||
expect(onSelect).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@ -178,7 +178,7 @@ exports[`DownloadScreen should render correctly 1`] = `
|
||||
"fontSize": 17,
|
||||
}
|
||||
}
|
||||
testID="listItemTitle"
|
||||
testID="title"
|
||||
>
|
||||
title
|
||||
</Text>
|
||||
@ -190,7 +190,7 @@ exports[`DownloadScreen should render correctly 1`] = `
|
||||
"fontSize": 15,
|
||||
}
|
||||
}
|
||||
testID="listItemTitle"
|
||||
testID="subtitle"
|
||||
>
|
||||
file name.mp4
|
||||
</Text>
|
||||
@ -207,6 +207,7 @@ exports[`DownloadScreen should render correctly 1`] = `
|
||||
color="#999999"
|
||||
hidesWhenStopped={true}
|
||||
size="small"
|
||||
testID="loading-indicator"
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
@ -310,7 +311,7 @@ exports[`DownloadScreen should render correctly 1`] = `
|
||||
"fontSize": 17,
|
||||
}
|
||||
}
|
||||
testID="listItemTitle"
|
||||
testID="title"
|
||||
>
|
||||
other title
|
||||
</Text>
|
||||
@ -322,7 +323,7 @@ exports[`DownloadScreen should render correctly 1`] = `
|
||||
"fontSize": 15,
|
||||
}
|
||||
}
|
||||
testID="listItemTitle"
|
||||
testID="subtitle"
|
||||
>
|
||||
other file name.mp4
|
||||
</Text>
|
||||
@ -339,6 +340,7 @@ exports[`DownloadScreen should render correctly 1`] = `
|
||||
color="#999999"
|
||||
hidesWhenStopped={true}
|
||||
size="small"
|
||||
testID="loading-indicator"
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
Loading…
Reference in New Issue
Block a user