diff --git a/__tests__/__snapshots__/topicCreate.test.native.js.snap.android b/__tests__/__snapshots__/topicCreate.test.native.js.snap.android index 77744a5..61b2838 100644 --- a/__tests__/__snapshots__/topicCreate.test.native.js.snap.android +++ b/__tests__/__snapshots__/topicCreate.test.native.js.snap.android @@ -27,15 +27,35 @@ exports[` renders everything 1`] = ` } } > - - + > + + + renders everything 1`] = ` } } > - - + > + + + renders everything 1`] = ` +exports[` renders everything 1`] = ` renders everything 1`] = ` } > - - renders everything 1`] = ` } /> + renders everything 1`] = ` } } > - NaN - minutos atrás + 1116717 + dias atrás @@ -160,7 +171,6 @@ exports[` renders everything 1`] = ` /> - renders everything 1`] = ` - - - renders everything 1`] = ` +exports[` renders everything 1`] = ` renders everything 1`] = ` } > - - renders everything 1`] = ` } /> + renders everything 1`] = ` } } > - NaN - minutos atrás + 1116717 + dias atrás @@ -160,7 +171,6 @@ exports[` renders everything 1`] = ` /> - renders everything 1`] = ` - - - ', () => { .create() .toJSON(); expect(tree).toMatchSnapshot(); - expect(wrapper.find('View').length).toBe(16); + expect(wrapper.find('View').length).toBe(18); expect(wrapper.find('Text').length).toBe(10); - expect(wrapper.find('TouchableOpacity').length).toBe(1); + expect(wrapper.find('TouchableOpacity').length).toBe(2); expect(wrapper.find('Icon').length).toBe(2); expect(wrapper.find('TextInput').length).toBe(2); }); @@ -33,12 +33,12 @@ describe('', () => { styles.TopicCreatemasterView ); expect(wrapper.find('View').at(2)).toHaveStyle(styles.TopicCreateheader); - expect(wrapper.find('View').at(6)).toHaveStyle(styles.TopicCreatecontainer); - expect(wrapper.find('View').at(8)).toHaveStyle(styles.TopicCreateUserDiv); - expect(wrapper.find('View').at(10)).toHaveStyle( + expect(wrapper.find('View').at(8)).toHaveStyle(styles.TopicCreatecontainer); + expect(wrapper.find('View').at(10)).toHaveStyle(styles.TopicCreateUserDiv); + expect(wrapper.find('View').at(12)).toHaveStyle( styles.TopicCreatetituloDiv ); - expect(wrapper.find('View').at(14)).toHaveStyle( + expect(wrapper.find('View').at(16)).toHaveStyle( styles.TopicCreatescrollDiv ); }); @@ -55,9 +55,6 @@ describe('', () => { expect(wrapper.find('Text').at(8)).toHaveText('username'); }); it('renders TouchableOpacity correctly', () => { - expect(wrapper.find('TouchableOpacity').at(0)).toHaveStyle( - styles.TopicCreatepublicarDiv - ); expect(wrapper.find('TouchableOpacity').at(0)).toHaveProp('onPress'); }); it('renders Icon correctly', () => { diff --git a/__tests__/topicView.test.native.js b/__tests__/topicView.test.native.js index 376dbe1..3dc348f 100644 --- a/__tests__/topicView.test.native.js +++ b/__tests__/topicView.test.native.js @@ -12,7 +12,7 @@ jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage); let wrapper; -describe('', () => { +describe('', () => { beforeEach(() => { wrapper = mount(); }); @@ -23,15 +23,15 @@ describe('', () => { .toJSON(); expect(tree).toMatchSnapshot(); expect(wrapper.find('KeyboardAvoidingView').length).toBe(1); - expect(wrapper.find('View').length).toBe(38); + expect(wrapper.find('View').length).toBe(36); expect(wrapper.find('Header').length).toBe(1); expect(wrapper.find('Image').length).toBe(2); expect(wrapper.find('Data').length).toBe(1); expect(wrapper.find('ScrollView').length).toBe(2); expect(wrapper.find('Comments').length).toBe(1); - expect(wrapper.find('Text').length).toBe(30); - expect(wrapper.find('TouchableOpacity').length).toBe(1); - expect(wrapper.find('Icon').length).toBe(7); + expect(wrapper.find('Text').length).toBe(26); + expect(wrapper.find('TouchableOpacity').length).toBe(2); + expect(wrapper.find('Icon').length).toBe(5); }); it('renders KeyboardAvoidingView correctly', () => { expect(wrapper.find('KeyboardAvoidingView').at(0)).toHaveStyle( @@ -48,7 +48,7 @@ describe('', () => { expect(wrapper.find('Image').at(0)).toHaveProp('defaultSource'); }); it('renders Data correctly', () => { - expect(wrapper.find('Data').at(0)).toHaveProp('tempo'); + expect(wrapper.find('Data').at(0)).toHaveProp('time'); }); it('renders ScrollView correctly', () => { expect(wrapper.find('ScrollView').at(0)).toHaveStyle( @@ -70,44 +70,32 @@ describe('', () => { expect(wrapper.find('View').at(16)).toHaveStyle({ marginTop: 10 }); expect(wrapper.find('View').at(17)).toHaveStyle({ marginTop: 10 }); expect(wrapper.find('View').at(20)).toHaveStyle(styles.topicContainer); - expect(wrapper.find('View').at(26)).toHaveStyle(styles.shareIcon); - expect(wrapper.find('View').at(30)).toHaveStyle(styles.commentsBar); - expect(wrapper.find('View').at(32)).toHaveStyle(styles.commentsListDiv); - expect(wrapper.find('View').at(34)).toHaveStyle(styles.commentsList); + expect(wrapper.find('View').at(28)).toHaveStyle(styles.commentsBar); + expect(wrapper.find('View').at(30)).toHaveStyle(styles.commentsListDiv); + expect(wrapper.find('View').at(32)).toHaveStyle(styles.commentsList); }); it('renders Text correctly', () => { expect(wrapper.find('Text').at(4)).toHaveStyle(styles.nameUser); expect(wrapper.find('Text').at(8)).toHaveStyle(styles.topicDivTitle); - expect(wrapper.find('Text').at(24)).toHaveText('Compartilhar'); - expect(wrapper.find('Text').at(24)).toHaveStyle({ fontSize: 10 }); - expect(wrapper.find('Text').at(26)).toHaveStyle(styles.commentsBarText); - expect(wrapper.find('Text').at(26)).toHaveText('Novo Comentário'); + expect(wrapper.find('Text').at(22)).toHaveStyle(styles.commentsBarText); + expect(wrapper.find('Text').at(22)).toHaveText('Novo Comentário'); }); it('renders TouchableOpacity correctly', () => { - expect(wrapper.find('TouchableOpacity').at(0)).toHaveStyle( - styles.commentsBarDiv - ); expect(wrapper.find('TouchableOpacity').at(0)).toHaveProp('onPress'); }); it('renders Icon correctly', () => { - expect(wrapper.find('Icon').at(2)).toHaveProp('name', 'arrowup'); + expect(wrapper.find('Icon').at(1)).toHaveProp('size', 18); + expect(wrapper.find('Icon').at(1)).toHaveProp('color', gray.shark()); + expect(wrapper.find('Icon').at(1)).toHaveProp('onPress'); + expect(wrapper.find('Icon').at(1)).toHaveProp('name', 'arrowup'); expect(wrapper.find('Icon').at(2)).toHaveProp('size', 18); expect(wrapper.find('Icon').at(2)).toHaveProp('color', gray.shark()); expect(wrapper.find('Icon').at(2)).toHaveProp('onPress'); - expect(wrapper.find('Icon').at(3)).toHaveProp('name', 'arrowdown'); - expect(wrapper.find('Icon').at(3)).toHaveProp('size', 18); + expect(wrapper.find('Icon').at(3)).toHaveProp('name', 'corner-up-right'); + expect(wrapper.find('Icon').at(3)).toHaveProp('size', 15); expect(wrapper.find('Icon').at(3)).toHaveProp('color', gray.shark()); - expect(wrapper.find('Icon').at(3)).toHaveProp('onPress'); - expect(wrapper.find('Icon').at(4)).toHaveProp('name', 'edit'); - expect(wrapper.find('Icon').at(4)).toHaveProp('size', 18); + expect(wrapper.find('Icon').at(4)).toHaveProp('name', 'triangle-right'); + expect(wrapper.find('Icon').at(4)).toHaveProp('size', 15); expect(wrapper.find('Icon').at(4)).toHaveProp('color', gray.shark()); - expect(wrapper.find('Icon').at(4)).toHaveProp('onPress'); - expect(wrapper.find('Icon').at(5)).toHaveProp('name', 'corner-up-right'); - expect(wrapper.find('Icon').at(5)).toHaveProp('size', 15); - expect(wrapper.find('Icon').at(5)).toHaveProp('color', gray.shark()); - expect(wrapper.find('Icon').at(6)).toHaveStyle(styles.commentsBarIcon); - expect(wrapper.find('Icon').at(6)).toHaveProp('name', 'triangle-right'); - expect(wrapper.find('Icon').at(6)).toHaveProp('size', 15); - expect(wrapper.find('Icon').at(6)).toHaveProp('color', gray.shark()); }); }); diff --git a/package.json b/package.json index 91d300e..4f70479 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "ios": "react-native run-ios", "web": "expo start --web", "start": "react-native start", - "test": "jest --all --no-watchman", + "test": "jest", "coverage": "rm -rf coverage/ node_modules/.cache/ && NODE_ENV=test npx jest --collect-coverage", "lint": "eslint .", "lint-fix": "eslint . --fix", diff --git a/src/screen/forum/components/NewTopic.js b/src/screen/forum/components/NewTopic.js index 0bb0544..3dfcbab 100644 --- a/src/screen/forum/components/NewTopic.js +++ b/src/screen/forum/components/NewTopic.js @@ -25,7 +25,14 @@ export default function NewTopic({ navigation, topTopic }) { {item?.createdAt} - + + + {item?.comments.length} + {item?.likes.length} diff --git a/src/screen/topic/TopicCreate.js b/src/screen/topic/TopicCreate.js index 7e857c0..f667f2f 100644 --- a/src/screen/topic/TopicCreate.js +++ b/src/screen/topic/TopicCreate.js @@ -34,10 +34,19 @@ export default function TopicCreate({ navigation }) { return ( - - - {plant?.scientificName} - + navigation.push('PlantCard', { itemID: plantID })} + > + + + {plant?.scientificName} + + postTopic()} diff --git a/src/screen/topic/TopicView.js b/src/screen/topic/TopicView.js index 6e4e3b6..3e69445 100644 --- a/src/screen/topic/TopicView.js +++ b/src/screen/topic/TopicView.js @@ -27,15 +27,18 @@ import { gray, highlight } from '../../theme/colorPalette'; function Data({ time }) { const now = new Date(); - const action = new Date(time); - const tmp = Math.trunc((now - action) / 1000 / 60); + const tmp = Math.trunc((now - time) / 1000 / 60); if (tmp / 60 > 24) { - return {tmp / 24} dias atrás; + return ( + {Math.trunc(tmp / 24)} dias atrás + ); } if (tmp / 3600 > 24) { - return {tmp / 24} horas atrás; + return ( + {Math.trunc(tmp / 60)} horas atrás + ); } - return {tmp} minutos atrás; + return {Math.trunc(tmp)} minutos atrás; } export default function TopicView({ navigation }) { @@ -45,7 +48,7 @@ export default function TopicView({ navigation }) { const [topic, setTopic] = useState({}); const [isNewComment, setIsNewComment] = useState(true); const [isEditing, setIsEditing] = useState(false); - const [isEditable, setIsEditable] = useState(true); + const [isEditable, setIsEditable] = useState(false); const [commentText, setCommentText] = useState(''); const [topicIsLiked, setTopicIsLiked] = useState(false); const [topicIsNotLiked, setTopicIsNotLiked] = useState(false); @@ -157,7 +160,7 @@ export default function TopicView({ navigation }) { /> {topic?.user?.username} - + diff --git a/src/screen/topic/comment/Comments.js b/src/screen/topic/comment/Comments.js index 6b7bd85..df98af2 100644 --- a/src/screen/topic/comment/Comments.js +++ b/src/screen/topic/comment/Comments.js @@ -52,7 +52,9 @@ export default function Comments({ topic, setTopic, user, like, dislike }) { {username} {topicEditing !== id ? ( - {description} + + {description} + ) : ( dislike('comment', id)} /> - {user?._id === userID && ( + {!!(user?._id === userID) && ( <> - - - - + + {title} - + + ); } @@ -30,6 +23,11 @@ const styles = StyleSheet.create({ alignContent: 'space-between', paddingTop: 15, }, + headerNav: { + flex: 0.8, + flexDirection: 'row', + alignItems: 'center', + }, publicarDiv: { flexDirection: 'row', alignItems: 'center', diff --git a/src/services/endpoints/topic.js b/src/services/endpoints/topic.js index afc62bf..2287bc4 100644 --- a/src/services/endpoints/topic.js +++ b/src/services/endpoints/topic.js @@ -18,6 +18,18 @@ export const createTopic = async (topicID, topicBody) => { }); }; +export const topTopic = () => { + const TOPIC = ENDPOINTS.API.topic; + return new Promise((resolve, reject) => { + fetch(ENDPOINTS.API.base_url + TOPIC.listTop.route, { + method: TOPIC.listTop.method, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); +}; + export const getTopic = (topicID) => { const TOPIC = ENDPOINTS.API.topic; return new Promise((resolve, reject) => { diff --git a/src/settings/endpoints.js b/src/settings/endpoints.js index 7a0895e..1b4f6b7 100644 --- a/src/settings/endpoints.js +++ b/src/settings/endpoints.js @@ -87,6 +87,10 @@ const ENDPOINTS = { route: (topicID) => `/topic/find/${topicID}`, method: 'GET', }, + listTop: { + route: `/topic/list`, + method: 'GET', + }, create: { route: (plantID) => `/topic/create/${plantID}`, method: 'POST',