aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/services/chat_service/chat_service.spec.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2021-03-08 22:01:28 +0200
committerHenry Jameson <me@hjkos.com>2021-03-08 22:01:28 +0200
commit2e7bd99444546b3a71e1ff0753e12e6706c8228e (patch)
treeb01067c88bc969041d23392e7e34c976fae7b801 /test/unit/specs/services/chat_service/chat_service.spec.js
parent9a8bc245a6f76f1a41da9d05408dadc36625ffe9 (diff)
parent6281241b92bc17a9535b15a52e656b9f218e3322 (diff)
Merge remote-tracking branch 'origin/develop' into websocket-fixes
* origin/develop: (119 commits) Apply 1 suggestion(s) to 1 file(s) Make it possible to localize user highlight options remove shoutbox test hacks fix shoutbox header, use custom scroll-to-bottom system, remove vue-chat-scroll, temporarily add chat test hack update changelog with 2.3.0 change icons around Translated using Weblate (Japanese) Update timeline_quick_settings.js add screen_name_ui to tests separate screen_name and screen_name_ui with decoded punycode Update CHANGELOG.md add basic validation for statusless status notifications changelog mention fix chat unread badge update shelljs to get rid of warnings on build save a few characters focus input in emoji picker and react picker fix vue warnings add only to wording basic loggedin check for reply filtering ...
Diffstat (limited to 'test/unit/specs/services/chat_service/chat_service.spec.js')
-rw-r--r--test/unit/specs/services/chat_service/chat_service.spec.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/unit/specs/services/chat_service/chat_service.spec.js b/test/unit/specs/services/chat_service/chat_service.spec.js
index 0251cae7..fbbca436 100644
--- a/test/unit/specs/services/chat_service/chat_service.spec.js
+++ b/test/unit/specs/services/chat_service/chat_service.spec.js
@@ -88,4 +88,21 @@ describe('chatService', () => {
expect(view.map(i => i.type)).to.eql(['date', 'message', 'message', 'date', 'message'])
})
})
+
+ describe('.cullOlderMessages', () => {
+ it('keeps 50 newest messages and idIndex matches', () => {
+ const chat = chatService.empty()
+
+ for (let i = 100; i > 0; i--) {
+ // Use decimal values with toFixed to hack together constant length predictable strings
+ chatService.add(chat, { messages: [{ ...message1, id: 'a' + (i / 1000).toFixed(3), idempotency_key: i }] })
+ }
+ chatService.cullOlderMessages(chat)
+ expect(chat.messages.length).to.eql(50)
+ expect(chat.messages[0].id).to.eql('a0.051')
+ expect(chat.minId).to.eql('a0.051')
+ expect(chat.messages[49].id).to.eql('a0.100')
+ expect(Object.keys(chat.idIndex).length).to.eql(50)
+ })
+ })
})