;;; noise-chat-list-test.el --- Tests for noise-chat-list -*- lexical-binding: t; -*- (require 'ert) (require 'noise-chat-list) (defun noise-chat-list-test--make-row (id name unread preview sender time) "Create a hash table representing a conversation row for testing." (let ((ht (make-hash-table :test 'equal))) (puthash "id" id ht) (puthash "name" name ht) (puthash "type" "direct" ht) (puthash "unread_count" unread ht) (puthash "last_message_preview" preview ht) (puthash "last_message_sender" sender ht) (puthash "last_message_time" time ht) ht)) (ert-deftest noise-chat-list--format-time-today () "Test relative time formatting for today shows HH:MM." (let ((result (noise-chat-list--format-time (float-time)))) (should (string-match "^[0-9][0-9]:[0-9][0-9]$" result)))) (ert-deftest noise-chat-list--format-time-yesterday () "Test relative time formatting for recent days." (let* ((one-day 86400) (yesterday (float-time (time-subtract (current-time) (seconds-to-time one-day)))) (result (noise-chat-list--format-time yesterday))) (should (string-match "^[A-Z][a-z][a-z]$" result)))) (ert-deftest noise-chat-list--format-time-older () "Test relative time formatting for older dates shows Mon DD." (let* ((two-weeks-ago (float-time (time-subtract (current-time) (seconds-to-time (* 14 86400)))))) (let ((result (noise-chat-list--format-time two-weeks-ago))) (should (string-match "^[A-Z][a-z][a-z] [0-9]+$" result))))) (ert-deftest noise-chat-list--format-row-with-unread () "Test formatting a conversation row with unread messages." (let ((row (noise-chat-list--format-row (noise-chat-list-test--make-row "conv-1" "Sarah" 3 "are you taking the girls?" "Sarah" (float-time))))) (should (string-match " 3" row)) (should (string-match "Sarah" row)) (should (string-match "are you taking" row)))) (ert-deftest noise-chat-list--format-row-no-unread () "Test formatting a conversation row without unread messages." (let ((row (noise-chat-list--format-row (noise-chat-list-test--make-row "conv-2" "Mark Okafor" 0 "merged" "me" (float-time))))) (should (string-match "Mark Okafor" row)) (should (string-match "^ " row))))