Improved the UX on Stations Page

This commit is contained in:
Eric Gullickson
2025-12-14 12:51:29 -06:00
parent 3852ec9f71
commit a9fc7741a6
9 changed files with 377 additions and 55 deletions

View File

@@ -8,6 +8,12 @@ import '@testing-library/jest-dom';
import { StationCard } from '../../components/StationCard';
import { Station } from '../../types/stations.types';
jest.mock('@/core/api/client', () => ({
apiClient: {
get: jest.fn(() => Promise.resolve({ data: new Blob(['photo'], { type: 'image/jpeg' }) }))
}
}));
const mockStation: Station = {
placeId: 'test-place-id',
name: 'Shell Gas Station',
@@ -23,6 +29,14 @@ describe('StationCard', () => {
beforeEach(() => {
jest.clearAllMocks();
window.open = jest.fn();
// JSDOM may not implement these; mock for blob URL handling
if (!global.URL.createObjectURL) {
global.URL.createObjectURL = jest.fn(() => 'blob:mock-url');
}
if (!global.URL.revokeObjectURL) {
global.URL.revokeObjectURL = jest.fn();
}
});
describe('Rendering', () => {
@@ -33,12 +47,12 @@ describe('StationCard', () => {
expect(screen.getByText('123 Main St, San Francisco, CA 94105')).toBeInTheDocument();
});
it('should render station photo if available', () => {
it('should render station photo if available', async () => {
render(<StationCard station={mockStation} isSaved={false} />);
const photo = screen.getByAltText('Shell Gas Station');
const photo = await screen.findByAltText('Shell Gas Station');
expect(photo).toBeInTheDocument();
expect(photo).toHaveAttribute('src', '/api/stations/photo/mock-photo-reference');
expect(photo).toHaveAttribute('src', expect.stringContaining('blob:'));
});
it('should render rating when available', () => {

View File

@@ -0,0 +1,34 @@
import { buildNavigationLinks } from '../../utils/navigation-links';
import { Station } from '../../types/stations.types';
const baseStation: Station = {
placeId: 'place-123',
name: 'Test Station',
address: '123 Main St, City',
latitude: 37.7749,
longitude: -122.4194,
rating: 4.2
};
describe('buildNavigationLinks', () => {
it('uses coordinates when valid', () => {
const links = buildNavigationLinks(baseStation);
expect(links.google).toContain('destination=37.7749,-122.4194');
expect(links.google).toContain('destination_place_id=place-123');
expect(links.apple).toContain('daddr=37.7749,-122.4194');
expect(links.waze).toContain('ll=37.7749,-122.4194');
});
it('falls back to query when coordinates are missing', () => {
const links = buildNavigationLinks({
...baseStation,
latitude: 0,
longitude: 0
});
expect(links.google).toContain('query=');
expect(links.apple).toContain('q=');
expect(links.waze).toContain('q=');
});
});