/
get-quick-info-at-position.test.ts
53 lines (50 loc) · 1.42 KB
/
get-quick-info-at-position.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import ts from 'typescript';
import { GraphQLSchema } from 'graphql';
import { mark, Frets } from 'fretted-strings';
import { createSimpleSchema } from './testing/simple-schema';
import { AdapterFixture } from './testing/adapter-fixture';
function delegateFn(): ts.QuickInfo {
return {
kind: ts.ScriptElementKind.string,
kindModifiers: '',
textSpan: {
start: 0,
length: 0,
},
displayParts: [],
};
}
function createFixture(name: string, schema?: GraphQLSchema) {
return new AdapterFixture(name, schema);
}
describe('getQuickInfoAtPosition', () => {
it('should return GraphQL quick info', () => {
const fixture = createFixture('main.ts', createSimpleSchema());
const quickInfoFn = fixture.adapter.getQuickInfoAtPosition.bind(fixture.adapter, delegateFn, 'main.ts');
const frets: Frets = {};
fixture.source = mark(
`
const query = \`
query {
hello
%%% ^ ^ %%%
%%% a1 a2 %%%
}
\`;
`,
frets,
);
expect(quickInfoFn(frets.a1.pos - 1)!.displayParts).toEqual([]);
expect(
quickInfoFn(frets.a1.pos)!
.displayParts!.map(dp => dp.text)
.join(''),
).toMatchSnapshot();
expect(
quickInfoFn(frets.a2.pos)!
.displayParts!.map(dp => dp.text)
.join(''),
).toMatchSnapshot();
expect(quickInfoFn(frets.a2.pos + 1)!.displayParts).toEqual([]);
});
});