Skip to content

Commit

Permalink
Made notes tool test even more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Oct 3, 2023
1 parent e72df4b commit 00d8271
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/tools/notes/notessaveload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ void NotesSaveLoad::buildChapters(const QStringList &folders, NoteBook &book) co
{
qCDebug(gmNotesSaveLoad()) << "Building chapters in book" << book.name() << folders;

bool createdNewChapters = false;

foreach (const auto &folder, folders)
{
bool exists = false;
Expand All @@ -360,6 +362,7 @@ void NotesSaveLoad::buildChapters(const QStringList &folders, NoteBook &book) co

if (!exists)
{
createdNewChapters = true;
const auto *chapter = new NoteBookChapter(folder, &book);
connect(chapter, &NoteBookChapter::loadPages, this, &NotesSaveLoad::loadPages);
connect(chapter, &NoteBookChapter::createPage, this, &NotesSaveLoad::createPage);
Expand All @@ -368,7 +371,10 @@ void NotesSaveLoad::buildChapters(const QStringList &folders, NoteBook &book) co
}
}

book.onChaptersLoaded();
if (createdNewChapters)
{
book.onChaptersLoaded();
}
}

/**
Expand Down Expand Up @@ -400,8 +406,11 @@ void NotesSaveLoad::buildPages(const QStringList &files, NoteBookChapter &chapte
}
}

chapter.onPagesLoaded();
emit pagesLoaded(pages);
if (!pages.isEmpty())
{
chapter.onPagesLoaded();
emit pagesLoaded(pages);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/testhelper/staticabstracttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void StaticAbstractTest::waitForSpy(QSignalSpy &spy, int count)

while (spy.count() < count)
{
ASSERT_TRUE(spy.wait());
ASSERT_TRUE(spy.wait()) << "current count: " << spy.count() << ", expected count: " << count;
}

ASSERT_EQ(spy.count(), count);
Expand Down
4 changes: 3 additions & 1 deletion tests/tools/notes/testnotestool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class NotesToolTest : public AbstractTest
QSignalSpy spy(book, &TreeItem::childItemsChanged);
book->create(book->creatables().at(0), u"chapter"_s);
StaticAbstractTest::waitForSpy(spy, 1);
spy.clear();

book->toggle();
StaticAbstractTest::waitForSpy(spy, 2);
StaticAbstractTest::waitForSpy(spy, 1);

chapter = qobject_cast<NoteBookChapter *>(book->childItems().at(0));
ASSERT_TRUE(chapter);
Expand Down

0 comments on commit 00d8271

Please sign in to comment.