From 7c60cdf706a54b371c0328c678d4d5f147be245a Mon Sep 17 00:00:00 2001 From: Scott Basgaard Date: Mon, 9 Oct 2023 12:44:32 +0200 Subject: [PATCH 1/3] chore: fix broken tests for layer actions --- src/store/map/index.js | 36 +++++++++++++--------- tests/unit/store/map/index/actions.spec.js | 13 ++++++-- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/store/map/index.js b/src/store/map/index.js index e7433ef..99bb664 100644 --- a/src/store/map/index.js +++ b/src/store/map/index.js @@ -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 + }) + } }) }, diff --git a/tests/unit/store/map/index/actions.spec.js b/tests/unit/store/map/index/actions.spec.js index 9e00fc0..189187c 100644 --- a/tests/unit/store/map/index/actions.spec.js +++ b/tests/unit/store/map/index/actions.spec.js @@ -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 () => { @@ -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 } From be0e24a0dd0b2569d79ff4f9ff7b4de0dc1039bb Mon Sep 17 00:00:00 2001 From: Scott Basgaard Date: Mon, 9 Oct 2023 13:09:57 +0200 Subject: [PATCH 2/3] build: update pipeline to Node 18 --- .github/workflows/node.js.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 6b20fa4..bc78797 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -7,7 +7,7 @@ on: push: branches: [main] tags: - - "*" + - '*' pull_request: branches: [main] @@ -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: @@ -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 From 5636f0cfa3c0c3a9aa16921b3f29a31765fecbfd Mon Sep 17 00:00:00 2001 From: Scott Basgaard Date: Mon, 9 Oct 2023 13:10:21 +0200 Subject: [PATCH 3/3] feat: support styling all layer types --- src/components/MapComponent.vue | 1 - src/lib/mapbox/styling/index.js | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/MapComponent.vue b/src/components/MapComponent.vue index bb716e5..305de06 100644 --- a/src/components/MapComponent.vue +++ b/src/components/MapComponent.vue @@ -206,7 +206,6 @@ export default { if (!layerSelected) { return } - console.log(layer.id) } const mapboxLayer = {} Object.entries(layer.properties).forEach(([id, prop]) => { diff --git a/src/lib/mapbox/styling/index.js b/src/lib/mapbox/styling/index.js index 4441b65..c52edbe 100644 --- a/src/lib/mapbox/styling/index.js +++ b/src/lib/mapbox/styling/index.js @@ -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'] || ''