Step 169: notification system
This commit is contained in:
41
editor/tests/step169_integration_test.cpp
Normal file
41
editor/tests/step169_integration_test.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Step 169: Notification system integration wiring checks.
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static std::string readFile(const std::string& path) {
|
||||
std::ifstream f(path);
|
||||
if (!f.is_open()) return {};
|
||||
return std::string((std::istreambuf_iterator<char>(f)),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
|
||||
static void assertContains(const std::string& text, const std::string& needle) {
|
||||
assert(text.find(needle) != std::string::npos);
|
||||
}
|
||||
|
||||
int main() {
|
||||
assert(fs::exists("src/NotificationSystem.h"));
|
||||
|
||||
const std::string editorState = readFile("src/EditorState.h");
|
||||
assertContains(editorState, "NotificationSystem");
|
||||
assertContains(editorState, "notifications");
|
||||
|
||||
const std::string statusBar = readFile("src/panels/StatusBarPanel.h");
|
||||
assertContains(statusBar, "Notifications");
|
||||
assertContains(statusBar, "state.notifications");
|
||||
|
||||
const std::string mainCpp = readFile("src/main.cpp");
|
||||
assertContains(mainCpp, "renderHistoryWindow");
|
||||
assertContains(mainCpp, "renderToasts");
|
||||
|
||||
const std::string bottomPanel = readFile("src/panels/BottomPanel.h");
|
||||
assertContains(bottomPanel, "state.notifications");
|
||||
|
||||
printf("step169_integration_test: all assertions passed\n");
|
||||
return 0;
|
||||
}
|
||||
48
editor/tests/step169_test.cpp
Normal file
48
editor/tests/step169_test.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Step 169: Notification system unit checks.
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
#include "NotificationSystem.h"
|
||||
|
||||
static const Notification* findById(const std::vector<Notification>& list, int id) {
|
||||
for (const auto& n : list) {
|
||||
if (n.id == id) return &n;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main() {
|
||||
NotificationSystem notifications;
|
||||
notifications.toastDurationSeconds = 5.0f;
|
||||
|
||||
notifications.notifyAt(NotificationLevel::Info, "hello", 1.0);
|
||||
assert(notifications.getHistory().size() == 1);
|
||||
assert(notifications.unreadCount() == 1);
|
||||
|
||||
NotificationTarget target;
|
||||
target.path = "C:\\temp\\example.cpp";
|
||||
target.line = 2;
|
||||
target.col = 5;
|
||||
notifications.notifyAt(NotificationLevel::Error, "boom", 2.0, &target);
|
||||
assert(notifications.getHistory().size() == 2);
|
||||
|
||||
const Notification& last = notifications.getHistory().back();
|
||||
assert(last.hasTarget);
|
||||
assert(last.target.path == target.path);
|
||||
assert(last.target.line == target.line);
|
||||
assert(last.target.col == target.col);
|
||||
|
||||
int id = last.id;
|
||||
notifications.dismiss(id);
|
||||
const Notification* found = findById(notifications.getHistory(), id);
|
||||
assert(found);
|
||||
assert(found->dismissed);
|
||||
assert(found->read);
|
||||
|
||||
notifications.markAllRead();
|
||||
assert(notifications.unreadCount() == 0);
|
||||
|
||||
printf("step169_test: all assertions passed\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user