From b6bae858a3ac781951ca303dd8d2553d4761f6fd Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Fri, 20 Aug 2021 09:30:39 +0200 Subject: [PATCH] Test suggestionList more thoroughly Particularly, verify natural instead of lexicographic sort order. --- 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']); }); });