Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix broken tests for layer actions #171

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florislangeraert I removed this test for type circle as the one you were testing was type symbol. Either way it should grab the paint styling directly over the API then.

) {
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 All @@ -23,7 +20,7 @@
return layerData
})
.catch(e => {
console.error(e)

Check warning on line 23 in src/lib/mapbox/styling/index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

return layerData
})
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 @@
}
},

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 Expand Up @@ -466,7 +472,7 @@
res.events.map(event => moment(event.timeStamp).format())
)
})
console.log({

Check warning on line 475 in src/store/map/index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement
id: datasetId,
data: {
[locationId]: {
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
Loading