Spaces:
Sleeping
Sleeping
File size: 1,551 Bytes
cd99321 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import { describe, it, expect } from 'vitest'
import { isGoogleMapsUrl } from './PlaceFormModal.helpers'
describe('isGoogleMapsUrl', () => {
it('accepts the short share hosts', () => {
expect(isGoogleMapsUrl('https://maps.app.goo.gl/abc123')).toBe(true)
expect(isGoogleMapsUrl('https://goo.gl/maps/xyz')).toBe(true)
})
it('rejects goo.gl links that are not /maps', () => {
expect(isGoogleMapsUrl('https://goo.gl/something')).toBe(false)
})
it('accepts maps.google.<tld> and maps.google.<sld>.<tld>', () => {
expect(isGoogleMapsUrl('https://maps.google.com/?q=eiffel')).toBe(true)
expect(isGoogleMapsUrl('https://maps.google.co.uk/?q=eiffel')).toBe(true)
})
it('accepts google.<tld>/maps with optional www', () => {
expect(isGoogleMapsUrl('https://google.com/maps/place/Eiffel')).toBe(true)
expect(isGoogleMapsUrl('https://www.google.co.uk/maps')).toBe(true)
})
it('rejects google.<tld> without a /maps path', () => {
expect(isGoogleMapsUrl('https://google.com/search?q=eiffel')).toBe(false)
})
it('rejects spoofed hosts like maps.google.evil.com', () => {
expect(isGoogleMapsUrl('https://maps.google.evil.com/maps')).toBe(false)
})
it('returns false for non-URL input', () => {
expect(isGoogleMapsUrl('not a url')).toBe(false)
expect(isGoogleMapsUrl('')).toBe(false)
expect(isGoogleMapsUrl('Eiffel Tower')).toBe(false)
})
it('trims surrounding whitespace before parsing', () => {
expect(isGoogleMapsUrl(' https://maps.app.goo.gl/abc123 ')).toBe(true)
})
})
|