From b09b29555c234e97d66b95551db7160dd440326d Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Mon, 30 Sep 2024 15:15:00 +0200 Subject: [PATCH] Test suggestionList more thoroughly (#3241) Particularly, verify that it first sorts by lexicographic distance and then naturally. --- src/jsutils/__tests__/suggestionList-test.ts | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/jsutils/__tests__/suggestionList-test.ts b/src/jsutils/__tests__/suggestionList-test.ts index 06719d8a1e..8a9a05c438 100644 --- a/src/jsutils/__tests__/suggestionList-test.ts +++ b/src/jsutils/__tests__/suggestionList-test.ts @@ -57,13 +57,44 @@ describe('suggestionList', () => { 'ab', 'a', ]); + + expectSuggestions('GraphQl', [ + 'graphics', + 'SQL', + 'GraphQL', + 'quarks', + 'mark', + ]).to.deep.equal(['GraphQL', 'graphics']); }); - it('Returns options with the same lexical distance sorted lexicographically', () => { + it('Returns options with the same lexical distance sorted naturally', () => { expectSuggestions('a', ['az', 'ax', 'ay']).to.deep.equal([ 'ax', 'ay', 'az', ]); + + expectSuggestions('boo', ['moo', 'foo', 'zoo']).to.deep.equal([ + 'foo', + 'moo', + 'zoo', + ]); + + expectSuggestions('abc', ['a1', 'a12', 'a2']).to.deep.equal([ + 'a1', + 'a2', + 'a12', + ]); + }); + + it('Returns options sorted first by lexical distance then naturally', () => { + // cSpell:ignore csutomer, stomer + expectSuggestions('csutomer', [ + 'store', + 'customer', + 'stomer', + 'some', + 'more', + ]).to.deep.equal(['customer', 'stomer', 'some', 'store']); }); });