Skip to content

Commit

Permalink
Add type param filter (flutter#596)
Browse files Browse the repository at this point in the history
Format code
Add match by type tests
  • Loading branch information
cazci authored Nov 17, 2020
1 parent 1091fb1 commit a0d314b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
11 changes: 11 additions & 0 deletions web/samples_index/lib/src/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ bool matchesQuery(String query, String sampleAttributes) {
var queryWords = query.split(' ')..removeWhere((s) => s.isEmpty);
var attributes = sampleAttributes.split(' ')..removeWhere((s) => s.isEmpty);

// Test for type filter
// This will check whether a type parameter is present in the
// search query, and return false if the self type mismatches
// the query type
for (var word in queryWords) {
if ((word.contains('type:') && !attributes.contains(word)) ||
(word.contains('platform:') && !attributes.contains('type:demo'))) {
return false;
}
}

// Test for exact matches
if (attributes.contains(query)) {
return true;
Expand Down
8 changes: 7 additions & 1 deletion web/samples_index/test/samples_index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void main() {
'widget:AnimatedBuilder '
'widget:FutureBuilder '
'package:json_serializable '
'package:path';
'package:path '
'type:sample';

// Test if various queries match these attributes
expect(matchesQuery('foo', attributes), false);
Expand All @@ -124,6 +125,11 @@ void main() {
expect(matchesQuery('kitten tag:cats', attributes), true);
expect(matchesQuery('tag:beginner dogs', attributes), false);
expect(matchesQuery('asdf ', attributes), false);

// Test if queries match by type
expect(matchesQuery('type:sample', attributes), true);
expect(matchesQuery('type:cookbook', attributes), false);
expect(matchesQuery('kittens type:cookbook', attributes), false);
});
});

Expand Down
5 changes: 4 additions & 1 deletion web/samples_index/tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ void deploy() {
@Depends(createThumbnails)
Future buildRelease() async {
var app = PubApp.local('build_runner');
await app.runAsync('build --release --output web:public --delete-conflicting-outputs'.split(' ').toList());
await app.runAsync(
'build --release --output web:public --delete-conflicting-outputs'
.split(' ')
.toList());
}

@DefaultTask('Build the project.')
Expand Down
3 changes: 1 addition & 2 deletions web/samples_index/web/description.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import 'package:mdc_web/mdc_web.dart';
InputElement searchInput;

void main() {
querySelectorAll('.mdc-card__primary-action')
.forEach((el) => MDCRipple(el));
querySelectorAll('.mdc-card__primary-action').forEach((el) => MDCRipple(el));
}

0 comments on commit a0d314b

Please sign in to comment.