Skip to content
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
8 changes: 0 additions & 8 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Deploy to Vercel (Staging)
if: github.ref == 'refs/heads/staging'
run: npx vercel --prod --yes --token=${{ secrets.VERCEL_STAGING_TOKEN }}

- name: Deploy to Vercel (Production)
if: github.ref == 'refs/heads/main'
run: npx vercel --prod --yes --token=${{ secrets.VERCEL_MAIN_TOKEN }}

- name: Notify Slack that tests passed
if: success()
env:
Expand Down
33 changes: 32 additions & 1 deletion __tests__/components/FindHelpEntry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,36 @@ describe('FindHelpEntry', () => {
await waitFor(() => {
expect(alertSpy).toHaveBeenCalledWith(expect.stringMatching(/something went wrong/i));
});
});
});

it('uses browser geolocation when available', async () => {
const mockGetCurrentPosition = jest.fn((success) => {
success({ coords: { latitude: 10, longitude: 20 } });
});
Object.defineProperty(global.navigator, 'geolocation', {
value: { getCurrentPosition: mockGetCurrentPosition },
configurable: true,
});

renderWithProvider(<FindHelpEntry organisation={mockOrgWithNoServices} />);

await waitFor(() => {
expect(mockGetCurrentPosition).toHaveBeenCalled();
expect(screen.getByText(/location set/i)).toBeInTheDocument();
});
});

it('shows postcode form when geolocation fails', async () => {
const mockGetCurrentPosition = jest.fn((_s, error) => error());
Object.defineProperty(global.navigator, 'geolocation', {
value: { getCurrentPosition: mockGetCurrentPosition },
configurable: true,
});

renderWithProvider(<FindHelpEntry organisation={mockOrgWithNoServices} />);

await waitFor(() => {
expect(screen.getByLabelText(/enter your postcode/i)).toBeInTheDocument();
});
});
});
54 changes: 54 additions & 0 deletions __tests__/contexts/LocationContext.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import React from 'react';
import { LocationProvider, useLocation } from '@/contexts/LocationContext';

function Consumer() {
const { location, setLocation, requestLocation } = useLocation();
return (
<div>
<span data-testid="loc">{location ? JSON.stringify(location) : 'null'}</span>
<button onClick={() => setLocation({ lat: 1, lng: 2 })}>set</button>
<button onClick={requestLocation}>request</button>
</div>
);
}

describe('LocationContext', () => {
it('throws if useLocation is used outside provider', () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
expect(() => render(<Consumer />)).toThrow('useLocation must be used within a LocationProvider');
(console.error as jest.Mock).mockRestore();
});

it('updates location via setLocation', () => {
render(
<LocationProvider>
<Consumer />
</LocationProvider>
);
fireEvent.click(screen.getByText('set'));
expect(screen.getByTestId('loc').textContent).toBe('{"lat":1,"lng":2}');
});

it('requests location using geolocation API', async () => {
const mockGetCurrentPosition = jest.fn((success) => {
success({ coords: { latitude: 3, longitude: 4 } });
});
Object.defineProperty(global.navigator, 'geolocation', {
value: { getCurrentPosition: mockGetCurrentPosition },
configurable: true,
});

render(
<LocationProvider>
<Consumer />
</LocationProvider>
);

fireEvent.click(screen.getByText('request'));

await waitFor(() => {
expect(screen.getByTestId('loc').textContent).toBe('{"lat":3,"lng":4}');
});
});
});
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function Home() {
{[
{ title: 'Instant Updates', desc: 'Stay informed with live alerts and notifications.' },
{ title: 'Community Map', desc: 'Visualise nearby resources and support hubs.' },
{ title: 'Volunteer Hub', desc: 'Connect with volunteers in your area.' }
{ title: 'Volunteer Hub', desc: 'Connect with volunteers in your local area.' }
].map((feature) => (
<div
key={feature.title}
Expand Down
5 changes: 0 additions & 5 deletions vercel.json

This file was deleted.

Loading