|
| 1 | +import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | + |
| 4 | +class BasicFilterQueryTest { |
| 5 | + final String description; |
| 6 | + final dynamic value; |
| 7 | + final String expectedValues; |
| 8 | + |
| 9 | + BasicFilterQueryTest({ |
| 10 | + required this.description, |
| 11 | + required this.value, |
| 12 | + required this.expectedValues, |
| 13 | + }); |
| 14 | +} |
| 15 | + |
| 16 | +void main() { |
| 17 | + group('basic filter tests', () { |
| 18 | + final tests = [ |
| 19 | + BasicFilterQueryTest( |
| 20 | + description: 'with a string', |
| 21 | + value: 's', |
| 22 | + expectedValues: '["s"]', |
| 23 | + ), |
| 24 | + BasicFilterQueryTest( |
| 25 | + description: 'with an integer', |
| 26 | + value: 1, |
| 27 | + expectedValues: '[1]', |
| 28 | + ), |
| 29 | + BasicFilterQueryTest( |
| 30 | + description: 'with a double', |
| 31 | + value: 1.2, |
| 32 | + expectedValues: '[1.2]', |
| 33 | + ), |
| 34 | + BasicFilterQueryTest( |
| 35 | + description: 'with a whole number double', |
| 36 | + value: 1.0, |
| 37 | + expectedValues: '[1.0]', |
| 38 | + ), |
| 39 | + BasicFilterQueryTest( |
| 40 | + description: 'with a bool', |
| 41 | + value: false, |
| 42 | + expectedValues: '[false]', |
| 43 | + ), |
| 44 | + BasicFilterQueryTest( |
| 45 | + description: 'with a list', |
| 46 | + value: ['a', 'b', 'c'], |
| 47 | + expectedValues: '["a","b","c"]', |
| 48 | + ), |
| 49 | + ]; |
| 50 | + |
| 51 | + group('equal()', () { |
| 52 | + for (var t in tests) { |
| 53 | + test(t.description, () { |
| 54 | + expect( |
| 55 | + Query.equal('attr', t.value), |
| 56 | + 'equal("attr", ${t.expectedValues})', |
| 57 | + ); |
| 58 | + }); |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + group('notEqual()', () { |
| 63 | + for (var t in tests) { |
| 64 | + test(t.description, () { |
| 65 | + expect( |
| 66 | + Query.notEqual('attr', t.value), |
| 67 | + 'notEqual("attr", ${t.expectedValues})', |
| 68 | + ); |
| 69 | + }); |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + group('lessThan()', () { |
| 74 | + for (var t in tests) { |
| 75 | + test(t.description, () { |
| 76 | + expect( |
| 77 | + Query.lessThan('attr', t.value), |
| 78 | + 'lessThan("attr", ${t.expectedValues})', |
| 79 | + ); |
| 80 | + }); |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + group('lessThanEqual()', () { |
| 85 | + for (var t in tests) { |
| 86 | + test(t.description, () { |
| 87 | + expect( |
| 88 | + Query.lessThanEqual('attr', t.value), |
| 89 | + 'lessThanEqual("attr", ${t.expectedValues})', |
| 90 | + ); |
| 91 | + }); |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + group('greaterThan()', () { |
| 96 | + for (var t in tests) { |
| 97 | + test(t.description, () { |
| 98 | + expect( |
| 99 | + Query.greaterThan('attr', t.value), |
| 100 | + 'greaterThan("attr", ${t.expectedValues})', |
| 101 | + ); |
| 102 | + }); |
| 103 | + } |
| 104 | + }); |
| 105 | + |
| 106 | + group('greaterThanEqual()', () { |
| 107 | + for (var t in tests) { |
| 108 | + test(t.description, () { |
| 109 | + expect( |
| 110 | + Query.greaterThanEqual('attr', t.value), |
| 111 | + 'greaterThanEqual("attr", ${t.expectedValues})', |
| 112 | + ); |
| 113 | + }); |
| 114 | + } |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + group('search()', () { |
| 119 | + test('returns search', () { |
| 120 | + expect(Query.search('attr', 'keyword1 keyword2'), 'search("attr", ["keyword1 keyword2"])'); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + group('isNull()', () { |
| 125 | + test('returns isNull', () { |
| 126 | + expect(Query.isNull('attr'), 'isNull("attr")'); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + group('isNotNull()', () { |
| 131 | + test('returns isNotNull', () { |
| 132 | + expect(Query.isNotNull('attr'), 'isNotNull("attr")'); |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + group('between()', () { |
| 137 | + test('with integers', () { |
| 138 | + expect(Query.between('attr', 1, 2), 'between("attr", [1,2])'); |
| 139 | + }); |
| 140 | + |
| 141 | + test('with doubles', () { |
| 142 | + expect(Query.between('attr', 1.0, 2.0), 'between("attr", [1.0,2.0])'); |
| 143 | + }); |
| 144 | + |
| 145 | + test('with strings', () { |
| 146 | + expect(Query.between('attr', "a", "z"), 'between("attr", ["a","z"])'); |
| 147 | + }); |
| 148 | + }); |
| 149 | + |
| 150 | + group('select()', () { |
| 151 | + test('returns select', () { |
| 152 | + expect(Query.select(['attr1', 'attr2']), 'select(["attr1","attr2"])'); |
| 153 | + }); |
| 154 | + }); |
| 155 | + |
| 156 | + group('orderAsc()', () { |
| 157 | + test('returns orderAsc', () { |
| 158 | + expect(Query.orderAsc('attr'), 'orderAsc("attr")'); |
| 159 | + }); |
| 160 | + }); |
| 161 | + |
| 162 | + group('orderDesc()', () { |
| 163 | + test('returns orderDesc', () { |
| 164 | + expect(Query.orderDesc('attr'), 'orderDesc("attr")'); |
| 165 | + }); |
| 166 | + }); |
| 167 | + |
| 168 | + group('cursorBefore()', () { |
| 169 | + test('returns cursorBefore', () { |
| 170 | + expect(Query.cursorBefore(ID.custom('custom')), 'cursorBefore("custom")'); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + group('cursorAfter()', () { |
| 175 | + test('returns cursorAfter', () { |
| 176 | + expect(Query.cursorAfter(ID.custom('custom')), 'cursorAfter("custom")'); |
| 177 | + }); |
| 178 | + }); |
| 179 | + |
| 180 | + group('limit()', () { |
| 181 | + test('returns limit', () { |
| 182 | + expect(Query.limit(1), 'limit(1)'); |
| 183 | + }); |
| 184 | + }); |
| 185 | + |
| 186 | + group('offset()', () { |
| 187 | + test('returns offset', () { |
| 188 | + expect(Query.offset(1), 'offset(1)'); |
| 189 | + }); |
| 190 | + }); |
| 191 | +} |
| 192 | + |
0 commit comments