Skip to content

Commit bb31357

Browse files
committed
userActions integration update profile PASS
1 parent be5991b commit bb31357

File tree

4 files changed

+153
-63
lines changed

4 files changed

+153
-63
lines changed

SmartClothingApp/__test__/__integration-test__/__main-tab-test__/__main-navigation-test/HomeToProfile.test.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -162,41 +162,41 @@ describe('Home to Profile Navigation', () => {
162162
it('Navigates from main Profile Screen to Edit Personal Info Screen', async () => {
163163
store = configureStore();
164164

165-
const { getByText, getAllByText } = render(
166-
<StoreProvider store={store}>
167-
<PaperProvider>
168-
<TestComponent2 />
169-
</PaperProvider>
170-
</StoreProvider>
171-
);
172-
173-
const editPersonalTextElement = getByText('Edit Profile');
174-
const editPersonalView = editPersonalTextElement.parent || editPersonalTextElement;
175-
176-
await act(() => {
177-
fireEvent.press(editPersonalView);
178-
});
179-
180-
const editFirstNameElements = getAllByText('First Name');
181-
const editLastNameElements = getAllByText('Last Name');
182-
183-
await waitFor(() => {
184-
expect(editFirstNameElements[0]).toBeTruthy();
185-
});
186-
await waitFor(() => {
187-
expect(editLastNameElements[0]).toBeTruthy();
188-
});
165+
const { getByText, getAllByText } = render(
166+
<StoreProvider store={store}>
167+
<PaperProvider>
168+
<TestComponent2 />
169+
</PaperProvider>
170+
</StoreProvider>
171+
);
172+
173+
const editPersonalTextElement = getByText('Edit Profile');
174+
const editPersonalView = editPersonalTextElement.parent || editPersonalTextElement;
175+
176+
await act(() => {
177+
fireEvent.press(editPersonalView);
178+
});
179+
180+
const editFirstNameElements = getAllByText('First Name');
181+
const editLastNameElements = getAllByText('Last Name');
182+
183+
await waitFor(() => {
184+
expect(editFirstNameElements[0]).toBeTruthy();
185+
});
186+
await waitFor(() => {
187+
expect(editLastNameElements[0]).toBeTruthy();
188+
});
189189
});
190190

191191
it('Navigates from main Profile Screen to Metrics Data Screen', async () => {
192192
store = configureStore();
193193

194194
const { getByText, getAllByText } = render(
195-
<StoreProvider store={store}>
195+
<StoreProvider store={store}>
196196
<PaperProvider>
197197
<TestComponent2 />
198198
</PaperProvider>
199-
</StoreProvider>
199+
</StoreProvider>
200200
);
201201

202202
const editMetricsTextElement = getByText('Edit Profile');

SmartClothingApp/__test__/__integration-test__/userActions.integration.test.js

+119-36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import configureMockStore from 'redux-mock-store';
1515
import thunk from 'redux-thunk';
1616
import App from '../../App'; // Assuming App is the root component
1717
import AppHeader from '../../src/components/AppHeader';
18+
import ProfileScreen from '../../src/screens/Profile';
1819

1920
import AppTheme from '../../src/constants/themes';
2021

@@ -32,6 +33,7 @@ const mockStore = configureMockStore(middlewares);
3233
jest.mock('../../src/utils/localStorage.js', () => ({
3334
AsyncStorage: jest.fn(),
3435
storeUID: jest.fn(),
36+
getUID: jest.fn(),
3537
}));
3638

3739
jest.mock('../../firebaseConfig', () => ({
@@ -43,6 +45,15 @@ jest.mock('../../firebaseConfig', () => ({
4345
},
4446
}));
4547

48+
jest.mock('../../firebaseConfig', () => ({
49+
auth: {
50+
signOut: jest.fn(() => Promise.resolve()),
51+
currentUser: {
52+
displayName: 'John Doe',
53+
},
54+
}
55+
}));
56+
4657
jest.mock('firebase/auth', () => ({
4758
createUserWithEmailAndPassword: jest.fn(),
4859
updateEmail: jest.fn(),
@@ -65,20 +76,7 @@ jest.mock('firebase/firestore', () => ({
6576
setDoc: jest.fn(),
6677
doc: jest.fn(() => ({ setDoc: jest.fn() })),
6778
updateDoc: jest.fn(),
68-
getDoc: jest.fn().mockReturnValue({
69-
exists: jest.fn().mockReturnValue(true), // Mock 'exists' as a function
70-
data: jest.fn().mockReturnValue({
71-
height: "6541",
72-
weight: "55",
73-
age: "666",
74-
gender: "male",
75-
sports: "running",
76-
dob: {
77-
seconds: 1627852800, // Example timestamp for July 2, 2021
78-
nanoseconds: 0, // Firestore Timestamps include nanoseconds, but it's often okay to mock them as 0 in tests
79-
},
80-
}), // Mock 'data' as a function
81-
}),
79+
getDoc: jest.fn(),
8280
}));
8381

8482

@@ -104,14 +102,6 @@ jest.mock('victory-native', () => {
104102
useChartPressState: MockUseChartPressState,
105103
};
106104
});
107-
// jest.mock('../../src/actions/appActions', () => ({
108-
// userMetricsDataModalVisible: jest.fn().mockReturnValue({
109-
// type: 'USER_METRICS_DATA_MODAL_VISIBLE',
110-
// payload: {
111-
// visibility: false,
112-
// isFromSignUpScreen: false,
113-
// }}),
114-
// }));
115105

116106
// Mocks ViewSleepData
117107
jest.mock('d3', () => ({
@@ -138,36 +128,51 @@ jest.mock('@react-navigation/native', () => {
138128
goBack: jest.fn(),
139129
}),
140130
useRoute: () => ({
141-
name: 'Previous Screen',
131+
//name: 'Previous Screen',
132+
params: {
133+
previousScreenTitle: 'Home',
134+
},
142135
}),
143136
};
144137
});
145138

146139

147140

148141

149-
const initialState = {
150-
auth: {
151-
uid: '123',
152-
displayName: 'John Doe',
153-
},
154-
user: {
155-
profile: {},
156-
metrics: {},
157-
},
158-
};
142+
143+
159144

160145
describe('User Actions Integration Test', () => {
161146
let store;
162147

163148
beforeEach(() => {
164-
store = mockStore(initialState);
149+
jest.spyOn(console, 'error').mockImplementation((message) => {
150+
if (message.includes('Warning: An update to')) {
151+
return;
152+
}
153+
console.error(message);
154+
});
155+
156+
jest.useFakeTimers();
157+
165158
});
166159

167160
it('should log out the user', async () => {
161+
const initialState = {
162+
auth: {
163+
uid: '123',
164+
displayName: 'John Doe',
165+
},
166+
user: {
167+
profile: {},
168+
metrics: {},
169+
},
170+
};
171+
172+
store = mockStore(initialState);
168173
store.dispatch = jest.fn(store.dispatch);
169174

170-
const { getByTestId, queryByText, getAllByTestId, getByText, getAllByRole, debug } = render(
175+
const { getByTestId, queryByText, debug } = render(
171176
<Provider store={store}>
172177
<PaperProvider >
173178
<NavigationContainer>
@@ -179,7 +184,7 @@ describe('User Actions Integration Test', () => {
179184
</Provider>
180185
);
181186

182-
debug(); // Log the rendered output to inspect the component tree
187+
// debug(); // Log the rendered output to inspect the component tree
183188

184189
const menuButton = getByTestId("menu-action");
185190

@@ -215,6 +220,84 @@ describe('User Actions Integration Test', () => {
215220
});
216221
});
217222

223+
224+
it('should update the user profile', async () => {
225+
store.dispatch = jest.fn(store.dispatch);
226+
227+
const initialState = {
228+
uuid: null,
229+
firstName: null,
230+
lastName: null,
231+
email: null,
232+
authError: null,
233+
user: {
234+
userMetricsData: {
235+
gender: "No Data",
236+
dob: new Date(),
237+
height: "No Data",
238+
weight: "No Data",
239+
sports: "No Data",
240+
},
241+
}
242+
};
243+
244+
store = mockStore(initialState);
245+
store.dispatch = jest.fn(store.dispatch);
246+
247+
const { getByTestId, queryByText, debug } = render(
248+
<Provider store={store}>
249+
<PaperProvider >
250+
<NavigationContainer>
251+
<View>
252+
<ProfileScreen route={{ params: { previousScreenTitle: 'Home' } }}/>
253+
</View>
254+
</NavigationContainer>
255+
</PaperProvider>
256+
</Provider>
257+
);
258+
259+
debug();
260+
261+
const editPersonalButton = getByTestId("edit-personal-button");
262+
await act(() => {
263+
fireEvent.press(editPersonalButton );
264+
});
265+
266+
await waitFor(() => {
267+
expect(getByTestId("personal-modal-content")).not.toBeNull();
268+
});
269+
270+
const firstNameInput = getByTestId("first-name-input");
271+
await act(() => {
272+
fireEvent.changeText(firstNameInput, 'John');
273+
});
274+
275+
const lastNameInput = getByTestId("last-name-input");
276+
await act(() => {
277+
fireEvent.changeText(lastNameInput, 'Doe');
278+
});
279+
280+
let savePersonalButton
281+
await waitFor(() => {
282+
savePersonalButton = getByTestId("save-personal-button");
283+
});
284+
await act(() => {
285+
fireEvent.press(savePersonalButton );
286+
});
287+
288+
//const lastNadfameInput = getByTestId("last-ndfasdfasdame-input");
289+
290+
await waitFor(() => {
291+
expect(store.dispatch).toHaveBeenCalledWith(expect.any(Function));
292+
const actions = store.getActions();
293+
expect(actions).toContainEqual({
294+
type: 'UPDATE_PROFILE',
295+
payload: ['John', 'Doe'],
296+
});
297+
});
298+
});
299+
300+
218301
// it('should update the user profile', async () => {
219302
// store.dispatch = jest.fn(store.dispatch);
220303

SmartClothingApp/src/components/PersonalModal/PersonalModal.jsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ const PersonalModal = (props) => {
6767
<View style={styles.container}>
6868
<Modal animationType="slide" transparent={true} visible={props.visible}>
6969
<View style={styles.modalBackground}>
70-
<View style={styles.modalContent}>
70+
<View
71+
style={styles.modalContent}
72+
testID="personal-modal-content"
73+
>
7174
<Text
7275
style={{ fontSize: 18, fontWeight: "bold", marginBottom: 20 }}
7376
numberOfLines={1}
@@ -85,6 +88,7 @@ const PersonalModal = (props) => {
8588
handleClearErrors();
8689
}}
8790
error={error.fname.length > 1}
91+
testID="first-name-input"
8892
/>
8993
<HelperText type="error" visible={error.fname.length > 1}>
9094
Please enter first name.
@@ -101,6 +105,7 @@ const PersonalModal = (props) => {
101105
handleClearErrors();
102106
}}
103107
error={error.lname.length > 1}
108+
testID="last-name-input"
104109
/>
105110
<HelperText type="error" visible={error.lname.length > 1}>
106111
Please enter last name.
@@ -126,6 +131,7 @@ const PersonalModal = (props) => {
126131
{ backgroundColor: isSubmitting ? "#ccc" : "#007bff" },
127132
]}
128133
textColor="white"
134+
testID="save-personal-button"
129135
>
130136
Save
131137
</Button>

SmartClothingApp/src/screens/Profile/index.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const ProfileScreen = ({ navigation, route }) => {
114114
textColor="white"
115115
style={{ borderRadius: 10 }}
116116
onPress={openPersonalModal}
117+
testID="edit-personal-button"
117118
>
118119
EDIT
119120
</Button>

0 commit comments

Comments
 (0)