loris/test/user/user_test.dart

46 lines
1.4 KiB
Dart
Raw Normal View History

2022-06-16 20:30:02 +00:00
import 'package:flutter_test/flutter_test.dart';
2022-06-28 20:05:24 +00:00
import 'package:slothmu/business_logic/user.dart';
2022-06-16 20:30:02 +00:00
void main() {
validUsernameTest();
usernameToUrlTest();
cleanupNameTest();
2022-06-17 09:50:07 +00:00
userFromUsernameTest();
2022-06-16 20:30:02 +00:00
}
void validUsernameTest() {
test("test if usernames are valid", () {
expect(isValidUsername(name: "hello world"), false);
expect(isValidUsername(name: ""), false);
expect(isValidUsername(name: "hello@world"), false);
expect(isValidUsername(name: "@hello@world"), false);
expect(isValidUsername(name: "@hello@world."), false);
expect(isValidUsername(name: "@hello@world.example"), true);
expect(isValidUsername(name: "hello@world.example"), true);
expect(isValidUsername(name: "noodles.noodles@gts.example.world.example"),
true);
});
}
void usernameToUrlTest() {
test("try valid transforming usernames into a url", () {
2022-06-28 20:19:46 +00:00
expect(urlFromUsername(name: "hello@example.com"), "example.com");
expect(urlFromUsername(name: "h@e.c"), "e.c");
2022-06-16 20:30:02 +00:00
});
}
void cleanupNameTest() {
test("try cleaning up a username", () {
expect(cleanUpUsername(name: "@ s o up @ s oup . par ty "),
"soup@soup.party");
expect(cleanUpUsername(name: ""), "");
});
}
2022-06-17 09:50:07 +00:00
void userFromUsernameTest() {
test("try extracting user from the full valid user id", () {
expect(userFromUsername(name: "@hello@world"), "hello");
expect(userFromUsername(name: "@john@from.garfield"), "john");
});
}