mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-06 00:02:13 +00:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FqHuykfRrkDHj9dHCJQQcE
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { alphabetical, byPopularity } from './pickerPopularity'
|
|
|
|
const order = (names: string[], hub: Record<string, number>, local: Record<string, number> = {}) =>
|
|
[...names].sort(byPopularity(hub, local))
|
|
|
|
describe('byPopularity', () => {
|
|
it('ranks hub picks above local usage', () => {
|
|
expect(order(['slack', 'stripe'], { slack: 1 }, { stripe: 40 })).toEqual(['slack', 'stripe'])
|
|
})
|
|
|
|
it('breaks a hub tie on local usage', () => {
|
|
expect(order(['slack', 'stripe'], { slack: 5, stripe: 5 }, { stripe: 2 })).toEqual([
|
|
'stripe',
|
|
'slack'
|
|
])
|
|
})
|
|
|
|
it('falls back to alphabetical for everything neither signal ranks', () => {
|
|
expect(order(['stripe', 'ably', 'github'], { github: 3 })).toEqual(['github', 'ably', 'stripe'])
|
|
})
|
|
|
|
it('orders on local usage alone when the hub ranks nothing', () => {
|
|
expect(order(['stripe', 'ably', 'github'], {}, { stripe: 1 })).toEqual([
|
|
'stripe',
|
|
'ably',
|
|
'github'
|
|
])
|
|
})
|
|
|
|
// The lists render before either signal lands, and one of them arrives in a server-side
|
|
// HashMap's iteration order, so the resting comparator has to sort rather than no-op.
|
|
it('leaves an alphabetical order with no signal at all', () => {
|
|
expect(['stripe', 'ably', 'github'].sort(alphabetical)).toEqual(['ably', 'github', 'stripe'])
|
|
})
|
|
})
|