Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronitjadhav committed Apr 10, 2024
1 parent 6b13d4a commit 8baab12
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
26 changes: 24 additions & 2 deletions libs/feature/map/src/lib/map-context/map-context.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ jest.mock('@camptocamp/ogc-client', () => ({
})
}
},
WfsEndpoint: class {
constructor(private url) {}
isReady() {
return Promise.resolve({
getLayerByName: (name) => {
if (this.url.indexOf('error') > -1) {
throw new Error('Something went wrong')
}
return {
name,
latLonBoundingBox: [1.33, 48.81, 4.3, 51.1],
}
},
getSingleFeatureTypeName: () => {
return 'ms:commune_actuelle_3857'
},
getFeatureUrl: () => {
return 'https://www.geograndest.fr/geoserver/region-grand-est/ows?service=WFS&version=1.1.0&request=GetFeature&outputFormat=application%2Fjson&typename=ms%3Acommune_actuelle_3857&srsname=EPSG%3A3857&bbox=10%2C20%2C30%2C40%2CEPSG%3A3857&maxFeatures=10000'
},
})
}
},
}))

describe('MapContextService', () => {
Expand Down Expand Up @@ -130,7 +152,7 @@ describe('MapContextService', () => {
const urls = source.getUrls()
expect(urls.length).toBe(1)
expect(urls[0]).toBe(
'https://www.geograndest.fr/geoserver/region-grand-est/ows'
'https://www.geograndest.fr/geoserver/region-grand-est/ows?REQUEST=GetCapabilities&SERVICE=WMS'
)
})
it('set WMS gutter of 20px', () => {
Expand Down Expand Up @@ -342,7 +364,7 @@ describe('MapContextService', () => {
const layerWMSUrl = (map.getLayers().item(1) as TileLayer<TileWMS>)
.getSource()
.getUrls()[0]
expect(layerWMSUrl).toEqual('https://some-wms-server/')
expect(layerWMSUrl).toEqual('https://some-wms-server')
})
it('add one WFS layer from config on top of baselayer', () => {
const layerWFSSource = (
Expand Down
10 changes: 5 additions & 5 deletions libs/feature/map/src/lib/utils/map-utils.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ jest.mock('@camptocamp/ogc-client', () => ({
boundingBoxes = {}
} else if (name.includes('4326')) {
boundingBoxes = {
'EPSG:4326': ['1', '2.6', '3.3', '4.2'],
'CRS:84': ['2.3', '50.6', '2.8', '50.9'],
'EPSG:4326': [1, 2.6, 3.3, 4.2],
'CRS:84': [2.3, 50.6, 2.8, 50.9],
}
} else if (name.includes('2154')) {
boundingBoxes = {
'EPSG:2154': ['650796.4', '7060330.6', '690891.3', '7090402.2'],
'EPSG:2154': [650796.4, 7060330.6, 690891.3, 7090402.2],
}
} else {
boundingBoxes = {
'CRS:84': ['2.3', '50.6', '2.8', '50.9'],
'EPSG:2154': ['650796.4', '7060330.6', '690891.3', '7090402.2'],
'CRS:84': [2.3, 50.6, 2.8, 50.9],
'EPSG:2154': [650796.4, 7060330.6, 690891.3, 7090402.2],
}
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ describe('MapViewComponent', () => {
expect(mapComponent.context).toEqual({
layers: [
{
name: 'orthophoto',
type: 'wmts',
options: expect.any(Object),
url: 'http://abcd.com/wmts',
},
],
view: expect.any(Object),
Expand Down
8 changes: 8 additions & 0 deletions libs/util/data-fetcher/src/lib/readers/csv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ afterEach(() => {
jest.clearAllMocks()
})

//todo: fix this test, to run without mocking useCache
jest.mock('@camptocamp/ogc-client', () => ({
useCache: jest.fn(async (factory) =>
JSON.parse(JSON.stringify(await factory()))
),
sharedFetch: jest.fn((url) => global.fetch(url)),
}))

describe('CSV parsing', () => {
describe('parseCsv', () => {
describe('valid CSV with id', () => {
Expand Down
8 changes: 8 additions & 0 deletions libs/util/data-fetcher/src/lib/readers/excel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const sampleXls = fs.readFileSync(
null
)

//todo: fix this test, to run without mocking useCache
jest.mock('@camptocamp/ogc-client', () => ({
useCache: jest.fn(async (factory) =>
JSON.parse(JSON.stringify(await factory()))
),
sharedFetch: jest.fn((url) => global.fetch(url)),
}))

describe('Excel parsing', () => {
describe('parseExcel', () => {
describe('.xslx file', () => {
Expand Down
8 changes: 8 additions & 0 deletions libs/util/data-fetcher/src/lib/readers/geojson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import fetchMock from 'fetch-mock-jest'
import path from 'path'
import fs from 'fs/promises'

//todo: fix this test, to run without mocking useCache
jest.mock('@camptocamp/ogc-client', () => ({
useCache: jest.fn(async (factory) =>
JSON.parse(JSON.stringify(await factory()))
),
sharedFetch: jest.fn((url) => global.fetch(url)),
}))

describe('geojson parsing', () => {
describe('parseGeojson', () => {
describe('Valid Geojson (array of features)', () => {
Expand Down
8 changes: 8 additions & 0 deletions libs/util/data-fetcher/src/lib/readers/gml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import fetchMock from 'fetch-mock-jest'
import path from 'path'
import fs from 'fs/promises'

//todo: fix this test, to run without mocking useCache
jest.mock('@camptocamp/ogc-client', () => ({
useCache: jest.fn(async (factory) =>
JSON.parse(JSON.stringify(await factory()))
),
sharedFetch: jest.fn((url) => global.fetch(url)),
}))

const singleFeatureValidGml = `<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
Expand Down
8 changes: 8 additions & 0 deletions libs/util/data-fetcher/src/lib/readers/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import fetchMock from 'fetch-mock-jest'
import path from 'path'
import fs from 'fs/promises'

//todo: fix this test, to run without mocking useCache
jest.mock('@camptocamp/ogc-client', () => ({
useCache: jest.fn(async (factory) =>
JSON.parse(JSON.stringify(await factory()))
),
sharedFetch: jest.fn((url) => global.fetch(url)),
}))

describe('json parsing', () => {
describe('parseJson', () => {
describe('valid JSON with id', () => {
Expand Down

0 comments on commit 8baab12

Please sign in to comment.