platform/packages/jael/angel_jael/test/all_test.dart

85 lines
2 KiB
Dart
Raw Normal View History

2017-10-01 03:14:44 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_jael/angel_jael.dart';
import 'package:angel_test/angel_test.dart';
import 'package:file/memory.dart';
2018-11-10 21:48:03 +00:00
import 'package:html/parser.dart' as html;
2017-10-01 03:14:44 +00:00
import 'package:logging/logging.dart';
import 'package:test/test.dart';
main() {
// These tests need not actually test that the preprocessor or renderer works,
// because those packages are already tested.
//
// Instead, just test that we can render at all.
2021-04-30 07:19:26 +00:00
late TestClient client;
2017-10-01 03:14:44 +00:00
setUp(() async {
var app = new Angel();
app.configuration['properties'] = app.configuration;
var fileSystem = new MemoryFileSystem();
var viewsDirectory = fileSystem.directory('views')..createSync();
2018-11-10 21:48:03 +00:00
viewsDirectory.childFile('layout.jael').writeAsStringSync('''
2017-10-01 03:14:44 +00:00
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<block name="content">
Fallback content
</block>
</body>
</html>
''');
2018-11-10 21:48:03 +00:00
viewsDirectory.childFile('github.jael').writeAsStringSync('''
<extend src="layout.jael">
2017-10-01 03:14:44 +00:00
<block name="content">{{username}}</block>
</extend>
''');
2018-11-10 21:48:03 +00:00
app.get('/github/:username', (req, res) {
var username = req.params['username'];
2017-10-01 03:14:44 +00:00
return res.render('github', {'username': username});
});
await app.configure(
jael(viewsDirectory),
);
2018-11-10 21:48:03 +00:00
app.fallback((req, res) => throw new AngelHttpException.notFound());
2017-10-01 03:14:44 +00:00
app.logger = new Logger('angel')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});
client = await connectTo(app);
});
test('can render', () async {
2021-03-07 16:47:49 +00:00
var response = await client.get(Uri.parse('/github/thosakwe'));
2017-10-01 03:14:44 +00:00
print('Body:\n${response.body}');
expect(
2018-11-10 21:48:03 +00:00
html.parse(response.body).outerHtml,
html
.parse('''
2017-10-01 03:14:44 +00:00
<html>
<head>
<title>
Hello
</title>
</head>
<body>
thosakwe
</body>
2018-11-10 21:48:03 +00:00
</html>'''
.trim())
.outerHtml);
2017-10-01 03:14:44 +00:00
});
}