Skip to content

Commit

Permalink
should render all menu names
Browse files Browse the repository at this point in the history
  • Loading branch information
guvenkaranfil committed Jan 7, 2024
1 parent cc33d73 commit 2d3615b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 11 deletions.
59 changes: 56 additions & 3 deletions __tests__/MenuEdit.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
import React from 'react';
import {render} from '../.jest/helper/testUtils';
import {render, screen} from '../.jest/helper/testUtils';

import MenuEdit from '../app/tabs/MenuEdit';
import MenuEdit, {IMenuItem} from '../app/tabs/MenuEdit';

describe('Menu Edit Page', () => {
test('should render MenuEdit', () => {
render(<MenuEdit />);
render(<MenuEdit menus={MOCK_MENU_ITEMS} />);
});
test('should render all menu names', () => {
render(<MenuEdit menus={MOCK_MENU_ITEMS} />);

const allItemNames = screen.queryAllByText(/Item/i);

expect(allItemNames).toHaveLength(8);
MOCK_MENU_ITEMS.map((item, index) => {
expect(allItemNames[index].props.children).toEqual(item.name);
});
});
});

const MOCK_MENU_ITEMS: IMenuItem[] = [
{
id: '7a379770-0524-4ab2-91a9-fcd9fe119999',
name: 'Item 1',
isActive: true,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe120121',
name: 'Item 2',
isActive: false,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe132131',
name: 'Item 3',
isActive: true,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe1191231',
name: 'Item 4',
isActive: true,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe141901',
name: 'Item 5',
isActive: true,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe119912',
name: 'Item 6',
isActive: true,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe14324',
name: 'Item 7',
isActive: true,
},
{
id: '7a379770-0524-4ab2-91a9-fcd9fe11943',
name: 'Item 8',
isActive: false,
},
];
29 changes: 21 additions & 8 deletions app/tabs/MenuEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import {StyleSheet, Text, View} from 'react-native';
import {FlatList, Text} from 'react-native';
import React from 'react';

export default function MenuEdit() {
return (
<View>
<Text>MenuEdit</Text>
</View>
);
export interface IMenuItem {
id: string;
name: string;
isActive: boolean;
}

const styles = StyleSheet.create({});
interface IMenuEditProps {
menus?: IMenuItem[];
}

export default function MenuEdit({menus}: IMenuEditProps) {
if (menus && menus.length > 0) {
return (
<FlatList
data={menus}
renderItem={({item}) => <Text>{item.name}</Text>}
/>
);
}

return null;
}

0 comments on commit 2d3615b

Please sign in to comment.