Skip to content

Commit

Permalink
feat(#10): account password reset (#57)
Browse files Browse the repository at this point in the history
chore: run format
  • Loading branch information
fredshema authored Oct 23, 2024
1 parent fd61cb2 commit 40d6b8d
Show file tree
Hide file tree
Showing 51 changed files with 5,995 additions and 1,568 deletions.
5 changes: 0 additions & 5 deletions AppManager.tsx

This file was deleted.

5 changes: 2 additions & 3 deletions __tests__/auth/login/OrgLogin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ describe('<OrgLogin />', () => {
expect(pulse_co).toBeTruthy();
expect(pulse_co.props.children).toBe('.pulse.co');

fireEvent.changeText(orgInput, 'MyOrganization');
fireEvent.changeText(orgInput, 'MyOrganization');
expect(orgInput.props.value).toBe('MyOrganization');

const expectedWidth = Math.min('MyOrganization'.length * 11, 200);
const expectedWidth = Math.min('MyOrganization'.length * 11, 200);
expect(orgInput.props.style.width).toBe(expectedWidth);

});

test('shows validation error if input is empty and submitted', async () => {
Expand Down
10 changes: 6 additions & 4 deletions __tests__/auth/login/UserLogin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ describe('UserLogin Component', () => {
fireEvent.changeText(getByPlaceholderText('Password'), 'ValidPassword');
fireEvent.press(getByText('Sign In'));

await waitFor(() => expect(mockOnSubmit).toHaveBeenCalledWith({
email: 'test@example.com',
password: 'ValidPassword',
}));
await waitFor(() =>
expect(mockOnSubmit).toHaveBeenCalledWith({
email: 'test@example.com',
password: 'ValidPassword',
})
);

expect(mockOnSubmit).toHaveBeenCalledTimes(1);
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/components/About_trainee.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ describe('AboutTrainee Component', () => {
expect(getByText('Available upon request.')).toBeTruthy();
expect(getByText('A passionate developer.')).toBeTruthy();
});
});
});
4 changes: 2 additions & 2 deletions __tests__/components/LanguagePicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import { I18nextProvider } from 'react-i18next';
import i18n from '@/internationalization';
import i18n from '@/internationalization';
import LanguagePicker from '@/components/LanguagePicker';

jest.mock('react-native/Libraries/Utilities/useColorScheme', () => ({
__esModule: true,
default: jest.fn(() => 'light'),
default: jest.fn(() => 'light'),
}));

describe('LanguagePicker', () => {
Expand Down
39 changes: 19 additions & 20 deletions __tests__/components/TraineeRatings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ describe('TraineeRatings Component', () => {
it('fetches user token from AsyncStorage', async () => {
const mockToken = 'mock-token';
AsyncStorage.getItem = jest.fn(() => Promise.resolve(mockToken));

render(<TraineeRatings />);

await waitFor(() => {
expect(AsyncStorage.getItem).toHaveBeenCalledWith('authToken');
});
});

it('alerts when token is not found', async () => {
AsyncStorage.getItem = jest.fn(() => Promise.resolve(null));
global.alert = jest.fn();

render(<TraineeRatings />);

await waitFor(() => {
expect(global.alert).toHaveBeenCalledWith('Error', 'User token not found.');
});
Expand All @@ -68,13 +68,13 @@ describe('TraineeRatings Component', () => {
request: { query: TRAINEE_RATING },
error: mockError,
};

const { getByText } = render(
<MockedProvider mocks={[mockErrorQuery]} addTypename={false}>
<TraineeRatings />
</MockedProvider>
);

await waitFor(() => {
expect(getByText('Error')).toBeTruthy();
});
Expand All @@ -85,9 +85,9 @@ describe('TraineeRatings Component', () => {
<TraineeRatings />
</MockedProvider>
);

fireEvent.changeText(getByPlaceholderText('Filter by Sprint'), '2');

await waitFor(() => {
const sprintFiltered = getAllByText(/Sprint 2/i);
expect(sprintFiltered.length).toBeGreaterThan(0);
Expand All @@ -99,9 +99,9 @@ describe('TraineeRatings Component', () => {
<TraineeRatings />
</MockedProvider>
);

fireEvent.press(getByText('Phase II'));

await waitFor(() => {
const phaseFiltered = getAllByText('Phase II');
expect(phaseFiltered.length).toBeGreaterThan(0);
Expand All @@ -113,7 +113,7 @@ describe('TraineeRatings Component', () => {
<TraineeRatings />
</MockedProvider>
);

await waitFor(() => {
expect(getByText('SPRINT')).toBeTruthy();
expect(getByText('QUANTITY')).toBeTruthy();
Expand All @@ -124,13 +124,13 @@ describe('TraineeRatings Component', () => {
request: { query: TRAINEE_RATING },
result: { data: { fetchRatingsTrainee: [] } },
};

const { getByText } = render(
<MockedProvider mocks={[emptyMockData]} addTypename={false}>
<TraineeRatings />
</MockedProvider>
);

await waitFor(() => {
expect(getByText('No Ratings Available')).toBeTruthy();
});
Expand All @@ -141,16 +141,16 @@ describe('TraineeRatings Component', () => {
<TraineeRatings />
</MockedProvider>
);

const viewButtons = getAllByText('View');
fireEvent.press(viewButtons[0]);

await waitFor(() => {
expect(getByText('From: Manager')).toBeTruthy();
expect(getByText('Feedback: Great performance')).toBeTruthy();
});
});

it('renders without errors and displays fetched data', async () => {
const { getByText, getByPlaceholderText } = render(
<MockedProvider mocks={[mockRatingsData]} addTypename={false}>
Expand Down Expand Up @@ -194,14 +194,13 @@ describe('TraineeRatings Component', () => {
<TraineeRatings />
</MockedProvider>
);

const viewButtons = await findAllByText('View'); // Async await find method
fireEvent.press(viewButtons[0]);

await waitFor(() => {
expect(getByText('From: Manager')).toBeTruthy();
expect(getByText('Feedback: Great performance')).toBeTruthy();
});
});

});
114 changes: 57 additions & 57 deletions __tests__/components/Trainee_org.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@ import { render } from '@testing-library/react-native';
import TraineeOrg from '../../components/trainee/Organisation';

describe('TraineeOrg Component', () => {
const profile = {
user: {
organizations: 'Andela',
role: 'Trainee',
team: {
cohort: {
program: {
name: 'Software Engineering',
},
name: 'Cohort 1',
phase: {
name: 'Phase 1',
},
},
name: 'Team A',
},
},
};
const profile = {
user: {
organizations: 'Andela',
role: 'Trainee',
team: {
cohort: {
program: {
name: 'Software Engineering',
},
name: 'Cohort 1',
phase: {
name: 'Phase 1',
},
},
name: 'Team A',
},
},
};

const pulse = '<svg></svg>';
const bgColor = 'bg-white';
const textColor = 'text-black';
const pulse = '<svg></svg>';
const bgColor = 'bg-white';
const textColor = 'text-black';

it('renders organization details correctly', () => {
const { getByText } = render(<TraineeOrg profile={profile} bgColor={bgColor} textColor={textColor} />);
it('renders organization details correctly', () => {
const { getByText } = render(
<TraineeOrg profile={profile} bgColor={bgColor} textColor={textColor} />
);

expect(getByText('YOUR ORGANISATION DETAILS')).toBeTruthy();
expect(getByText('Organisation Name:')).toBeTruthy();
expect(getByText('Andela')).toBeTruthy();
expect(getByText('Admin email:')).toBeTruthy();
expect(getByText('devpulse@proton.me')).toBeTruthy();
expect(getByText('Role:')).toBeTruthy();
expect(getByText('Trainee')).toBeTruthy();
});
expect(getByText('YOUR ORGANISATION DETAILS')).toBeTruthy();
expect(getByText('Organisation Name:')).toBeTruthy();
expect(getByText('Andela')).toBeTruthy();
expect(getByText('Admin email:')).toBeTruthy();
expect(getByText('devpulse@proton.me')).toBeTruthy();
expect(getByText('Role:')).toBeTruthy();
expect(getByText('Trainee')).toBeTruthy();
});

it('renders management details correctly', () => {
const { getByText } = render(<TraineeOrg profile={profile} bgColor={bgColor} textColor={textColor} />);
it('renders management details correctly', () => {
const { getByText } = render(
<TraineeOrg profile={profile} bgColor={bgColor} textColor={textColor} />
);

expect(getByText('MANAGEMENT')).toBeTruthy();
expect(getByText('Program:')).toBeTruthy();
expect(getByText('Software Engineering')).toBeTruthy();
expect(getByText('Cohort :')).toBeTruthy();
expect(getByText('Cohort 1')).toBeTruthy();
expect(getByText('Team:')).toBeTruthy();
expect(getByText('Team A')).toBeTruthy();
expect(getByText('Phase:')).toBeTruthy();
expect(getByText('Phase 1')).toBeTruthy();
});
it('renders unavailable text when data is missing', () => {
const emptyProfile = {};
const { getAllByText } = render(
<TraineeOrg
profile={emptyProfile}
bgColor="bg-white"
textColor="text-black"
/>
);

const unavailableElements = getAllByText('Unavailable');
expect(unavailableElements.length).toBe(6); // Adjust the expected count to match the actual rendered elements
});
});
expect(getByText('MANAGEMENT')).toBeTruthy();
expect(getByText('Program:')).toBeTruthy();
expect(getByText('Software Engineering')).toBeTruthy();
expect(getByText('Cohort :')).toBeTruthy();
expect(getByText('Cohort 1')).toBeTruthy();
expect(getByText('Team:')).toBeTruthy();
expect(getByText('Team A')).toBeTruthy();
expect(getByText('Phase:')).toBeTruthy();
expect(getByText('Phase 1')).toBeTruthy();
});
it('renders unavailable text when data is missing', () => {
const emptyProfile = {};
const { getAllByText } = render(
<TraineeOrg profile={emptyProfile} bgColor="bg-white" textColor="text-black" />
);

const unavailableElements = getAllByText('Unavailable');
expect(unavailableElements.length).toBe(6); // Adjust the expected count to match the actual rendered elements
});
});
1 change: 0 additions & 1 deletion __tests__/components/sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,4 @@ describe('Sidebar', () => {
expect(mockPush).toHaveBeenCalledWith('/auth/login');
});
});

});
34 changes: 23 additions & 11 deletions __tests__/dashboard/trainee/Profile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,25 @@ describe('<Profile />', () => {
render(<Profile />);

await waitFor(() => {
expect(showMock).toHaveBeenCalledWith('Token Not found.', { type: 'danger', placement: 'top', duration: 3000 });
expect(showMock).toHaveBeenCalledWith('Token Not found.', {
type: 'danger',
placement: 'top',
duration: 3000,
});
});
});

test('handles tab switching correctly', async () => {
mockUseQuery.mockReturnValue({
data: {
getProfile: {
avatar: 'https://example.com/avatar.png',
name: 'John Doe',
email: 'john.doe@example.com',
phoneNumber: '1234567890',
address: '123 Main St',
resume: 'https://example.com/resume.pdf',
biography: 'This is a biography.',
avatar: 'https://example.com/avatar.png',
name: 'John Doe',
email: 'john.doe@example.com',
phoneNumber: '1234567890',
address: '123 Main St',
resume: 'https://example.com/resume.pdf',
biography: 'This is a biography.',
},
},
loading: false,
Expand Down Expand Up @@ -136,7 +140,11 @@ describe('<Profile />', () => {
render(<Profile />);

await waitFor(() => {
expect(showMock).toHaveBeenCalledWith('Error fetching profile.', { type: 'danger', placement: 'top', duration: 3000 });
expect(showMock).toHaveBeenCalledWith('Error fetching profile.', {
type: 'danger',
placement: 'top',
duration: 3000,
});
});
});

Expand Down Expand Up @@ -176,7 +184,11 @@ describe('<Profile />', () => {
fireEvent.press(getByTestId('edit-button'));

await waitFor(() => {
expect(showMock).toHaveBeenCalledWith('Edit button pressed', { type: 'info', placement: 'top', duration: 3000 });
expect(showMock).toHaveBeenCalledWith('Edit button pressed', {
type: 'info',
placement: 'top',
duration: 3000,
});
});
});

Expand All @@ -200,4 +212,4 @@ describe('<Profile />', () => {
expect(getByText('John Doe')).toHaveStyle({ color: 'text-gray-100' });
});
});
});
});
Loading

0 comments on commit 40d6b8d

Please sign in to comment.