chore: Refactor enabledExpression tests to use LightDashboard and improve button identification
This commit is contained in:
parent
3d5268d1c9
commit
7428c160e7
|
|
@ -93,7 +93,7 @@ function setupVue (i18nSettings) {
|
||||||
|
|
||||||
function setupErrorDisplay (errorMessage) {
|
function setupErrorDisplay (errorMessage) {
|
||||||
const ErrorApp = {
|
const ErrorApp = {
|
||||||
render() {
|
render () {
|
||||||
return h('section', { class: 'bad', style: 'padding: 2em; text-align: center; margin: 2em auto;' }, [
|
return h('section', { class: 'bad', style: 'padding: 2em; text-align: center; margin: 2em auto;' }, [
|
||||||
h('h2', 'OliveTin Init Failed'),
|
h('h2', 'OliveTin Init Failed'),
|
||||||
h('p', errorMessage),
|
h('p', errorMessage),
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,21 @@ function goBack() {
|
||||||
async function getDashboard() {
|
async function getDashboard() {
|
||||||
let title = props.title
|
let title = props.title
|
||||||
|
|
||||||
|
// Decode URL-encoded title if present (Vue Router should decode automatically,
|
||||||
|
// but handle cases where it might not)
|
||||||
|
if (title) {
|
||||||
|
try {
|
||||||
|
// Try decoding in case it's URL-encoded (e.g., "Lights%20Dashboard" -> "Lights Dashboard")
|
||||||
|
const decoded = decodeURIComponent(title)
|
||||||
|
// Use decoded version if it's different from the original
|
||||||
|
if (decoded !== title) {
|
||||||
|
title = decoded
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// If decoding fails (e.g., invalid encoding), use original title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If no specific title was provided or it's the placeholder 'default',
|
// If no specific title was provided or it's the placeholder 'default',
|
||||||
// prefer the first configured root dashboard (e.g., "Test").
|
// prefer the first configured root dashboard (e.g., "Test").
|
||||||
if ((!title || title === 'default') && window.initResponse.rootDashboards && window.initResponse.rootDashboards.length > 0) {
|
if ((!title || title === 'default') && window.initResponse.rootDashboards && window.initResponse.rootDashboards.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ entities:
|
||||||
name: light
|
name: light
|
||||||
|
|
||||||
dashboards:
|
dashboards:
|
||||||
- title: Lights Dashboard
|
- title: LightDashboard
|
||||||
contents:
|
contents:
|
||||||
- title: Light Controls
|
- title: Light Controls
|
||||||
type: fieldset
|
type: fieldset
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import { describe, it, before, after } from 'mocha'
|
import { describe, it, before, after } from 'mocha'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { By, until } from 'selenium-webdriver'
|
import { By, until, Condition } from 'selenium-webdriver'
|
||||||
import {
|
import {
|
||||||
getRootAndWait,
|
getRootAndWait,
|
||||||
takeScreenshotOnFailure,
|
takeScreenshotOnFailure,
|
||||||
} from '../../lib/elements.js'
|
} from '../../lib/elements.js'
|
||||||
|
|
||||||
describe('config: enabledExpression', function () {
|
describe('config: enabledExpression', function () {
|
||||||
|
this.timeout(30000) // Increase timeout for async operations
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
await runner.start('enabledExpression')
|
await runner.start('enabledExpression')
|
||||||
})
|
})
|
||||||
|
|
@ -23,26 +25,86 @@ describe('config: enabledExpression', function () {
|
||||||
await getRootAndWait()
|
await getRootAndWait()
|
||||||
|
|
||||||
// Navigate to the Lights Dashboard
|
// Navigate to the Lights Dashboard
|
||||||
await webdriver.get(runner.baseUrl() + '/dashboard/Lights%20Dashboard')
|
// Use the path with space encoded as %20 - Vue Router should decode it
|
||||||
|
await webdriver.get(runner.baseUrl() + '/dashboards/LightDashboard')
|
||||||
|
|
||||||
// Wait for dashboard to load
|
// Wait for the URL to change and the route to be processed
|
||||||
await webdriver.wait(until.elementLocated(By.css('.action-button')), 10000)
|
await webdriver.wait(new Condition('wait for URL to contain dashboards', async function() {
|
||||||
|
const url = await webdriver.getCurrentUrl()
|
||||||
|
return url.includes('/dashboards/')
|
||||||
|
}), 5000)
|
||||||
|
|
||||||
// Find action buttons
|
// Wait for dashboard to load by checking the loaded-dashboard attribute
|
||||||
const actionButtons = await webdriver.findElements(By.css('.action-button button'))
|
// The attribute should be set to the decoded title "LightDashboard"
|
||||||
|
await webdriver.wait(new Condition('wait for loaded-dashboard', async function() {
|
||||||
|
const body = await webdriver.findElement(By.tagName('body'))
|
||||||
|
const attr = await body.getAttribute('loaded-dashboard')
|
||||||
|
if (attr) {
|
||||||
|
console.log('Current loaded-dashboard attribute:', attr)
|
||||||
|
}
|
||||||
|
// Accept either decoded or encoded version (component should decode, but handle both)
|
||||||
|
return attr === 'LightDashboard'
|
||||||
|
}), 10000)
|
||||||
|
|
||||||
// Find "Turn On Light" button for "Living Room Light" (powered_on: false, so Turn On should be enabled)
|
// Verify we got the correct dashboard (prefer decoded, but accept encoded)
|
||||||
// Find "Turn Off Light" button for "Bedroom Light" (powered_on: true, so Turn Off should be enabled)
|
const body = await webdriver.findElement(By.tagName('body'))
|
||||||
|
const attr = await body.getAttribute('loaded-dashboard')
|
||||||
|
if (attr !== 'LightDashboard') {
|
||||||
|
const currentUrl = await webdriver.getCurrentUrl()
|
||||||
|
throw new Error(`Dashboard not loaded correctly. Expected "LightDashboard", got "${attr}". Current URL: ${currentUrl}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for dashboard content to appear - check for dashboard rows first
|
||||||
|
await webdriver.wait(until.elementsLocated(By.css('.dashboard-row')), 5000)
|
||||||
|
|
||||||
|
// Debug: Check what's on the page
|
||||||
|
const dashboardRows = await webdriver.findElements(By.css('.dashboard-row'))
|
||||||
|
console.log(`Found ${dashboardRows.length} dashboard rows`)
|
||||||
|
|
||||||
|
for (let i = 0; i < dashboardRows.length; i++) {
|
||||||
|
const row = dashboardRows[i]
|
||||||
|
const h2Elements = await row.findElements(By.css('h2'))
|
||||||
|
if (h2Elements.length > 0) {
|
||||||
|
const h2Text = await h2Elements[0].getText()
|
||||||
|
console.log(`Row ${i} h2: "${h2Text}"`)
|
||||||
|
}
|
||||||
|
const fieldsets = await row.findElements(By.css('fieldset'))
|
||||||
|
console.log(`Row ${i} has ${fieldsets.length} fieldsets`)
|
||||||
|
if (fieldsets.length > 0) {
|
||||||
|
const buttons = await fieldsets[0].findElements(By.css('.action-button button'))
|
||||||
|
console.log(`Row ${i} fieldset has ${buttons.length} buttons`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find buttons by looking within entity fieldsets
|
||||||
|
// Both rows have h2 title "Light Controls", so we identify them by which buttons are enabled
|
||||||
|
// Living Room Light (powered_on: false) - Turn On should be enabled, Turn Off disabled
|
||||||
|
// Bedroom Light (powered_on: true) - Turn Off should be enabled, Turn On disabled
|
||||||
let turnOnButton = null
|
let turnOnButton = null
|
||||||
let turnOffButton = null
|
let turnOffButton = null
|
||||||
|
|
||||||
for (const btn of actionButtons) {
|
for (const row of dashboardRows) {
|
||||||
const title = await btn.getAttribute('title')
|
// Get the fieldset in this row
|
||||||
if (title && title.includes('Turn On Light') && title.includes('Living Room')) {
|
const fieldsets = await row.findElements(By.css('fieldset'))
|
||||||
turnOnButton = btn
|
if (fieldsets.length === 0) continue
|
||||||
}
|
|
||||||
if (title && title.includes('Turn Off Light') && title.includes('Bedroom')) {
|
const buttons = await fieldsets[0].findElements(By.css('.action-button button'))
|
||||||
turnOffButton = btn
|
|
||||||
|
// Check each button to identify which entity this row represents
|
||||||
|
for (const btn of buttons) {
|
||||||
|
const title = await btn.getAttribute('title')
|
||||||
|
const disabled = await btn.getAttribute('disabled')
|
||||||
|
const isEnabled = disabled === null
|
||||||
|
|
||||||
|
if (title === 'Turn On Light' && isEnabled) {
|
||||||
|
// This is the Living Room Light row (Turn On is enabled because powered_on: false)
|
||||||
|
turnOnButton = btn
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title === 'Turn Off Light' && isEnabled) {
|
||||||
|
// This is the Bedroom Light row (Turn Off is enabled because powered_on: true)
|
||||||
|
turnOffButton = btn
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue