1 |
|
2 | import { compose } from './fswquery-compose';
|
3 | it('should compose generic queries', () => {
|
4 | expect(compose({
|
5 | query: true
|
6 | })).toBe('Q');
|
7 | expect(compose({
|
8 | query: true,
|
9 | style: true
|
10 | })).toBe('Q-');
|
11 | })
|
12 |
|
13 | it('should compose prefix queries', () => {
|
14 | expect(compose({
|
15 | query: true,
|
16 | prefix: { required: true }
|
17 | })).toBe('QT');
|
18 | expect(compose({
|
19 | query: true,
|
20 | prefix: { required: true },
|
21 | style: true
|
22 | })).toBe('QT-');
|
23 | expect(compose({
|
24 | query: true,
|
25 | prefix: {
|
26 | required: true,
|
27 | parts: [
|
28 | 'S10000',
|
29 | ['100', '204'],
|
30 | 'S20500'
|
31 | ]
|
32 | }
|
33 | })).toBe('QAS10000R100t204S20500T');
|
34 | })
|
35 |
|
36 | it('should compose signbox queries', () => {
|
37 | expect(compose({
|
38 | query: true,
|
39 | signbox: [
|
40 | { symbol: 'S20000' }
|
41 | ]
|
42 | })).toBe('QS20000');
|
43 | expect(compose({
|
44 | query: true,
|
45 | signbox: [
|
46 | {
|
47 | symbol: 'S20000',
|
48 | coord: [500, 500]
|
49 | }
|
50 | ]
|
51 | })).toBe('QS20000500x500');
|
52 | expect(compose({
|
53 | query: true,
|
54 | signbox: [
|
55 | { range: ['100', '105'] }
|
56 | ]
|
57 | })).toBe('QR100t105');
|
58 | expect(compose({
|
59 | query: true,
|
60 | signbox: [
|
61 | {
|
62 | range: ['100', '105'],
|
63 | coord: [500, 500]
|
64 | }
|
65 | ]
|
66 | })).toBe('QR100t105500x500');
|
67 | expect(compose({
|
68 | query: true,
|
69 | signbox: [
|
70 | { symbol: 'S20000' },
|
71 | {
|
72 | range: ['100', '105'],
|
73 | coord: [500, 500]
|
74 | }
|
75 | ]
|
76 | })).toBe('QS20000R100t105500x500');
|
77 | })
|
78 |
|
79 | it('should not break on invalid input', () => {
|
80 | expect(compose()).toBe(undefined);
|
81 | expect(compose('a')).toBe(undefined);
|
82 | expect(compose({ 'a': 5 })).toBe(undefined);
|
83 | expect(compose(['a'])).toBe(undefined);
|
84 | })
|
85 |
|
86 | it('should not break on mangled input', () => {
|
87 | expect(compose({
|
88 | query: true,
|
89 | prefix: {
|
90 | required: true,
|
91 | parts: [
|
92 | 'x',
|
93 | ['100', '204'],
|
94 | 'S20500'
|
95 | ]
|
96 | }
|
97 | })).toBe('Q');
|
98 | expect(compose({
|
99 | query: true,
|
100 | prefix: {
|
101 | required: true,
|
102 | parts: [
|
103 | ['444', '204'],
|
104 | 'S20500'
|
105 | ]
|
106 | }
|
107 | })).toBe('Q');
|
108 | expect(compose({
|
109 | query: true,
|
110 | prefix: {
|
111 | required: true,
|
112 | parts: 'xx'
|
113 | }
|
114 | })).toBe('QT');
|
115 | expect(compose({
|
116 | query: true,
|
117 | prefix: {
|
118 | required: true,
|
119 | parts: [{ a: 'xx' }]
|
120 | }
|
121 | })).toBe('Q');
|
122 | expect(compose({
|
123 | query: true,
|
124 | signbox: [
|
125 | { symbolx: 'S20000' },
|
126 | {
|
127 | rangex: ['100', '105'],
|
128 | coord: [500, 500]
|
129 | }
|
130 | ]
|
131 | })).toBe('Q');
|
132 | expect(compose({
|
133 | query: true,
|
134 | signbox: [
|
135 | { symbol: 'x' },
|
136 | {
|
137 | rangex: ['100', '105'],
|
138 | coord: [500, 500]
|
139 | }
|
140 | ]
|
141 | })).toBe('Q');
|
142 | })
|