alessandro trinca tornidor commited on
Commit Β·
2ee94fb
1
Parent(s): 81f4ed8
test: add test cases for more components
Browse files- static/tests/MobileNavBar.test.ts +34 -0
- static/tests/NavBar.test.ts +37 -0
- static/tests/helpers.test.ts +67 -0
static/tests/MobileNavBar.test.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { describe, it, expect } from 'vitest'
|
| 2 |
+
import { shallowMount } from '@vue/test-utils'
|
| 3 |
+
import MobileNavBar from '@/components/NavBar/MobileNavBar.vue'
|
| 4 |
+
|
| 5 |
+
describe('MobileNavBar', () => {
|
| 6 |
+
it('renders a container div with bg-gray-200 class', () => {
|
| 7 |
+
const wrapper = shallowMount(MobileNavBar)
|
| 8 |
+
expect(wrapper.find('div.bg-gray-200').exists()).toBe(true)
|
| 9 |
+
})
|
| 10 |
+
|
| 11 |
+
it('renders exactly three TabComponent instances', () => {
|
| 12 |
+
const wrapper = shallowMount(MobileNavBar)
|
| 13 |
+
const tabs = wrapper.findAllComponents({ name: 'TabComponent' })
|
| 14 |
+
expect(tabs).toHaveLength(3)
|
| 15 |
+
})
|
| 16 |
+
|
| 17 |
+
it('passes correct hrefs to TabComponents', () => {
|
| 18 |
+
const wrapper = shallowMount(MobileNavBar)
|
| 19 |
+
const tabs = wrapper.findAllComponents({ name: 'TabComponent' })
|
| 20 |
+
expect(tabs[0].props('href')).toBe(
|
| 21 |
+
'https://trinca.tornidor.com/projects/samgis-segment-anything-applied-to-GIS'
|
| 22 |
+
)
|
| 23 |
+
expect(tabs[1].props('href')).toBe('https://trinca.tornidor.com/')
|
| 24 |
+
expect(tabs[2].props('href')).toBe('https://docs.trinca.tornidor.com/')
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
it('passes correct descriptions to TabComponents', () => {
|
| 28 |
+
const wrapper = shallowMount(MobileNavBar)
|
| 29 |
+
const tabs = wrapper.findAllComponents({ name: 'TabComponent' })
|
| 30 |
+
expect(tabs[0].props('description')).toBe('About SamGIS')
|
| 31 |
+
expect(tabs[1].props('description')).toBe('My blog')
|
| 32 |
+
expect(tabs[2].props('description')).toBe('SamGIS docs')
|
| 33 |
+
})
|
| 34 |
+
})
|
static/tests/NavBar.test.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { describe, it, expect } from 'vitest'
|
| 2 |
+
import { shallowMount } from '@vue/test-utils'
|
| 3 |
+
import NavBar from '@/components/NavBar/NavBar.vue'
|
| 4 |
+
|
| 5 |
+
describe('NavBar', () => {
|
| 6 |
+
it('renders a fixed-position container div', () => {
|
| 7 |
+
const wrapper = shallowMount(NavBar)
|
| 8 |
+
const div = wrapper.find('div.fixed')
|
| 9 |
+
expect(div.exists()).toBe(true)
|
| 10 |
+
expect(div.classes()).toContain('top-2')
|
| 11 |
+
expect(div.classes()).toContain('right-5')
|
| 12 |
+
})
|
| 13 |
+
|
| 14 |
+
it('renders exactly three TabComponent instances', () => {
|
| 15 |
+
const wrapper = shallowMount(NavBar)
|
| 16 |
+
const tabs = wrapper.findAllComponents({ name: 'TabComponent' })
|
| 17 |
+
expect(tabs).toHaveLength(3)
|
| 18 |
+
})
|
| 19 |
+
|
| 20 |
+
it('passes correct hrefs to TabComponents', () => {
|
| 21 |
+
const wrapper = shallowMount(NavBar)
|
| 22 |
+
const tabs = wrapper.findAllComponents({ name: 'TabComponent' })
|
| 23 |
+
expect(tabs[0].props('href')).toBe(
|
| 24 |
+
'https://trinca.tornidor.com/projects/samgis-segment-anything-applied-to-GIS'
|
| 25 |
+
)
|
| 26 |
+
expect(tabs[1].props('href')).toBe('https://trinca.tornidor.com/')
|
| 27 |
+
expect(tabs[2].props('href')).toBe('https://docs.ml-trinca.tornidor.com/')
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
it('passes correct descriptions to TabComponents', () => {
|
| 31 |
+
const wrapper = shallowMount(NavBar)
|
| 32 |
+
const tabs = wrapper.findAllComponents({ name: 'TabComponent' })
|
| 33 |
+
expect(tabs[0].props('description')).toBe('About SamGIS')
|
| 34 |
+
expect(tabs[1].props('description')).toBe('My blog')
|
| 35 |
+
expect(tabs[2].props('description')).toBe('SamGIS docs')
|
| 36 |
+
})
|
| 37 |
+
})
|
static/tests/helpers.test.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
| 12 |
updateZoomBboxMap,
|
| 13 |
getQueryParams,
|
| 14 |
getGeoJSONRequest,
|
|
|
|
| 15 |
} from '@/components/helpers'
|
| 16 |
import {
|
| 17 |
currentMapBBoxRef,
|
|
@@ -523,3 +524,69 @@ describe('getGeoJSONRequest', () => {
|
|
| 523 |
expect(result).toContain('SyntaxError')
|
| 524 |
})
|
| 525 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
updateZoomBboxMap,
|
| 13 |
getQueryParams,
|
| 14 |
getGeoJSONRequest,
|
| 15 |
+
getPopupContentPoint,
|
| 16 |
} from '@/components/helpers'
|
| 17 |
import {
|
| 18 |
currentMapBBoxRef,
|
|
|
|
| 524 |
expect(result).toContain('SyntaxError')
|
| 525 |
})
|
| 526 |
})
|
| 527 |
+
|
| 528 |
+
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 529 |
+
// getPopupContentPoint
|
| 530 |
+
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 531 |
+
describe('getPopupContentPoint', () => {
|
| 532 |
+
/**
|
| 533 |
+
* Builds an HTMLDivElement popup for a point marker.
|
| 534 |
+
* The event mock needs `layer._latlng` (for coordinates)
|
| 535 |
+
* and `layer._leaflet_id` (displayed in the popup text).
|
| 536 |
+
* jsdom provides full DOM APIs so we can assert on the returned element.
|
| 537 |
+
*/
|
| 538 |
+
|
| 539 |
+
const makePointEvent = (lat: number, lng: number, leafletId: number) => ({
|
| 540 |
+
layer: { _latlng: { lat, lng }, _leaflet_id: leafletId },
|
| 541 |
+
})
|
| 542 |
+
|
| 543 |
+
it('returns an HTMLDivElement', () => {
|
| 544 |
+
const event = makePointEvent(45.5, 9.2, 42)
|
| 545 |
+
const result = getPopupContentPoint(event, 1)
|
| 546 |
+
expect(result).toBeInstanceOf(HTMLDivElement)
|
| 547 |
+
})
|
| 548 |
+
|
| 549 |
+
it('outer div has class "leaflet-popup-content-inner"', () => {
|
| 550 |
+
const event = makePointEvent(45.5, 9.2, 42)
|
| 551 |
+
const result = getPopupContentPoint(event, 1)
|
| 552 |
+
expect(result.className).toBe('leaflet-popup-content-inner')
|
| 553 |
+
})
|
| 554 |
+
|
| 555 |
+
it('contains lat value from event', () => {
|
| 556 |
+
const event = makePointEvent(45.5, 9.2, 42)
|
| 557 |
+
const result = getPopupContentPoint(event, 1)
|
| 558 |
+
expect(result.textContent).toContain('lat:45.5')
|
| 559 |
+
})
|
| 560 |
+
|
| 561 |
+
it('contains lng value from event', () => {
|
| 562 |
+
const event = makePointEvent(45.5, 9.2, 42)
|
| 563 |
+
const result = getPopupContentPoint(event, 1)
|
| 564 |
+
expect(result.textContent).toContain('lng:9.2')
|
| 565 |
+
})
|
| 566 |
+
|
| 567 |
+
it('contains label value', () => {
|
| 568 |
+
const event = makePointEvent(45.5, 9.2, 42)
|
| 569 |
+
const result = getPopupContentPoint(event, 1)
|
| 570 |
+
expect(result.textContent).toContain('label:1')
|
| 571 |
+
})
|
| 572 |
+
|
| 573 |
+
it('contains leaflet id', () => {
|
| 574 |
+
const event = makePointEvent(45.5, 9.2, 42)
|
| 575 |
+
const result = getPopupContentPoint(event, 1)
|
| 576 |
+
expect(result.textContent).toContain('id:42')
|
| 577 |
+
})
|
| 578 |
+
|
| 579 |
+
it('works with label 0 (exclude) β falsy but valid', () => {
|
| 580 |
+
const event = makePointEvent(44.0, 8.0, 7)
|
| 581 |
+
const result = getPopupContentPoint(event, 0)
|
| 582 |
+
expect(result.textContent).toContain('label:0')
|
| 583 |
+
expect(result.textContent).toContain('id:7')
|
| 584 |
+
})
|
| 585 |
+
|
| 586 |
+
it('preserves decimal precision in coordinates', () => {
|
| 587 |
+
const event = makePointEvent(46.123456789, 9.987654321, 99)
|
| 588 |
+
const result = getPopupContentPoint(event, 1)
|
| 589 |
+
expect(result.textContent).toContain('lat:46.123456789')
|
| 590 |
+
expect(result.textContent).toContain('lng:9.987654321')
|
| 591 |
+
})
|
| 592 |
+
})
|