Skip to content

Commit

Permalink
Merge pull request #171 from scottbasgaard/scott/fix-tests
Browse files Browse the repository at this point in the history
chore: fix broken tests for layer actions
  • Loading branch information
florislangeraert authored Oct 12, 2023
2 parents b6e924a + 5636f0c commit b793cdf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
branches: [main]
tags:
- "*"
- '*'
pull_request:
branches: [main]

Expand All @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -26,7 +26,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Test
Expand Down
1 change: 0 additions & 1 deletion src/components/MapComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export default {
if (!layerSelected) {
return
}
console.log(layer.id)
}
const mapboxLayer = {}
Object.entries(layer.properties).forEach(([id, prop]) => {
Expand Down
5 changes: 1 addition & 4 deletions src/lib/mapbox/styling/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export function decorateLayerStyling(layerData) {
if (
layerData.properties['deltares:source-layer'] &&
layerData.properties['deltares:type'] === 'circle'
) {
if (layerData.properties['deltares:source-layer']) {
const style = process.env.VUE_APP_MAPBOX_LAYERS_STYLE || ''
const token = process.env.VUE_APP_MAPBOX_TOKEN || ''
const target = layerData.properties['deltares:source-layer'] || ''
Expand Down
36 changes: 21 additions & 15 deletions src/store/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,33 @@ export const actions = {
}
},

loadLayerCollection(
async loadLayerCollection(
{ commit },
{ collectionUrl, setCollectionCommit, addLayerCommit, datasetId }
) {
// Retrieve a layer collection and it's underlaying collection
getCatalog(collectionUrl).then(dataset => {
dataset.layers = []
// Retrieve a layer collection and it's underlaying collectiongit
await getCatalog(collectionUrl).then(async dataset => {
const itemLinks = _.get(dataset, 'links')
const items = itemLinks.filter(child => child.rel === 'item')
const layers = []
items.forEach((item, index) => {
getCatalog(item.href)
.then(decorateLayerStyling)
.then(layerData => {
layers.push(layerData)
if (index === items.length - 1) {
dataset.layers = layers
commit(setCollectionCommit, { id: datasetId, data: dataset })
}
})
})

await Promise.all(
items.map(async item =>
getCatalog(item.href)
.then(decorateLayerStyling)
.then(layerData => {
layers.push(layerData)
})
)
)

if (layers.length > 0) {
dataset.layers = layers
commit(setCollectionCommit, {
id: datasetId,
data: dataset
})
}
})
},

Expand Down
13 changes: 11 additions & 2 deletions tests/unit/store/map/index/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { actions } from '@/store/map/index.js'
import getCatalog from '@/lib/request/get-catalog'

jest.mock('@/lib/request/get-catalog')
jest.mock('@/lib/mapbox/styling/index.js', () => ({
decorateLayerStyling: jest
.fn()
.mockImplementation(input => Promise.resolve(input))
}))

describe('loadDatasets', () => {
test('fetches datasets and stores them', async () => {
Expand Down Expand Up @@ -218,12 +223,16 @@ describe('loadLayerCollection', () => {
getCatalog.mockResolvedValueOnce(apiResult)
getCatalog.mockResolvedValue('bar')

const childs = await actions.loadLayerCollection(
// Call the async function and await its resolution
await actions.loadLayerCollection(
{ commit },
{ collectionUrl: 'url', setCollectionCommit: 'foo', datasetId: 'par1' }
)
await childs

// Modify apiResult after the async operation is done
apiResult.layers = ['bar', 'bar']

// Expect commit to be called with the modified data
expect(commit.mock.calls[0]).toEqual([
'foo',
{ id: 'par1', data: apiResult }
Expand Down

0 comments on commit b793cdf

Please sign in to comment.