From bb2eeaa79d6497cbfa82c53a0424eb3668675c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Wed, 18 Sep 2024 13:10:02 +0200 Subject: [PATCH] Storybook: TestUtils singleton added --- storybook/src/Storybook/TestUtils.qml | 42 +++++++++++++++++++++++++++ storybook/src/Storybook/qmldir | 1 + 2 files changed, 43 insertions(+) create mode 100644 storybook/src/Storybook/TestUtils.qml diff --git a/storybook/src/Storybook/TestUtils.qml b/storybook/src/Storybook/TestUtils.qml new file mode 100644 index 0000000000..2b717b0a51 --- /dev/null +++ b/storybook/src/Storybook/TestUtils.qml @@ -0,0 +1,42 @@ +pragma Singleton + +import QtQuick 2.15 + +import QtQml 2.15 + +QtObject { + function findTextItem(root, text) { + for (let i = 0; i < root.children.length; i++) { + const c = root.children[i] + + if (c instanceof Text && c.text === text) + return c + + const sub = findTextItem(c, text) + + if (sub) + return sub + } + + return null + } + + function findByType(root, type) { + const children = [] + + for (let i = 0; i < root.children.length; i++) + children.push(root.children[i]) + + while (children.length > 0) { + const c = children.shift() + + if (c instanceof type) + return c + + for (let i = 0; i < c.children.length; i++) + children.push(c.children[i]) + } + + return null + } +} diff --git a/storybook/src/Storybook/qmldir b/storybook/src/Storybook/qmldir index d78ff1145c..4bdfa75983 100644 --- a/storybook/src/Storybook/qmldir +++ b/storybook/src/Storybook/qmldir @@ -33,3 +33,4 @@ TestRunnerControls 1.0 TestRunnerControls.qml singleton FigmaUtils 1.0 FigmaUtils.qml singleton InspectionUtils 1.0 InspectionUtils.qml singleton StorybookUtils 1.0 StorybookUtils.qml +singleton TestUtils 1.0 TestUtils.qml