feat: prevent duplicate banner entries in recent history

Add duplicate detection to banner recording to prevent multiple entries
for the same banner ID in recent history. This prevents duplicate history
entries when pages refresh or banners are shown multiple times.

- Check if banner ID already exists in recentHistory before adding
- Return early if duplicate found to prevent adding same banner multiple times
- Add comprehensive tests for banner history functionality including:
  - Adding new banners to history
  - Preventing duplicate entries
  - Handling multiple different banners
- Clear history between tests to ensure test isolation
This commit is contained in:
Will Miao
2025-11-03 20:13:48 +08:00
parent 4862419b61
commit d73903e82e
2 changed files with 85 additions and 0 deletions

View File

@@ -348,6 +348,13 @@ class BannerService {
return;
}
// Check if banner with this ID already exists in recent history
// Only record if it's not already in history (prevents duplicates on page refresh)
const existingEntry = this.recentHistory.find(entry => entry.id === banner.id);
if (existingEntry) {
return; // Banner already exists in history, don't add again
}
const sanitizedActions = Array.isArray(banner.actions)
? banner.actions.map(action => ({
text: action.text,