-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for helpers and moels to Flutter and Dart SDKs
- Loading branch information
1 parent
fbeead0
commit e427d24
Showing
9 changed files
with
415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('unique()', () { | ||
test('returns unique()', () { | ||
expect(ID.unique(), 'unique()'); | ||
}); | ||
}); | ||
|
||
group('custom()', () { | ||
test('returns the custom string', () { | ||
expect(ID.custom('custom'), 'custom'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('read()', () { | ||
test('returns read', () { | ||
expect(Permission.read(Role.any()), 'read("any")'); | ||
}); | ||
}); | ||
|
||
group('write()', () { | ||
test('returns write', () { | ||
expect(Permission.write(Role.any()), 'write("any")'); | ||
}); | ||
}); | ||
|
||
group('create()', () { | ||
test('returns create', () { | ||
expect(Permission.create(Role.any()), 'create("any")'); | ||
}); | ||
}); | ||
|
||
group('update()', () { | ||
test('returns update', () { | ||
expect(Permission.update(Role.any()), 'update("any")'); | ||
}); | ||
}); | ||
|
||
group('delete()', () { | ||
test('returns delete', () { | ||
expect(Permission.delete(Role.any()), 'delete("any")'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
class BasicFilterQueryTest { | ||
final String description; | ||
final dynamic value; | ||
final String expectedValues; | ||
|
||
BasicFilterQueryTest({ | ||
required this.description, | ||
required this.value, | ||
required this.expectedValues, | ||
}); | ||
} | ||
|
||
void main() { | ||
group('basic filter tests', () { | ||
final tests = [ | ||
BasicFilterQueryTest( | ||
description: 'with a string', | ||
value: 's', | ||
expectedValues: '["s"]', | ||
), | ||
BasicFilterQueryTest( | ||
description: 'with an integer', | ||
value: 1, | ||
expectedValues: '[1]', | ||
), | ||
BasicFilterQueryTest( | ||
description: 'with a double', | ||
value: 1.2, | ||
expectedValues: '[1.2]', | ||
), | ||
BasicFilterQueryTest( | ||
description: 'with a whole number double', | ||
value: 1.0, | ||
expectedValues: '[1.0]', | ||
), | ||
BasicFilterQueryTest( | ||
description: 'with a bool', | ||
value: false, | ||
expectedValues: '[false]', | ||
), | ||
BasicFilterQueryTest( | ||
description: 'with a list', | ||
value: ['a', 'b', 'c'], | ||
expectedValues: '["a","b","c"]', | ||
), | ||
]; | ||
|
||
group('equal()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
expect( | ||
Query.equal('attr', t.value), | ||
'equal("attr", ${t.expectedValues})', | ||
); | ||
}); | ||
} | ||
}); | ||
|
||
group('notEqual()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
expect( | ||
Query.notEqual('attr', t.value), | ||
'notEqual("attr", ${t.expectedValues})', | ||
); | ||
}); | ||
} | ||
}); | ||
|
||
group('lessThan()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
expect( | ||
Query.lessThan('attr', t.value), | ||
'lessThan("attr", ${t.expectedValues})', | ||
); | ||
}); | ||
} | ||
}); | ||
|
||
group('lessThanEqual()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
expect( | ||
Query.lessThanEqual('attr', t.value), | ||
'lessThanEqual("attr", ${t.expectedValues})', | ||
); | ||
}); | ||
} | ||
}); | ||
|
||
group('greaterThan()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
expect( | ||
Query.greaterThan('attr', t.value), | ||
'greaterThan("attr", ${t.expectedValues})', | ||
); | ||
}); | ||
} | ||
}); | ||
|
||
group('greaterThanEqual()', () { | ||
for (var t in tests) { | ||
test(t.description, () { | ||
expect( | ||
Query.greaterThanEqual('attr', t.value), | ||
'greaterThanEqual("attr", ${t.expectedValues})', | ||
); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
group('search()', () { | ||
test('returns search', () { | ||
expect(Query.search('attr', 'keyword1 keyword2'), 'search("attr", ["keyword1 keyword2"])'); | ||
}); | ||
}); | ||
|
||
group('isNull()', () { | ||
test('returns isNull', () { | ||
expect(Query.isNull('attr'), 'isNull("attr")'); | ||
}); | ||
}); | ||
|
||
group('isNotNull()', () { | ||
test('returns isNotNull', () { | ||
expect(Query.isNotNull('attr'), 'isNotNull("attr")'); | ||
}); | ||
}); | ||
|
||
group('between()', () { | ||
test('with integers', () { | ||
expect(Query.between('attr', 1, 2), 'between("attr", [1,2])'); | ||
}); | ||
|
||
test('with doubles', () { | ||
expect(Query.between('attr', 1.0, 2.0), 'between("attr", [1.0,2.0])'); | ||
}); | ||
|
||
test('with strings', () { | ||
expect(Query.between('attr', "a", "z"), 'between("attr", ["a","z"])'); | ||
}); | ||
}); | ||
|
||
group('select()', () { | ||
test('returns select', () { | ||
expect(Query.select(['attr1', 'attr2']), 'select(["attr1","attr2"])'); | ||
}); | ||
}); | ||
|
||
group('orderAsc()', () { | ||
test('returns orderAsc', () { | ||
expect(Query.orderAsc('attr'), 'orderAsc("attr")'); | ||
}); | ||
}); | ||
|
||
group('orderDesc()', () { | ||
test('returns orderDesc', () { | ||
expect(Query.orderDesc('attr'), 'orderDesc("attr")'); | ||
}); | ||
}); | ||
|
||
group('cursorBefore()', () { | ||
test('returns cursorBefore', () { | ||
expect(Query.cursorBefore(ID.custom('custom')), 'cursorBefore("custom")'); | ||
}); | ||
}); | ||
|
||
group('cursorAfter()', () { | ||
test('returns cursorAfter', () { | ||
expect(Query.cursorAfter(ID.custom('custom')), 'cursorAfter("custom")'); | ||
}); | ||
}); | ||
|
||
group('limit()', () { | ||
test('returns limit', () { | ||
expect(Query.limit(1), 'limit(1)'); | ||
}); | ||
}); | ||
|
||
group('offset()', () { | ||
test('returns offset', () { | ||
expect(Query.offset(1), 'offset(1)'); | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('any()', () { | ||
test('returns any', () { | ||
expect(Role.any(), 'any'); | ||
}); | ||
}); | ||
|
||
group('user()', () { | ||
test('without status', () { | ||
expect(Role.user('custom'), 'user:custom'); | ||
}); | ||
|
||
test('with status', () { | ||
expect(Role.user('custom', 'verified'), 'user:custom/verified'); | ||
}); | ||
}); | ||
|
||
group('users()', () { | ||
test('without status', () { | ||
expect(Role.users(), 'users'); | ||
}); | ||
|
||
test('with status', () { | ||
expect(Role.users('verified'), 'users/verified'); | ||
}); | ||
}); | ||
|
||
group('guests()', () { | ||
test('returns guests', () { | ||
expect(Role.guests(), 'guests'); | ||
}); | ||
}); | ||
|
||
group('team()', () { | ||
test('without role', () { | ||
expect(Role.team('custom'), 'team:custom'); | ||
}); | ||
|
||
test('with role', () { | ||
expect(Role.team('custom', 'owner'), 'team:custom/owner'); | ||
}); | ||
}); | ||
|
||
group('member()', () { | ||
test('returns member', () { | ||
expect(Role.member('custom'), 'member:custom'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:{{ language.params.packageName }}/src/enums.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('name()', () { | ||
for (final method in HttpMethod.values) { | ||
test('returns ${method.toString().split('.').last.toUpperCase()} for $method', () { | ||
expect(method.name(), method.toString().split('.').last.toUpperCase()); | ||
}); | ||
} | ||
}); | ||
} |
Oops, something went wrong.