Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 6b2e460

Browse files
committed
webui, cypress: Fix bug stopping logged-out users from using public visualisations
Introduced 2 days ago in 7b2caad. :( This commit also adds a Cypress test, to ensure we don't accidentally re-introduce this bug at some point.
1 parent c92f0f8 commit 6b2e460

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

cypress/e2e/1-webui/visualisation.cy.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,51 @@ describe('visualisation', () => {
358358
cy.get('[data-cy="nameinput"').should('exist')
359359
cy.get('[data-cy="delvisbtn"').should('exist')
360360
})
361+
362+
// Ensure a logged-out user can still change visualisations
363+
it('Ensure a logged-out user can still change visualisations', () => {
364+
// Switch to the default user
365+
cy.request('/x/test/switchdefault')
366+
367+
// Load a public database
368+
cy.visit('/vis/default/Assembly Election 2017 with view.sqlite')
369+
370+
// Delete the "default" visualisation
371+
cy.get('[data-cy="visdropdown"]').click()
372+
cy.get('[data-cy="vis-default"]').click()
373+
cy.get('[data-cy="delvisbtn"]').click()
374+
375+
// Create a second visualisation
376+
cy.get('[data-cy="sqltab"]').click()
377+
cy.get('[data-cy="usersqltext"]').type('{selectall}{backspace}').type(
378+
'SELECT Constituency_Name, Constituency_Number\n' +
379+
'FROM Constituency_Turnout_Information\n' +
380+
'ORDER BY Constituency_Name ASC\n' +
381+
'LIMIT 5')
382+
cy.get('[data-cy="nameinput"]').type('{selectall}{backspace}').type('test2 ASC')
383+
cy.get('[data-cy="savebtn"]').click()
384+
385+
// Log out
386+
cy.request('/x/test/logout')
387+
388+
// Load the database again
389+
cy.visit('/vis/default/Assembly Election 2017 with view.sqlite')
390+
391+
// Ensure the visualisation drop down works ok
392+
cy.get('[data-cy="visdropdown"]').click()
393+
cy.get('[data-cy="vis-test2 ASC"]').click()
394+
cy.get('[data-cy="usersqltext"]').should('contain.text', 'SELECT Constituency_Name, Constituency_Number\n' +
395+
'FROM Constituency_Turnout_Information\n' +
396+
'ORDER BY Constituency_Name ASC\n' +
397+
'LIMIT 5')
398+
cy.get('[data-cy="visdropdown"]').click()
399+
cy.get('[data-cy="vis-test1"]').click()
400+
cy.get('[data-cy="usersqltext"]').should('contain.text', 'SELECT Constituency_Name, Constituency_Number, Turnout_pct\n' +
401+
'FROM Constituency_Turnout_Information\n' +
402+
'ORDER BY Constituency_Name DESC\n' +
403+
'LIMIT 10')
404+
405+
// Switch back to the default user
406+
cy.request('/x/test/switchdefault')
407+
})
361408
})

webui/templates/visualise.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ <h4 style="color: {{ statusMessageColour }};" data-cy="statusmsg">&nbsp;{{ statu
441441
// Change to a newly selected visualisation
442442
// Note, the 'execNewVis' parameter controls whether to execute and display the visualisation after loading it
443443
$scope.changeVis = function(newVis, execNewVis) {
444+
444445
// Clear out any existing table data and chart
445446
$scope.showVis = false;
446447
$scope.clearData();
@@ -454,7 +455,10 @@ <h4 style="color: {{ statusMessageColour }};" data-cy="statusmsg">&nbsp;{{ statu
454455
}
455456

456457
// Apply the retrieved information
457-
document.getElementById("savename").value = newVis;
458+
let saveTxt = document.getElementById("savename");
459+
if (saveTxt) {
460+
saveTxt.value = newVis;
461+
}
458462
$scope.visName = newVis;
459463

460464
// We include '.textContent' here now because Cypress (v12.3.0) *refuses* to return the correct

0 commit comments

Comments
 (0)