Skip to content

Commit

Permalink
Merge pull request #161 from Geoportail-Luxembourg/GSLUX-707_drawStyle
Browse files Browse the repository at this point in the history
GSLUX-707 activate style edition for drawings
  • Loading branch information
mki-c2c authored Nov 15, 2024
2 parents 55e4941 + eae429f commit 3345a92
Show file tree
Hide file tree
Showing 29 changed files with 689 additions and 154 deletions.
6 changes: 6 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export default defineConfig({

// It's IMPORTANT to return the config object
// with any changed environment variables
config.browsers = [
config.browsers.find(
b => b.name === 'chromium' || b.name === 'chrome'
)!,
].map(b => ({ ...b, name: 'my-chromium' }))
config.experimentalRunAllSpecs = true
return config
},
},
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/background-selection.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Background selector', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')
.filter((l: any) => !/feature(Edit)?Layer/.exec(l.get('cyLayerType')))

Check warning on line 25 in cypress/e2e/background-selection.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
expect(layers[0].get('id')).to.eq(556)
})

Expand Down Expand Up @@ -52,7 +52,7 @@ describe('Background selector', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')
.filter((l: any) => !/feature(Edit)?Layer/.exec(l.get('cyLayerType')))

Check warning on line 55 in cypress/e2e/background-selection.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
expect(layers[0].get('id')).to.eq(502)
})
})
Expand Down
5 changes: 4 additions & 1 deletion cypress/e2e/draw/draw-feat-circle.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ describe('Draw "Circle"', () => {
)
cy.dragVertexOnMap(200, 200, 300, 300)
cy.get('*[data-cy="featItemLength"]').should('contain.text', '693.17 km')
cy.get('*[data-cy="featItemArea"]').should('contain.text', '38235.40 km²')
// testing just integer part due to precision issues between local tests and CI
cy.get('*[data-cy="featItemArea"]')
.should('contain.text', 'Surface: 38235.')
.and('contain.text', ' km²')
})

it('updates length and area measurements when editing radius in panel', () => {
Expand Down
5 changes: 3 additions & 2 deletions cypress/e2e/draw/draw-feat-point.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ describe('Draw "Point"', () => {

it('displays the symbol edition tab', () => {
cy.get('[data-cy="featStyleColor"]').should('exist')
cy.get('[data-cy="featStyleSymbol"]').should('have.length', 4)
// starting with featStyleSymbol_
cy.get('[data-cy^="featStyleSymbol_"]').should('have.length', 4)
})

describe('When browsing public symbols', () => {
Expand All @@ -147,7 +148,7 @@ describe('Draw "Point"', () => {

describe('When clicking close button', () => {
it('returns to style edition tab', () => {
cy.get('[data-cy="featStyleNavBack"]').click()
cy.get('[data-cy="featClosePopup"]').click()
testFeatStyleEditionTabContent()
})
})
Expand Down
7 changes: 6 additions & 1 deletion cypress/e2e/draw/draw-feat-polygon.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ describe('Draw "Polygon"', () => {
cy.get('*[data-cy="featItemArea"]').should('contain.text', '766.33 km²')
cy.dragVertexOnMap(200, 200, 300, 300)
cy.get('*[data-cy="featItemLength"]').should('contain.text', '238.47 km')
cy.get('*[data-cy="featItemArea"]').should('contain.text', '1532.65 km²')
// there is a strange behaviour in CI:
// - chrome and chromium browsers give different decimals in measurements
// - therefore only the int part of the surface is checked
cy.get('*[data-cy="featItemArea"]')
.should('contain.text', 'Surface: 1532.')
.and('contain.text', ' km²')
})

it('displays the possible actions for the feature', () => {
Expand Down
293 changes: 293 additions & 0 deletions cypress/e2e/draw/draw-feat-style.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
beforeEach(() => {
cy.visit('/')
})
describe('Test style edition of Point feature', () => {
beforeEach('Draw "Point"', () => {
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawPointButton"]').click()
cy.get('div.ol-viewport').click(400, 300, { force: true })
// finish editing, otherwise we have two OL objects
cy.get('button[data-cy="featItemToggleEdit"]').click()
})
beforeEach('Edit feature style', () => {
cy.get('*[data-cy="featItemActionStyle"]').click()
cy.get('*[data-cy="featStyleColor"]')
.invoke('val', '#00ff00')
.trigger('input')
cy.get('*[data-cy="featStyleSymbol"]').click()
cy.get('*[data-cy="featStyleSymbol_2"]').click()
cy.get('*[data-cy="featStyleSize"]').type('{selectAll}50')
cy.get('*[data-cy="featStyleAngle"]').type('{selectAll}30')
cy.get('*[data-cy="featStyleAngle"]').trigger('input')
})
it('Check that new feature style is not yet encoded in URL', () => {
cy.url().as('url')
cy.window()
.its('featureHash')
.then(function (fh) {
const features = new URLSearchParams(new URL(this.url).search).get(
'features'
)!
const ff = fh.readFeatures(features)
cy.wrap(ff[0].get('t')).should('equal', '10')
})
})

it('Validate Style and check that new feature style is encoded in URL', () => {
// URL is updated when clicking validation button
cy.get('button[data-cy="featureEditValidate"]').click()
cy.url().as('url')
cy.window()
.its('featureHash')
.then(function (fh) {
const features = new URLSearchParams(new URL(this.url).search).get(
'features'
)!
const ff = fh.readFeatures(features)
cy.wrap(ff).its('length').should('equal', 1)

cy.wrap(ff[0].getGeometry()?.getType()).should('equal', 'Point')
// check color green
cy.wrap(ff[0].get('c')).should('equal', '%2300ff00')
// check shape: cross
cy.wrap(ff[0].get('s')).should('equal', 'cross')
// check size 50
cy.wrap(ff[0].get('t')).should('equal', '50')

return cy.wrap(ff)
})
.its('length')
.should('equal', 1) // only one geometry has been created
})
it('Check that new feature style is applied to feature on map', () => {
cy.window()
.its('olMap')
.then(function (olMap) {
const featureLayers = olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') === 'featureLayer')

Check warning on line 69 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
const features = featureLayers
.map((l: any) => l.getSource().getFeatures())

Check warning on line 71 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
.flat()
cy.wrap(features.length).should('equal', 1)

// const ff = features.find((f: any) => f.get('name') === 'Point 1')
const ff = features[0]
cy.wrap(ff.featureType).should('equal', 'drawnPoint')
// check color green
cy.wrap(ff.featureStyle.color).should('equal', '#00ff00')
// check shape: cross
cy.wrap(ff.featureStyle.shape).should('equal', 'cross')
// check size = 50
cy.wrap(ff.featureStyle.size).should('equal', 50)
// check angle = 30°
// no idea why the angle setting cannot be checked here
// cy.log(ff.featureStyle.angle, (ff.featureStyle.angle / Math.PI) * 180)
// cy.wrap(Math.abs(30 - ff.featureStyle.angle / Math.PI * 180)).should('be.lessThan', 0.0001)
})
})

it('Cancel style changes and check that initial style is restored', () => {
cy.get('button[data-cy="featureEditCancel"]').click()

cy.window()
.its('olMap')
.then(function (olMap) {
const featureLayers = olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') === 'featureLayer')

Check warning on line 100 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
const features = featureLayers
.map((l: any) => l.getSource().getFeatures())

Check warning on line 102 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
.flat()
cy.wrap(features.length).should('equal', 1)
const ff = features[0]
// check size = 10
cy.wrap(ff.featureStyle.size).should('equal', 10)
})
})
})

describe('Test style edition of Label feature', () => {
beforeEach('Draw "Point"', () => {
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawLabelButton"]').click()
cy.get('div.ol-viewport').click(250, 150, { force: true })
})
beforeEach('Edit feature style', () => {
cy.get('*[data-cy="featItemActionStyle"]').click()
cy.get('*[data-cy="featStyleColor"]')
.invoke('val', '#009f09')
.trigger('input')
cy.get('*[data-cy="featStyleSize"]').type('{selectAll}8') // max size 10
cy.get('*[data-cy="featStyleAngle"]').type('{selectAll}60')
cy.get('button[data-cy="featureEditValidate"]').click()
})

it('Check that new feature style is applied to feature on map', () => {
// get featureLayer
cy.window()
.its('olMap')
.then(function (olMap) {
const featureLayers = olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') === 'featureLayer')

Check warning on line 136 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
const features = featureLayers
.map((l: any) => l.getSource().getFeatures())

Check warning on line 138 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
.flat()
cy.wrap(features.length).should('equal', 1)

const ff = features[0]
cy.wrap(ff.featureType).should('equal', 'drawnLabel')
// check color green
cy.wrap(ff.featureStyle.color).should('equal', '#009f09')
// check size = 50
cy.wrap(ff.featureStyle.size).should('equal', 8)
// check angle = 60°
cy.wrap(Math.abs(60 - (ff.featureStyle.angle / Math.PI) * 180)).should(
'be.lessThan',
0.0001
)
})
})
})

describe('Test style edition of Line feature', () => {
beforeEach('Draw "Line"', () => {
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawLineButton"]').click()
cy.get('div.ol-viewport').click(200, 400, { force: true })
cy.get('div.ol-viewport').click(300, 300, { force: true })
cy.get('div.ol-viewport').click(400, 400, { force: true })
cy.get('div.ol-viewport').dblclick(500, 300, { force: true })
})
beforeEach('Edit feature style', () => {
cy.get('*[data-cy="featItemActionStyle"]').click()
cy.get('*[data-cy="featStyleColor"]')
.invoke('val', '#0088ff')
.trigger('input')
cy.get('*[data-cy="featStyleLineWidth"]')
.find('input')
.eq(1)
.type('{selectAll}7.5', { force: true })
cy.get('*[data-cy="featStyleLineStyle"]').find('button').eq(1).click()
cy.get('button[data-cy="featureEditValidate"]').click()
})

it('Check that new feature style is applied to feature on map', () => {
// get featureLayer
cy.window()
.its('olMap')
.then(function (olMap) {
const featureLayers = olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') === 'featureLayer')

Check warning on line 187 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
const features = featureLayers
.map((l: any) => l.getSource().getFeatures())

Check warning on line 189 in cypress/e2e/draw/draw-feat-style.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
.flat()
cy.wrap(features.length).should('equal', 1)
const ff = features[0]
cy.wrap(ff.featureType).should('equal', 'drawnLine')
// check color blue
cy.wrap(ff.featureStyle.color).should('equal', '#0088ff')
// check line width 5
cy.wrap(ff.featureStyle.stroke).should('equal', 7.5)
// check line style dashed
cy.wrap(ff.featureStyle.linestyle).should('equal', 'dashed')
})
})
})

describe('Test style edition of Polygon feature', () => {
beforeEach('Draw "Polygon"', () => {
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawPolygonButton"]').click()
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.ol-viewport').click(100, 200, { force: true })
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
})
beforeEach('Edit feature style', () => {
cy.get('*[data-cy="featItemActionStyle"]').click()
cy.get('*[data-cy="featStyleColor"]')
.invoke('val', '#0000ff')
.trigger('input')
cy.get('*[data-cy="featStyleLineWidth"]')
.find('input')
.eq(1)
.type('{selectAll}5.5')
cy.get('*[data-cy="featStyleTransparency"]').type('{selectAll}22')
cy.get('button[data-cy="featureEditValidate"]').click()
})

it('Check that new feature style is applied to feature on map', () => {
// get featureLayer
cy.window()
.its('olMap')
.then(function (olMap) {
const featureLayers = olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') === 'featureLayer')
const features = featureLayers
.map((l: any) => l.getSource().getFeatures())
.flat()
cy.wrap(features.length).should('equal', 1)
const ff = features[0]
cy.wrap(ff.featureType).should('equal', 'drawnPolygon')
// check color blue
cy.wrap(ff.featureStyle.color).should('equal', '#0000ff')
// check line width 5
cy.wrap(ff.featureStyle.stroke).should('equal', 5.5)
// check opacity 0.78
cy.wrap(ff.featureStyle.opacity).should('equal', 0.78)
})
})
})

describe('Test style edition of Circle feature', () => {
beforeEach('Draw "Circle"', () => {
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawCircleButton"]').click()
cy.get('div.ol-viewport').click(500, 400, { force: true })
cy.get('div.ol-viewport').dblclick(550, 450, { force: true })
})
beforeEach('Edit feature style', () => {
cy.get('*[data-cy="featItemActionStyle"]').click()
cy.get('*[data-cy="featStyleColor"]')
.invoke('val', '#00004f')
.trigger('input')
cy.get('*[data-cy="featStyleLineWidth"]')
.find('input')
.eq(1)
.type('{selectAll}3.5')
cy.get('*[data-cy="featStyleTransparency"]').type('{selectAll}62')
cy.get('button[data-cy="featureEditValidate"]').click()
})

it('Check that new feature style is applied to feature on map', () => {
// get featureLayer
cy.window()
.its('olMap')
.then(function (olMap) {
const featureLayers = olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') === 'featureLayer')
const features = featureLayers
.map((l: any) => l.getSource().getFeatures())
.flat()
cy.wrap(features.length).should('equal', 1)
const ff = features[0]
cy.wrap(ff.featureType).should('equal', 'drawnCircle')
// check color blue
cy.wrap(ff.featureStyle.color).should('equal', '#00004f')
// check line width 5
cy.wrap(ff.featureStyle.stroke).should('equal', 3.5)
// check opacity 0.78
cy.wrap(ff.featureStyle.opacity).should('equal', 0.38)
})
})
})
12 changes: 10 additions & 2 deletions cypress/e2e/layers-selection/layers-selection-catalog.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ describe('Catalogue', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')
.filter(
(l: any) =>
// regex match
!/feature(Edit)?Layer/.exec(l.get('cyLayerType'))
)
expect(layers[0].get('id')).to.eq(556)
})
cy.get('[data-cy="catalog"]')
Expand All @@ -81,7 +85,11 @@ describe('Catalogue', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')
.filter(
(l: any) =>
// regex match
!/feature(Edit)?Layer/.exec(l.get('cyLayerType'))
)
expect(layers[0].get('id')).to.eq(359)
expect(layers[1].get('id')).to.eq(353)
})
Expand Down
Loading

0 comments on commit 3345a92

Please sign in to comment.