Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat card screen #291

Merged
merged 16 commits into from
May 30, 2024
Merged
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
139 changes: 103 additions & 36 deletions src/__tests__/components/ChatCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import React from "react";
import {render,fireEvent,waitFor } from "@testing-library/react-native";
import { ChatCard } from "../../components/ChartCard/ChatCard";

const mockNavigate = jest.fn();
jest.mock("@react-navigation/native", () => ({
useNavigation: () => ({
navigate: mockNavigate,
}),
}));


const post = {
description: "Test Description",
date: new Date(),
Expand All @@ -13,7 +21,11 @@ const post = {
userID: "user1",
activityCity: 'Mock City',
imageURL: 'sampleImageUrl',
// comments:comments
emoji: [{ emojiName: '😊', userID: 'user1', userFirstName: 'Erik', userLastName: 'Andersson' }],
comments : [
{ id: 1, comment: 'First comment', userID: 'user2', userFirstName: 'John', userLastName: 'Doe' },
{ id: 2, comment: 'Second comment', userID: 'user3', userFirstName: 'Erik', userLastName: 'Andersson' }
]
};

const loggedInUser = {
Expand All @@ -25,23 +37,30 @@ const loggedInUser = {
statusActive: true
};


describe("Testing ChatCardComponent", () => {

//TODO: add handleAddComment function when we add react function

it('Testing ChatCardDate component to ensure it renders with correct date', () => {
const { getByTestId } = render(
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
);
const chatCardDate = getByTestId('chat-card-date');
expect(chatCardDate).toBeTruthy();
expect(chatCardDate.props.children).toEqual('Today');
});

test('Testing ChatCardDate component to ensure it renders with correct date', () => {

it('Testing ChatCardDate component to ensure it renders with correct date', () => {
const { getByTestId } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
);
const chatCardDate = getByTestId('chat-card-date');
expect(chatCardDate).toBeTruthy();
expect(chatCardDate.props.children).toEqual('Today');
});

test('Testing ChatCardHeadercomponent to ensure it renders with correct data', () => {
it('Testing ChatCardHeadercomponent to ensure it renders with correct data', () => {
const { getByTestId, getByText } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
);
const chatCardHeader = getByTestId('chat-card-header');
expect(chatCardHeader).toBeTruthy();
Expand All @@ -52,26 +71,26 @@ describe("Testing ChatCardComponent", () => {
expect(activityImage.props.source.testUri).toBe( "../../../assets/images/activities/symbol_sport.png" )
});

test('Testing ChatCardImage component to ensure it renders with correct data', () => {
it('Testing ChatCardImage component to ensure it renders with correct data', () => {
const { getByTestId } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser}/>
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser}/>
);
const chatCardImage = getByTestId('chat-card-image');
expect(chatCardImage).toBeTruthy();
expect(chatCardImage.props.source.uri).toBe(post.imageURL);
});

test('Testing ChatCardDescription component to ensure it renders with correct data', () => {
it('Testing ChatCardDescription component to ensure it renders with correct data', () => {
const {getByText } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
);
expect(getByText('Test Description')).toBeTruthy();
});

test('Testing ChatCardEditMenu component is rendered', () => {
it('Testing ChatCardEditMenu component is rendered', () => {
const onDeleteMock = jest.fn();
const { getByTestId,getByText } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={onDeleteMock} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
<ChatCard post={post} onDelete={onDeleteMock} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
);
const chatCardEditMenu = getByTestId('chat-card-edit-menu');
expect(chatCardEditMenu).toBeTruthy();
Expand All @@ -81,42 +100,90 @@ describe("Testing ChatCardComponent", () => {
expect(onDeleteMock).toBeTruthy();
});

test('Testing ChatCard does not render ChatCardEditMenu when isCurrentUser is false', () => {
it('Testing ChatCard does not render ChatCardEditMenu when isCurrentUser is false', () => {
const { queryByTestId } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={!loggedInUser} />
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={!loggedInUser} />
);
const chatCardEditMenu = queryByTestId('chat-card-edit-menu');
expect(chatCardEditMenu).toBeFalsy();
});

test('Testing ChatCard component touchability', () => {
it('Testing ChatCard component touchability', () => {
const { getByTestId } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
<ChatCard post={post} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
);
const chatCard= getByTestId('chat-card');
fireEvent.press(chatCard);
});

test('Testing ChatCardEmoji component to ensure it renders ', () => {
it('Rendering ChatCard with ChatCardEmoji', () => {
const { getByTestId } = render(
<ChatCard post={post} handleAddComment={() => {}} onDelete={() => {}} addEmoji={() => {}} deleteEmoji={() => {}} loggedInUser={loggedInUser} />
<ChatCard
post={post}
onDelete={() => {}}
addEmoji={() => {}}
deleteEmoji={() => {}}
loggedInUser={loggedInUser}
commentsCount={0}
/>
);
const chatCardDate = getByTestId('chat-card-date');
expect(chatCardDate).toBeTruthy();

const chatCardEmoji = getByTestId('chat-card-emoji');
expect(chatCardEmoji).toBeTruthy();
});

it('Adding Emoji in ChatCardEmoji', () => {
const addEmojiMock = jest.fn();
const deleteEmojiMock = jest.fn();
const { getByTestId,getByText } = render(
<ChatCard
post={post}
onDelete={() => {}}
addEmoji={addEmojiMock}
deleteEmoji={() => {}}
loggedInUser={loggedInUser}
commentsCount={0}
/>
);

const chatCardEmoji = getByTestId('chat-card-emoji');
fireEvent.press(chatCardEmoji);
expect(addEmojiMock).toBeTruthy();
expect(getByText('😊')).toBeTruthy();
});

it('Deleting Emoji in ChatCardEmoji', () => {
const deleteEmojiMock = jest.fn();
const addEmojiMock = jest.fn();

// ToDo adapt test after creating a new ChatCardScreen and also write test for ChatCardEmoji
// test('Testing CommentsSection component to ensure it renders data correctly', async() => {
// const { getAllByTestId,getByText,debug} = render(
// <ChatCard post={post} users={users} handleAddComment={() => {}} />
// );
// await waitFor(() => {
// const commentsSection = getAllByTestId('comment-user-name');
// const commentsList = getAllByTestId('comment-text');
// debug();
// expect(commentsSection[0].props.children).toBe('Erik Andersson');
// expect(commentsList[0].props.children).toBe('First comment');
// })
// });
const { getByText,queryByText } = render(
<ChatCard
post={post}
onDelete={() => {}}
addEmoji={addEmojiMock}
deleteEmoji={deleteEmojiMock}
loggedInUser={loggedInUser}
commentsCount={post.comments.length}
/>
);

const emojiText = getByText('😊');
fireEvent.press(emojiText);
expect(deleteEmojiMock).toHaveBeenCalled();
expect(queryByText('😊')).toBeNull();
});

it('Testing comments count in ChatCard', () => {
const { getByText } = render(
<ChatCard
post={post}
onDelete={() => {}}
addEmoji={() => {}}
deleteEmoji={() => {}}
loggedInUser={loggedInUser}
commentsCount={post.comments.length}
/>
);
const commentsCountText = getByText("2 Kommentarer");
expect(commentsCountText).toBeTruthy();
});
});
20 changes: 20 additions & 0 deletions src/assets/icons/ArrowUpward.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Icon } from "@rneui/base";
import { TextStyle, TouchableOpacity, ViewStyle } from "react-native";

type Props = {
onPress?: () => void;
style?: ViewStyle | TextStyle | undefined;
};

export const ArrowUpward = ({ onPress, style }: Props) => {
return (
<TouchableOpacity onPress={() => onPress && onPress()}>
<Icon
style={style}
testID={'arrow-upward'}
color="#5B6770"
name="arrow-upward" size={20}
/>
</TouchableOpacity>
);
};
1 change: 1 addition & 0 deletions src/components/Buttons/GoBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const GoBackButton = ({ onPress, style, text = true }: Props) => {
const styles = StyleSheet.create({
container: {
flexDirection: "row",
marginVertical:6
},
textGoBackButton: {
marginLeft: 10,
Expand Down
36 changes: 33 additions & 3 deletions src/components/ChartCard/ActivityListOverLay.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useState } from "react";
import React from "react";
import {
View,
StyleSheet,
Text,
Image,
ScrollView,
TouchableOpacity,
} from "react-native";
Expand All @@ -12,6 +11,7 @@ import { ActivityItem } from "./ActivityItem";
import { Overlay } from "@rneui/base";
import colors from "../../assets/theme/colors";
import typography from "../../assets/theme/typography";
import { UserStack } from "../../utility/routeEnums";

const createPropsObject = (activity: Activity, user: User): UserPost => {
let obj = {
Expand Down Expand Up @@ -40,16 +40,26 @@ type Props = {
onActivityPress: (post: UserPost) => void;
onBackdropPress: () => void;
user: User;
navigation: any;
};

export const ActivityListOverLay = ({
activities,
activities = [],
onActivityPress,
visible,
user,
onBackdropPress,
navigation
}: Props) => {

const handleNoActivityPress = () => {
navigation.navigate(UserStack.AddOrEditPost, {
post: { userFirstName: user.firstName,
userLastName: user.lastName,description: '', userID: user.id, activityID: null},
toEdit: false,
});
onBackdropPress();
};

return (
<Overlay
Expand All @@ -63,6 +73,15 @@ export const ActivityListOverLay = ({
<Text style={styles.header}>
Vilken aktivitet vill du berätta om?
</Text>
<TouchableOpacity
onPress={handleNoActivityPress}
style={styles.noActivityContainer}
>
<Text style={styles.noActivityText}>Ingen aktivitet</Text>
</TouchableOpacity>
<Text style={styles.header}>
Välj från dina aktiviteter.
</Text>
{activities.map((activity, index) => (
<TouchableOpacity
onPress={() => onActivityPress(createPropsObject(activity, user))}
Expand Down Expand Up @@ -99,4 +118,15 @@ const styles = StyleSheet.create({
width: "90%",
maxHeight: "60%",
},
noActivityContainer: {
marginBottom: 10,
backgroundColor: colors.background,
padding: 10,
borderRadius: 5,
alignItems: 'center',
},
noActivityText: {
...typography.cardTitle,
color: colors.dark
},
});
Loading
Loading