Skip to content

Commit

Permalink
More QML and some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rozyczko committed Aug 15, 2024
1 parent 011501c commit 4bc8e15
Show file tree
Hide file tree
Showing 97 changed files with 245,831 additions and 146,796 deletions.
4 changes: 2 additions & 2 deletions easyDiffractionApp/Gui/Components/ApplicationWindow.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors <support@easydiffraction.org>
// SPDX-License-Identifier: BSD-3-Clause
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction>

import QtQuick
import QtQuick.Controls
Expand Down
4 changes: 2 additions & 2 deletions easyDiffractionApp/Gui/Components/CloseDialog.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors <support@easydiffraction.org>
// SPDX-License-Identifier: BSD-3-Clause
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction>

import QtQuick
import QtQuick.Controls
Expand Down
175 changes: 92 additions & 83 deletions easyDiffractionApp/Gui/Components/GuiTestsController.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors <support@easydiffraction.org>
// SPDX-License-Identifier: BSD-3-Clause
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction>

import QtQuick
import QtQuick.Controls
Expand All @@ -19,13 +19,15 @@ EaElements.RemoteController {

property int exitCode: 0
property var res: []
property string savedLoggingLevel

Timer {
running: true
interval: 1000
onTriggered: {
runBasicGuiTest()
processTestResults()
savedLoggingLevel = EaGlobals.Vars.loggingLevel
EaGlobals.Vars.loggingLevel = "Debug"
startGuiTest()
}
}

Expand All @@ -36,60 +38,40 @@ EaElements.RemoteController {
onTriggered: {
console.debug(`Starting forced exit timer`)
console.debug(`Calling python exit app helper from within QML with code ${exitCode}`)
EaGlobals.Vars.loggingLevel = savedLoggingLevel
Globals.Proxies.main.backendHelpers.exitApp(exitCode)
}
}

// Tests

function processTestResults() {
let okTests = 0
let failedTests = 0

console.info("============================ GUI TEST REPORT START =============================")

for (let i in res) {
if (res[i].startsWith('FAIL')) {
exitCode = 1
failedTests += 1
console.error(res[i])
} else {
okTests +=1
}
Timer {
running: Globals.Proxies.main.status.fitStatus
interval: 3000
onTriggered: {
finishGuiTest()
processTestResults()
}
}

console.info("--------------------------------------------------------------------------------")
console.info(`${res.length} total, ${res.length - failedTests} passed, ${failedTests} failed`)
console.info("============================= GUI TEST REPORT END ==============================")

console.debug(`Exiting application from QML with code ${exitCode}`)
//applicationWindow.close()
//Qt.callLater(Qt.exit, exitCode) // Doesn't work on GH Windows if running app via `python main.py`
Qt.exit(exitCode) // Doesn't work on GH Windows if running app via `python main.py`
// Tests

// Start timer to force python exit if normal way above doesn't work
exitTimer.start()
function saveImage(fileName, path='tests/gui/screenshots/actual') {
saveScreenshot(parent, `${path}/${fileName}`)
}

function saveImage(dirName, fileName) {
saveScreenshot(parent, `${dirName}/${fileName}`)
}
function startGuiTest() {
console.debug('Start basic suit of GUI tests (step 1 of 2)')

function runBasicGuiTest() {
/////////////////////////
// Set up testing process
/////////////////////////

console.debug('Run basic suit of GUI tests')

//const saveImagesDir = '../.tests/GuiTests/BasicGuiTest/ActualImages'

rc.posToCenter()
rc.showPointer()



////////////
// Home Page

//saveImage(saveImagesDir, 'HomePage.png')
////////////

res.push( rc.compare(Globals.Refs.app.appbar.homeButton.enabled, true) )
res.push( rc.compare(Globals.Refs.app.appbar.projectButton.enabled, false) )
Expand All @@ -101,14 +83,13 @@ EaElements.RemoteController {
res.push( rc.compare(Globals.Refs.app.homePage.startButton.text, 'Start') )
res.push( rc.compare(Globals.Refs.app.homePage.startButton.enabled, true) )

saveImage('HomePage.png')
rc.mouseClick(Globals.Refs.app.homePage.startButton)
//rc.wait(2000)



///////////////
// Project Page

//saveImage(saveImagesDir, 'ProjectPage.png')
///////////////

res.push( rc.compare(Globals.Refs.app.appbar.homeButton.enabled, true) )
res.push( rc.compare(Globals.Refs.app.appbar.projectButton.enabled, true) )
Expand All @@ -122,15 +103,12 @@ EaElements.RemoteController {

res.push( rc.compare(Globals.Proxies.main.status.project, 'Undefined') )

saveImage('ProjectPage.png')
rc.mouseClick(Globals.Refs.app.projectPage.continueButton)
//rc.wait(2000)




/////////////
// Model Page

//saveImage(saveImagesDir, 'ModelPage.png')
/////////////

res.push( rc.compare(Globals.Refs.app.appbar.homeButton.enabled, true) )
res.push( rc.compare(Globals.Refs.app.appbar.projectButton.enabled, true) )
Expand Down Expand Up @@ -158,18 +136,17 @@ EaElements.RemoteController {
//res.push( rc.compare(parseFloat(Globals.Refs.app.modelPage.widthParameter.text), Tests.NoProjectCreated.expected.model[0].params.width.value) )
//res.push( rc.compare(parseFloat(Globals.Refs.app.modelPage.scaleParameter.text), Tests.NoProjectCreated.expected.model[0].params.scale.value) )

// res.push( rc.compare(Globals.Refs.app.modelPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
// res.push( rc.compare(Globals.Refs.app.modelPage.plotView.calculatedYData, Globals.Tests.expected.created.model.yData) )
//res.push( rc.compare(Globals.Refs.app.modelPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
//res.push( rc.compare(Globals.Refs.app.modelPage.plotView.calculatedYData, Globals.Tests.expected.created.model.yData) )

res.push( rc.compare(Globals.Proxies.main.status.phaseCount, '2') )

saveImage('ModelPage.png')
rc.mouseClick(Globals.Refs.app.modelPage.continueButton)
//rc.wait(2000)


//////////////////
// Experiment page

//saveImage(saveImagesDir, 'ExperimentPage.png')
//////////////////

res.push( rc.compare(Globals.Refs.app.appbar.homeButton.enabled, true) )
res.push( rc.compare(Globals.Refs.app.appbar.projectButton.enabled, true) )
Expand All @@ -188,24 +165,21 @@ EaElements.RemoteController {
rc.mouseClick(Globals.Refs.app.experimentPage.importDataFromLocalDriveButton)
rc.wait(2000)

res.push( rc.compare(Globals.Refs.app.experimentPage.importDataFromLocalDriveButton.enabled, true) )
res.push( rc.compare(Globals.Refs.app.experimentPage.importDataFromLocalDriveButton.enabled, false) )
res.push( rc.compare(Globals.Refs.app.experimentPage.addDefaultExperimentDataButton.enabled, false) )
res.push( rc.compare(Globals.Refs.app.experimentPage.continueButton.text, 'Continue') )

// res.push( rc.compare(Globals.Refs.app.modelPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
// res.push( rc.compare(Globals.Refs.app.experimentPage.plotView.measuredYData, Globals.Tests.expected.created.experiment.yData) )
//res.push( rc.compare(Globals.Refs.app.modelPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
//res.push( rc.compare(Globals.Refs.app.experimentPage.plotView.measuredYData, Globals.Tests.expected.created.experiment.yData) )

res.push( rc.compare(Globals.Proxies.main.status.experimentsCount, '1') )

saveImage('ExperimentPage.png')
rc.mouseClick(Globals.Refs.app.experimentPage.continueButton)
//rc.wait(2000)




////////////////
// Analysis page

//saveImage(saveImagesDir, 'AnalysisPage.png')
////////////////

res.push( rc.compare(Globals.Refs.app.appbar.homeButton.enabled, true) )
res.push( rc.compare(Globals.Refs.app.appbar.projectButton.enabled, true) )
Expand All @@ -220,27 +194,31 @@ EaElements.RemoteController {
res.push( rc.compare(Globals.Refs.app.analysisPage.continueButton.enabled, false) )

res.push( rc.compare(Globals.Proxies.main.status.calculator, 'CrysPy') )
res.push( rc.compare(Globals.Proxies.main.status.minimizer, 'Lmfit (BFGS)') )
res.push( rc.compare(Globals.Proxies.main.status.minimizer, 'Lmfit (leastsq)') )

rc.wait(2000)

// res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
// res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.measuredYData, Globals.Tests.expected.created.experiment.yData) )
// res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.calculatedYData, Globals.Tests.expected.created.model.yData) )
//res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
//res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.measuredYData, Globals.Tests.expected.created.experiment.yData) )
//res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.calculatedYData, Globals.Tests.expected.created.model.yData) )

saveImage('AnalysisPage.png')
rc.mouseClick(Globals.Refs.app.analysisPage.startFittingButton)
}

console.debug('Waiting 80 secons for minimization step to be finished')
rc.wait(80000)
//rc.mouseClick(Globals.Refs.app.analysisPage.startFittingButton)
//rc.wait(3000)
function finishGuiTest() {
console.debug('Finish basic suit of GUI tests (step 2 of 2)')

// res.push( rc.compare(Globals.Refs.app.modelPage.slopeParameter.text, Globals.Tests.expected.fitted.model.parameters.slope.value) )
// res.push( rc.compare(Globals.Refs.app.modelPage.yInterceptParameter.text, Globals.Tests.expected.fitted.model.parameters.yIntercept.value) )
////////////////
// Analysis page
////////////////

//res.push( rc.compare(Globals.Refs.app.modelPage.slopeParameter.text, Globals.Tests.expected.fitted.model.parameters.slope.value) )
//res.push( rc.compare(Globals.Refs.app.modelPage.yInterceptParameter.text, Globals.Tests.expected.fitted.model.parameters.yIntercept.value) )

// res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
// res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.measuredYData, Globals.Tests.expected.created.experiment.yData) )
// res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.calculatedYData, Globals.Tests.expected.fitted.model.yData) )
//res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.xData, Globals.Tests.expected.created.experiment.xData) )
//res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.measuredYData, Globals.Tests.expected.created.experiment.yData) )
//res.push( rc.compare(Globals.Refs.app.analysisPage.plotView.calculatedYData, Globals.Tests.expected.fitted.model.yData) )

rc.mouseClick(Globals.Refs.app.analysisPage.fitStatusDialogOkButton)

Expand All @@ -252,18 +230,49 @@ EaElements.RemoteController {
rc.mouseClick(Globals.Refs.app.analysisPage.continueButton)
//rc.wait(2000)



///////////////
// Summary page
///////////////

//saveImage(saveImagesDir, 'SummaryPage.png')
saveImage('SummaryPage.png')

///////////////////////////
// Complete testing process
///////////////////////////

// rc.mouseClick(Globals.Refs.app.appbar.resetStateButton)
//rc.mouseClick(Globals.Refs.app.appbar.resetStateButton)
rc.wait(2000)

rc.hidePointer()
}

function processTestResults() {
let okTests = 0
let failedTests = 0

console.info("============================ GUI TEST REPORT START =============================")

for (let i in res) {
if (res[i].startsWith('FAIL')) {
exitCode = 1
failedTests += 1
console.error(res[i])
} else {
okTests +=1
}
}

console.info("--------------------------------------------------------------------------------")
console.info(`${res.length} total, ${res.length - failedTests} passed, ${failedTests} failed`)
console.info("============================= GUI TEST REPORT END ==============================")

console.debug(`Exiting application from QML with code ${exitCode}`)
//applicationWindow.close()
//Qt.callLater(Qt.exit, exitCode) // Doesn't work on GH Windows if running app via `python main.py`
Qt.exit(exitCode) // Doesn't work on GH Windows if running app via `python main.py`

// Start timer to force python exit if normal way above doesn't work
exitTimer.start()
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors <support@easydiffraction.org>
// SPDX-License-Identifier: BSD-3-Clause
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction>

import QtQuick
import QtQuick.Controls
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors
// SPDX-FileCopyrightText: 2023 EasyDiffraction contributors <support@easydiffraction.org>
// SPDX-License-Identifier: BSD-3-Clause
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffractionApp>
// © 2023 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction>

import QtQuick
import QtQuick.Controls
Expand Down Expand Up @@ -52,12 +52,22 @@ Column {
EaCharts.QtCharts1dBase {
id: mainChart

property var experimentDataBlocksNoMeas: Globals.Proxies.main.experiment.dataBlocksNoMeas
onExperimentDataBlocksNoMeasChanged: {
if (Globals.Proxies.experimentMainParam('_diffrn_radiation', 'type').value === 'cwl') {
axisX.title = '2θ (degree)'
} else if (Globals.Proxies.experimentMainParam('_diffrn_radiation', 'type').value === 'tof') {
axisX.title = 'TOF (µs)'
} else {
axisX.title = ''
}
}

anchors.topMargin: EaStyle.Sizes.toolButtonHeight - EaStyle.Sizes.fontPixelSize - 1
anchors.bottomMargin: -12 - EaStyle.Sizes.fontPixelSize

useOpenGL: container.useOpenGL

axisX.title: "2θ (degree)"
axisX.titleVisible: false
axisX.labelsVisible: false
axisX.min: Globals.Proxies.rangeValue('xMin')
Expand Down Expand Up @@ -98,7 +108,7 @@ Column {
axisX: mainChart.axisX
axisY: mainChart.axisY

useOpenGL: mainChart.useOpenGL
//useOpenGL: mainChart.useOpenGL

color: EaStyle.Colors.chartForegroundsExtra[2]
width: 2
Expand All @@ -115,7 +125,7 @@ Column {
axisX: mainChart.axisX
axisY: mainChart.axisY

useOpenGL: mainChart.useOpenGL
//useOpenGL: mainChart.useOpenGL

color: EaStyle.Colors.chartForegrounds[1]
width: 1
Expand All @@ -130,7 +140,7 @@ Column {
axisX: mainChart.axisX
axisY: mainChart.axisY

useOpenGL: mainChart.useOpenGL
//useOpenGL: mainChart.useOpenGL

color: calcSerieColor
width: 2
Expand Down Expand Up @@ -304,7 +314,7 @@ Column {
axisX: residualChart.axisX
axisY: residualChart.axisY

useOpenGL: residualChart.useOpenGL
//useOpenGL: residualChart.useOpenGL

color: EaStyle.Colors.chartForegrounds[2]

Expand Down
Loading

0 comments on commit 4bc8e15

Please sign in to comment.