Skip to content

Commit

Permalink
test(pages): CreateAppointment
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtesch9 committed Jul 15, 2020
1 parent 748fd6d commit 3e3c838
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions mobile/src/__tests__/pages/CreateAppointment.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jest.mock('../../hooks/auth', () => ({
}),
}));

jest.mock('react-native/Libraries/Utilities/Platform', () => ({
OS: 'android',
select: () => null,
}));

const mockApi = new MockAdapter(api);

type MockResponse = [string, string, number, any?];
Expand Down Expand Up @@ -383,6 +388,82 @@ describe('CreateAppointment page', () => {
});
});

it('should not display DatePicker automatically on android', async () => {
const hourStart = 8;

const eachHourArray = Array.from(
{ length: 10 },
(_, index) => index + hourStart,
);

const availability = eachHourArray.map(hour => {
return {
hour,
available: true,
};
});

const providers = [
{
id: 'provider-id-1',
name: 'provider-name-1',
avatar_url: 'provider-1-avatar.png',
},
{
id: 'provider-id-2',
name: 'provider-name-2',
avatar_url: 'provider-2-avatar.png',
},
];

mockApi
.onGet('providers')
.reply(200, providers)
.onGet('providers/provider-id-1/day-availability')
.reply(200, availability);

mockApi.onPost('/appointments').reply(200);

const { getByText, getByTestId, queryByTestId } = render(
<CreateAppointment />,
);

await waitFor(() => {
expect(getByText('Cabeleireiros')).toBeTruthy();
});

expect(getByTestId('provider-provider-id-1-container')).toHaveStyle({
backgroundColor: '#ff9000',
});

const sixteenHourContainer = getByTestId('afternoon-hour-container-16');

fireEvent.press(sixteenHourContainer);

expect(sixteenHourContainer.props.selected).toBeTruthy();
expect(sixteenHourContainer).toHaveStyle({ backgroundColor: '#ff9000' });

expect(queryByTestId('date-picker')).toBeNull();

const bookAppointmentButton = getByText('Agendar');

fireEvent.press(bookAppointmentButton);

await waitFor(() => {
expect(mockReset).toHaveBeenCalledWith(
expect.objectContaining({
routes: [
{
name: 'AppointmentCreated',
params: { date: expect.any(Number) },
},
],
index: 0,
}),
);
});
});

it('should display an error if create appointment fails', async () => {
const spyAlert = jest.spyOn(Alert, 'alert');

Expand Down

0 comments on commit 3e3c838

Please sign in to comment.