// Copyright 2017 Google Inc.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
import 'package:ngflutter/src/page_object_data.dart';
import 'package:test/test.dart';
void main() {
group('PageObjectData', () {
test('should generate items.', () {
var po = new PageObjectData(
'',
);
expect(po.variables.first.getterString,
'Future get good => _getGood();');
expect(po.variables.first.internalString,
"@ByClass('good')\n Lazy _getGood;");
expect(po.variables.first.type.uri, 'package:pageloader/objects.dart');
});
test('should generate items in list', () {
var po = new PageObjectData(
'',
);
expect(po.variables.first.getterString,
'Future> get good => _getGood();');
expect(po.variables.first.internalString,
"@ByClass('good')\n Lazy> _getGood;");
});
test('should generate items in parents list', () {
var po = new PageObjectData(
''
'
',
);
expect(po.variables.first.getterString,
'Future> get good => _getGood();');
expect(po.variables.first.internalString,
"@ByClass('good')\n Lazy> _getGood;");
});
test('should generate items with default type', () {
var po = new PageObjectData('');
expect(po.variables.first.getterString,
'Future get cool => _getCool();');
expect(po.variables.first.internalString,
"@ByClass('cool')\n Lazy _getCool;");
expect(po.variables.first.type.uri, 'package:pageloader/objects.dart');
});
test('should sort generated items', () {
var po1 = new PageObjectData(
''
'',
);
expect(po1.variables.first.name, 'Bad');
expect(po1.variables.last.name, 'Good');
var po2 = new PageObjectData(
''
'',
);
expect(po2.variables.first.name, 'Bad');
expect(po2.variables.last.name, 'Good');
});
test('should ignore some tags.', () {
var po = new PageObjectData('123
');
expect(po.variables.isEmpty, true);
});
test('should add optional annotation.', () {
var po = new PageObjectData('');
expect(po.variables[0].internalString, startsWith('@optional'));
});
test('should add optional annotation when parent is optional.', () {
var po = new PageObjectData(
'
');
expect(po.variables[0].internalString, startsWith('@optional'));
});
test('should add optional annotation when in ', () {
var po = new PageObjectData(
'',
);
expect(po.variables[0].internalString, startsWith('@optional'));
});
test('should choose correct selector.', () {
var po = new PageObjectData(
''
''
'',
);
expect(po.variables.length, 3);
expect(po.variables[0].selector.toString(), "@ByClass('cool')");
expect(po.variables[1].selector.toString(), "@ById('cooler')");
expect(po.variables[2].selector.toString(), "@ByTagName('some-widget')");
});
test('should work with selectors with attributes', () {
var po = new PageObjectData(
''
'',
);
expect(po.variables[0].selector.toString(), "@ByClass('field-class')");
expect(po.variables[1].selector.toString(), "@ById('fieldWithId')");
expect(po.variables[0].name, 'FieldClass');
expect(po.variables[1].name, 'FieldWithId');
});
test('should produce correct commonDependencies.', () {
var po1 = new PageObjectData('');
expect(po1.commonDependencies, [PageObjectData.pageLoaderDependency]);
var po3 = new PageObjectData('');
expect(po3.commonDependencies, [
PageObjectData.pageLoaderDependency,
PageObjectData.asyncDependency
]);
});
});
}