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

Add tests for aqicn layer #436

Merged
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
24 changes: 24 additions & 0 deletions cypress/fixtures/aqicn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": [
{
"lat": 43.458591187681,
"lon": 11.888247347751,
"uid": 9437,
"aqi": "30",
"station": {
"name": "Acropoli, Arezzo, Italy",
"time": "2020-03-01T23:00:00+01:00"
}
},
{
"lat": 37.350923,
"lon": -6.0520363,
"uid": 8494,
"aqi": "20",
"station": {
"name": "Aljarafe, Mairena Del Aljarafe, Spain",
"time": "2020-03-03T05:00:00+01:00"
}
}
]
}
51 changes: 51 additions & 0 deletions cypress/integration/aqicn.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe('Aqicn layer', function() {
it('adds markers on click', function() {
cy.openWindow('/example/index.html#lat=51.15&lon=13.45&zoom=4&layers=Standard')
cy.wait(300)
cy.window().then((win) => {
cy.fixture('aqicn').then((data) => {
cy.stub(win.AQICNLayer, 'requestRegionData', function() {
win.AQICNLayer.parseData(data);
})
})

cy.get('#menu-aqicnLayer label').click({ force: true })
cy.get('.leaflet-marker-pane').children().should('have.length', 2)
})
})

it('should have the layer name added to the hash', function() {
cy.hash().should('eq', '#lat=51.15&lon=13.45&zoom=4&layers=Standard,aqicnLayer')
})

it('has default markers in default mode', function() {
cy.get('.leaflet-marker-pane .leaflet-marker-icon').should('have.class', 'aqiSign')
cy.get('.leaflet-marker-pane .aqiSign').should('have.length', 2)
})

it('has circle markers in minimal mode', function() {
cy.server()
cy.route('GET', 'https://api.waqi.info/map/bounds/?latlng=31.052933985705163,-30.498046875000004,65.18303007291382,57.39257812500001&token=566331c289f0aeacd78e0b18362b4bcfa5097572', 'fixture:aqicn.json')
const spy = cy.spy(window.top.aut.AQICNLayer, 'requestRegionData')
cy.get('[title="Show minimal markers"]').click().then(() => {
expect(spy).to.be.called
cy.get('.leaflet-overlay-pane svg g').children().should('have.length', 2)
cy.get('.leaflet-overlay-pane svg g path').invoke('attr', 'stroke').should('eq', '#7c7c7c')
cy.get('.leaflet-overlay-pane svg g path').invoke('attr', 'stroke-linecap').should('eq', 'round')
cy.get('.leaflet-overlay-pane svg g path').invoke('attr', 'stroke-linecap').should('eq', 'round')
})
})

it('shows popup', function() {
cy.get('.leaflet-overlay-pane svg g').children().last().click({ force: true })
cy.get('.leaflet-popup-pane').children().should('have.length', 1)
cy.get('.leaflet-popup-content').should('contain', 'Spain')
})

it('removes markers from the map and the layer name from the hash when clicked again', function() {
cy.get('#menu-aqicnLayer label').click({ force: true })
cy.hash().should('eq', '#lat=51.15&lon=13.45&zoom=4&layers=Standard')
cy.get('.leaflet-marker-pane').children().should('have.length', 0)
cy.get('.leaflet-overlay-pane svg g').children().should('have.length', 0)
})
})