feat(embed): session sidebar grouping and embed theme alignment (#1657)
Group embed sessions in the sidebar by channel, replace session source filter with grouping buckets, and align shared chat components with embed theme colors.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
applyBucketCountProbe,
|
||||
bucketVisible,
|
||||
createEmptyBucket,
|
||||
prependSessionToWebBucket,
|
||||
type BucketDefinition,
|
||||
} from './sessionSidebarBuckets.ts'
|
||||
|
||||
const imDef: BucketDefinition = {
|
||||
key: 'im:feishu',
|
||||
apiSource: 'feishu',
|
||||
label: 'Feishu',
|
||||
kind: 'im',
|
||||
platform: 'feishu',
|
||||
}
|
||||
|
||||
test('bucketVisible hides channel buckets until count is known', () => {
|
||||
const bucket = createEmptyBucket(imDef)
|
||||
assert.equal(bucketVisible(bucket), false)
|
||||
})
|
||||
|
||||
test('bucketVisible hides channel buckets with zero sessions after probe', () => {
|
||||
const bucket = applyBucketCountProbe(createEmptyBucket(imDef), 0)
|
||||
assert.equal(bucketVisible(bucket), false)
|
||||
})
|
||||
|
||||
test('bucketVisible shows channel buckets with sessions after probe', () => {
|
||||
const bucket = applyBucketCountProbe(createEmptyBucket(imDef), 3)
|
||||
assert.equal(bucketVisible(bucket), true)
|
||||
})
|
||||
|
||||
test('prependSessionToWebBucket inserts new session at front and bumps total', () => {
|
||||
const webDef: BucketDefinition = {
|
||||
key: 'web',
|
||||
apiSource: 'web',
|
||||
label: 'Chats',
|
||||
kind: 'web',
|
||||
}
|
||||
const bucket = { ...createEmptyBucket(webDef), total: 2, items: [{ id: 'a' }] }
|
||||
const next = prependSessionToWebBucket(bucket, { id: 'b', title: 'New' })
|
||||
assert.deepEqual(next.items.map((s) => s.id), ['b', 'a'])
|
||||
assert.equal(next.total, 3)
|
||||
})
|
||||
|
||||
test('prependSessionToWebBucket is idempotent for existing session', () => {
|
||||
const webDef: BucketDefinition = {
|
||||
key: 'web',
|
||||
apiSource: 'web',
|
||||
label: 'Chats',
|
||||
kind: 'web',
|
||||
}
|
||||
const bucket = { ...createEmptyBucket(webDef), total: 1, items: [{ id: 'a' }] }
|
||||
const next = prependSessionToWebBucket(bucket, { id: 'a', title: 'Same' })
|
||||
assert.equal(next, bucket)
|
||||
})
|
||||
Reference in New Issue
Block a user