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

test: add e2e tests for superset embedded dashboards feature #3197

Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2fa3897
chore: add excludeByVersionTag to cypress config and add tagify depen…
HendrikThePendric Jan 28, 2025
a090c25
chore: allow mixing cucumber and non-cucumber specs
HendrikThePendric Jan 29, 2025
6cd75a6
chore: temporarily disable all cypress-cucumber stuff
HendrikThePendric Jan 29, 2025
ff01cf6
test: add cypress test for creating a superset embedded dashboard
HendrikThePendric Jan 29, 2025
675218b
chore: update dependencies so that cypress-tags could run
HendrikThePendric Jan 29, 2025
daf813f
chore: disable exclude by version tags and enable cucumber preprocessor
HendrikThePendric Jan 29, 2025
ae0f90e
chore: detect version during run and skip tests if below 42
HendrikThePendric Jan 29, 2025
73135fc
chore: keep cucumber specs separate from js specs to prevent
HendrikThePendric Jan 29, 2025
0cd1fe1
fix: close more-menu after toggling dashboard starred state
HendrikThePendric Jan 30, 2025
94668c4
fix: ensure dashboard iframe is reloaded when dashboard embed data is…
HendrikThePendric Jan 30, 2025
daee5c7
test: finalize e2e test suite for superset embedded dashboard feature
HendrikThePendric Jan 30, 2025
f9ccfdd
chore: ensure the before callback has a this scope
HendrikThePendric Jan 30, 2025
15de3d4
chore: update yarn.lock
HendrikThePendric Jan 31, 2025
a24953d
chore: upgrade node version in all workflows
HendrikThePendric Jan 31, 2025
cf4517f
chore: adjust cypress spec path
HendrikThePendric Jan 31, 2025
0ac529e
chore: adjust test matrix so it includes both cucumber and regular cy…
HendrikThePendric Jan 31, 2025
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
Prev Previous commit
Next Next commit
chore: detect version during run and skip tests if below 42
HendrikThePendric committed Jan 29, 2025
commit ae0f90e332025c9fe285195f7e18adda734564b4
165 changes: 84 additions & 81 deletions cypress/e2e/embedded_superset_dashboard.cy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isFeature } from '@badeball/cypress-cucumber-preprocessor'

Check failure on line 1 in cypress/e2e/embedded_superset_dashboard.cy.js

GitHub Actions / lint

'isFeature' is defined but never used
import { newButtonSel } from '../elements/viewDashboard.js'
import { EXTENDED_TIMEOUT } from '../support/utils.js'

@@ -19,93 +20,95 @@
const getInputByLabelText = (labelText, inputTag = 'input') =>
cy.get('form').contains('label', labelText).parent().find(inputTag)

describe(
['>=42'],
'Creating, viewing, editing and deleting an embedded superset dashboard',
() => {
before(() => {
cy.intercept('**', (req) => {
if (req.url.includes('/systemSettings?')) {
// Append system setting for embedded dashboard support
req.continue((resp) => {
resp.body.keyEmbeddedDashboardsEnabled = true
return resp
})
} else if (req.url.includes('/superset-gateway/api/info')) {
// Stub the response to the superset gateway info request
req.reply({
supersetBaseUrl: SUPERSET_BASE_URL,
apiDocsPath:
'/superset-gateway/apidocs/dhis2-superset-gateway/swagger-ui/',
})
} else if (
req.url.includes(
'/superset-gateway/api/guestTokens/dhis2/dashboards/'
)
) {
// Stub the response to the superset gatewat guest token request
req.reply({
// Note that the string below does need to have a particular pattern: it was
// copied from the network tab and cannot be replaced by a random shorter string.
// The superset embed SDK must do some sort of pattern validation on it
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJuYW1lIjoiYW5hbHl0aWNzIiwiZmlyc3RfbmFtZSI6IkRISVMgMiBTdXBlcnNldCIsImxhc3RfbmFtZSI6IkdhdGV3YXkifSwicmVzb3VyY2VzIjpbeyJ0eXBlIjoiZGFzaGJvYXJkIiwiaWQiOiI2NmEzNGMyYS1mYTA2LTRkYjUtYmQ2ZS0wOGZkMjRiZjVhY2MifV0sInJsc19ydWxlcyI6W10sImlhdCI6MTczNzk5NTE0My4yMTU5NjcsImV4cCI6MTczNzk5NTQ0My4yMTU5NjcsImF1ZCI6Imh0dHA6Ly8wLjAuMC4wOjgwODAvIiwidHlwZSI6Imd1ZXN0In0.AayCHirBjomllKxThOCQsn4RHoIfaXfULOVtcnylhj8',
})
} else if (req.url.includes(`${SUPERSET_BASE_URL}/embedded/`)) {
req.reply(SUPERSET_DASHBOARD_STUB)
} else {
// Just return the response by default
req.continue((resp) => resp)
}
})
describe('Creating, viewing, editing and deleting an embedded superset dashboard', function () {
before(function () {
// Skip this test if the DHIS2 Core version is below 42
const version = parseInt(Cypress.env('dhis2InstanceVersion'))
if (version < 42) {
this.skip()
}

// Fake support for embedded dashboards by intercepting the requests below
cy.intercept('**', (req) => {
if (req.url.includes('/systemSettings?')) {
// Append system setting for embedded dashboard support
req.continue((resp) => {
resp.body.keyEmbeddedDashboardsEnabled = true
return resp
})
} else if (req.url.includes('/superset-gateway/api/info')) {
// Stub the response to the superset gateway info request
req.reply({
supersetBaseUrl: SUPERSET_BASE_URL,
apiDocsPath:
'/superset-gateway/apidocs/dhis2-superset-gateway/swagger-ui/',
})
} else if (
req.url.includes(
'/superset-gateway/api/guestTokens/dhis2/dashboards/'
)
) {
// Stub the response to the superset gatewat guest token request
req.reply({
// Note that the string below does need to have a particular pattern: it was
// copied from the network tab and cannot be replaced by a random shorter string.
// The superset embed SDK must do some sort of pattern validation on it
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJuYW1lIjoiYW5hbHl0aWNzIiwiZmlyc3RfbmFtZSI6IkRISVMgMiBTdXBlcnNldCIsImxhc3RfbmFtZSI6IkdhdGV3YXkifSwicmVzb3VyY2VzIjpbeyJ0eXBlIjoiZGFzaGJvYXJkIiwiaWQiOiI2NmEzNGMyYS1mYTA2LTRkYjUtYmQ2ZS0wOGZkMjRiZjVhY2MifV0sInJsc19ydWxlcyI6W10sImlhdCI6MTczNzk5NTE0My4yMTU5NjcsImV4cCI6MTczNzk5NTQ0My4yMTU5NjcsImF1ZCI6Imh0dHA6Ly8wLjAuMC4wOjgwODAvIiwidHlwZSI6Imd1ZXN0In0.AayCHirBjomllKxThOCQsn4RHoIfaXfULOVtcnylhj8',
})
} else if (req.url.includes(`${SUPERSET_BASE_URL}/embedded/`)) {
req.reply(SUPERSET_DASHBOARD_STUB)
} else {
// Just return the response by default
req.continue((resp) => resp)
}
})
})

it('is possible to create an embedded superset dashboard', () => {
// Start a new dashboard from the start page
cy.visit('#/start')
cy.get(newButtonSel, EXTENDED_TIMEOUT).click()
it('is possible to create an embedded superset dashboard', () => {
// Start a new dashboard from the start page
cy.visit('#/start')

// Choose the embedded dashboard option
cy.contains('External: Data from another source')
.should('be.visible')
.click()
cy.get(newButtonSel, EXTENDED_TIMEOUT).click()

// Click the configure source button
cy.contains('Configure source').should('be.visible').click()
// Choose the embedded dashboard option
cy.contains('External: Data from another source')
.should('be.visible')
.click()

// A modal form to create a new embedded dashboard is showing
cy.contains(
'New dashboard: configure external source (superset)'
).should('be.visible')
// Click the configure source button
cy.contains('Configure source').should('be.visible').click()

// All text fields are empty and both checkboxes are checked
getInputByLabelText('Title').should('have.value', '')
getInputByLabelText('Code').should('have.value', '')
getInputByLabelText('Description', 'textarea').should(
'have.value',
''
)
getInputByLabelText('Superset Embed ID').should('have.value', '')
getInputByLabelText(
'Show chart controls on dashboard items'
).should('have.prop', 'checked')
getInputByLabelText('Show filters').should('have.prop', 'checked')
// A modal form to create a new embedded dashboard is showing
cy.contains(
'New dashboard: configure external source (superset)'
).should('be.visible')

// Fill in the title and superset ID fields
getInputByLabelText('Title').type('My new dashboard ')
// getInputByLabelText('Code').type('MY_CODE')
getInputByLabelText('Description', 'textarea').type(
'My dashboard description'
)
getInputByLabelText('Superset Embed ID').type(UUID)
// All text fields are empty and both checkboxes are checked
getInputByLabelText('Title').should('have.value', '')
getInputByLabelText('Code').should('have.value', '')
getInputByLabelText('Description', 'textarea').should('have.value', '')
getInputByLabelText('Superset Embed ID').should('have.value', '')
getInputByLabelText('Show chart controls on dashboard items').should(
'have.prop',
'checked'
)
getInputByLabelText('Show filters').should('have.prop', 'checked')

// Click the create button
cy.contains('Save dashboard').should('be.enabled').click()
// Fill in the title and superset ID fields
getInputByLabelText('Title').type('My new dashboard ')
// getInputByLabelText('Code').type('MY_CODE')
getInputByLabelText('Description', 'textarea').type(
'My dashboard description'
)
getInputByLabelText('Superset Embed ID').type(UUID)

// An iframe should be visible with the UUID in the src
cy.get('iframe')
.should('be.visible')
.and('have.attr', 'src')
.and('contain', UUID)
})
}
)
// Click the create button
cy.contains('Save dashboard').should('be.enabled').click()

// An iframe should be visible with the UUID in the src
cy.get('iframe')
.should('be.visible')
.and('have.attr', 'src')
.and('contain', UUID)
})
})
Loading