From 2d3615b332a86b2c6a10826cd831662c80c5da4c Mon Sep 17 00:00:00 2001 From: guvenkaranfil Date: Sun, 7 Jan 2024 20:11:43 +0300 Subject: [PATCH] should render all menu names --- __tests__/MenuEdit.test.tsx | 59 +++++++++++++++++++++++++++++++++++-- app/tabs/MenuEdit.tsx | 29 +++++++++++++----- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/__tests__/MenuEdit.test.tsx b/__tests__/MenuEdit.test.tsx index d96eae5..2b7a854 100644 --- a/__tests__/MenuEdit.test.tsx +++ b/__tests__/MenuEdit.test.tsx @@ -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(); + render(); + }); + test('should render all menu names', () => { + render(); + + 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, + }, +]; diff --git a/app/tabs/MenuEdit.tsx b/app/tabs/MenuEdit.tsx index db7d7b5..beb4261 100644 --- a/app/tabs/MenuEdit.tsx +++ b/app/tabs/MenuEdit.tsx @@ -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 ( - - MenuEdit - - ); +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 ( + {item.name}} + /> + ); + } + + return null; +}