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

85 lines
2 KiB
Dart
Raw Normal View History

2021-05-15 10:45:39 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart';
import 'package:angel3_test/angel3_test.dart';
2017-10-01 03:14:44 +00:00
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';
2021-05-15 10:45:39 +00:00
void main() {
2017-10-01 03:14:44 +00:00
// 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 {
2021-05-15 10:45:39 +00:00
var app = Angel();
2017-10-01 03:14:44 +00:00
app.configuration['properties'] = app.configuration;
2021-05-15 10:45:39 +00:00
var fileSystem = MemoryFileSystem();
2017-10-01 03:14:44 +00:00
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),
);
2021-05-15 10:45:39 +00:00
app.fallback((req, res) => throw AngelHttpException.notFound());
2017-10-01 03:14:44 +00:00
2021-05-15 10:45:39 +00:00
app.logger = Logger('angel')
2017-10-01 03:14:44 +00:00
..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
});
}