Add frozen TikZRefinery demo baseline and build pipeline
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "ui/tkrFolderBrowser.h"
|
||||
#include "ui/tkrMainWindow.h"
|
||||
#include "ui/tkrShapePalette.h"
|
||||
#include "ui/tkrWorkspaceSidebar.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPointer>
|
||||
#include <QPushButton>
|
||||
#include <QSplitter>
|
||||
#include <QTemporaryDir>
|
||||
#include <QToolButton>
|
||||
#include <QtDebug>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace TikzRefinery;
|
||||
|
||||
namespace {
|
||||
constexpr int iSidebarTestWidth = 350;
|
||||
constexpr int iWorkspaceTestWidth = 1000;
|
||||
constexpr int iSidebarPaneIndex = 0;
|
||||
constexpr int iWidthTolerancePixels = 2;
|
||||
constexpr int iNoRequests = 0;
|
||||
constexpr int iOneRequest = 1;
|
||||
const QByteArray baFixture("\\path[use as bounding box] (-2cm,-2cm) rectangle (8cm,6cm);\n"
|
||||
"\\draw (0cm,0cm) rectangle (2cm,1cm);\n");
|
||||
|
||||
void require(bool bCondition, const char *pMessage)
|
||||
{
|
||||
if (!bCondition) qFatal("%s", pMessage);
|
||||
}
|
||||
|
||||
void checkSidebar()
|
||||
{
|
||||
QTemporaryDir directory;
|
||||
require(directory.isValid(), "Cannot create sidebar fixture directory");
|
||||
const QString strPath = directory.filePath(QStringLiteral("sidebar.tex"));
|
||||
QFile file(strPath);
|
||||
require(file.open(QIODevice::WriteOnly), "Cannot write sidebar fixture");
|
||||
require(file.write(baFixture) == baFixture.size(), "Incomplete sidebar fixture write");
|
||||
file.close();
|
||||
QPointer<tkrWorkspaceSidebar> pObservedSidebar;
|
||||
QPointer<tkrShapePalette> pObservedPalette;
|
||||
{
|
||||
tkrMainWindow window(nullptr, strPath);
|
||||
window.show();
|
||||
QApplication::processEvents();
|
||||
auto *pSidebar = window.findChild<tkrWorkspaceSidebar *>();
|
||||
auto *pSplitter = window.findChild<QSplitter *>(QStringLiteral("workspaceSplitter"));
|
||||
auto *pSource = window.findChild<QPlainTextEdit *>();
|
||||
require(pSidebar && pSplitter && pSource, "Sidebar or editor assembly missing");
|
||||
auto *pShapes = pSidebar->findChild<QToolButton *>(QStringLiteral("workspaceShapesTab"));
|
||||
auto *pFiles = pSidebar->findChild<QToolButton *>(QStringLiteral("workspaceFilesTab"));
|
||||
auto *pCollapse = pSidebar->findChild<QToolButton *>(QStringLiteral("workspaceCollapseButton"));
|
||||
auto *pContent = pSidebar->findChild<QWidget *>(QStringLiteral("workspaceSidebarContent"));
|
||||
auto *pCreate = pSidebar->findChild<QPushButton *>(QStringLiteral("createShapeButton"));
|
||||
require(pShapes && pFiles && pCollapse && pContent && pCreate, "Sidebar controls missing");
|
||||
require(!pShapes->icon().isNull() && !pFiles->icon().isNull(), "Tab icons missing");
|
||||
require(pShapes->accessibleName() != pFiles->accessibleName()
|
||||
&& !pShapes->toolTip().isEmpty() && !pFiles->toolTip().isEmpty(), "Tab identification missing");
|
||||
require(!pCreate->isEnabled() && !pCreate->toolTip().isEmpty(), "Unimplemented creation must be unavailable");
|
||||
const QString strSource = pSource->toPlainText();
|
||||
require(strSource.toUtf8() == baFixture && !window.isWindowModified(), "Opening fixture changed source");
|
||||
pSplitter->setSizes({iSidebarTestWidth, iWorkspaceTestWidth});
|
||||
QApplication::processEvents();
|
||||
const int iExpandedWidth = pSplitter->sizes().at(iSidebarPaneIndex);
|
||||
pCollapse->click();
|
||||
QApplication::processEvents();
|
||||
require(pSidebar->isCollapsed() && !pContent->isVisible() && pShapes->isVisible()
|
||||
&& pFiles->isVisible(), "Collapse must retain a visible tab strip");
|
||||
pFiles->click();
|
||||
QApplication::processEvents();
|
||||
require(!pSidebar->isCollapsed() && pSidebar->selectedPage() == tkrWorkspaceSidebar::Page::Files
|
||||
&& pFiles->isChecked() && !pShapes->isChecked(), "Files tab did not reopen its page");
|
||||
require(qAbs(pSidebar->width() - iExpandedWidth) <= iWidthTolerancePixels, "Expanded width was not restored");
|
||||
pFiles->click();
|
||||
QApplication::processEvents();
|
||||
require(pSidebar->isCollapsed() && pSidebar->selectedPage() == tkrWorkspaceSidebar::Page::Files,
|
||||
"Selected tab must toggle collapse without losing the page");
|
||||
pFiles->click();
|
||||
QApplication::processEvents();
|
||||
require(!pSidebar->isCollapsed() && pSidebar->selectedPage() == tkrWorkspaceSidebar::Page::Files,
|
||||
"Selected collapsed tab must reopen the retained page");
|
||||
pShapes->click();
|
||||
QApplication::processEvents();
|
||||
require(pSidebar->selectedPage() == tkrWorkspaceSidebar::Page::Shapes && pShapes->isChecked(),
|
||||
"Shapes tab did not activate");
|
||||
require(pSource->toPlainText() == strSource && !window.isWindowModified(),
|
||||
"Sidebar navigation must not edit or dirty the document");
|
||||
pObservedSidebar = pSidebar;
|
||||
pObservedPalette = window.findChild<tkrShapePalette *>();
|
||||
require(pObservedPalette, "Shapes page missing");
|
||||
}
|
||||
require(pObservedSidebar.isNull() && pObservedPalette.isNull(), "Window teardown did not release sidebar/pages");
|
||||
QFile saved(strPath);
|
||||
require(saved.open(QIODevice::ReadOnly) && saved.readAll() == baFixture, "Sidebar browsing changed the file");
|
||||
}
|
||||
|
||||
void checkFilesRequest()
|
||||
{
|
||||
tkrFolderBrowser browser;
|
||||
int iRequests = iNoRequests;
|
||||
QObject::connect(&browser, &tkrFolderBrowser::openDocumentRequested, &browser, [&iRequests]() { ++iRequests; });
|
||||
auto *pOpen = browser.findChild<QPushButton *>(QStringLiteral("sidebarOpenDocumentButton"));
|
||||
require(pOpen && pOpen->isEnabled(), "Files shell must retain an available Open entry point");
|
||||
pOpen->click();
|
||||
require(iRequests == iOneRequest, "Open request must be emitted exactly once");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int iArgumentCount, char **pArguments)
|
||||
{
|
||||
QApplication application(iArgumentCount, pArguments);
|
||||
checkSidebar();
|
||||
checkFilesRequest();
|
||||
qInfo("Sidebar collapse/reopen, page/width retention, accessible tabs, unavailable creation, source preservation and teardown passed.");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user