diff --git a/src/components/ProjectSelect.client.test.tsx b/src/components/ProjectSelect.client.test.tsx new file mode 100644 index 00000000..e40e042f --- /dev/null +++ b/src/components/ProjectSelect.client.test.tsx @@ -0,0 +1,31 @@ +import { render } from 'solid-js/web'; +import { afterEach, describe, expect, it } from 'vitest'; +import { setStore } from '../store/core'; +import { ProjectSelect } from './ProjectSelect'; + +const disposers: Array<() => void> = []; + +afterEach(() => { + while (disposers.length > 0) disposers.pop()?.(); + document.body.replaceChildren(); + setStore('projects', []); +}); + +describe('ProjectSelect', () => { + it('lists projects alphabetically by name', () => { + setStore('projects', [ + { id: 'zulu', name: 'Zulu', path: '/zulu', color: '' }, + { id: 'alpha', name: 'alpha', path: '/alpha', color: '' }, + { id: 'beta', name: 'Beta', path: '/beta', color: '' }, + ]); + const container = document.createElement('div'); + document.body.append(container); + disposers.push( + render(() => undefined} />, container), + ); + + expect( + Array.from(container.querySelectorAll('option'), (option) => option.textContent), + ).toEqual(['alpha — /alpha', 'Beta — /beta', 'Zulu — /zulu']); + }); +}); diff --git a/src/components/ProjectSelect.tsx b/src/components/ProjectSelect.tsx index d648bfe4..26ec7fb1 100644 --- a/src/components/ProjectSelect.tsx +++ b/src/components/ProjectSelect.tsx @@ -20,7 +20,7 @@ export function ProjectSelect(props: ProjectSelectProps) { {props.placeholder} - + a.name.localeCompare(b.name))}> {(project) => (