moxxy/test/stanzahandler_test.dart

68 lines
2.4 KiB
Dart
Raw Normal View History

2022-01-09 22:38:28 +00:00
import "package:test/test.dart";
import "package:moxxyv2/xmpp/stanzas/stanza.dart";
import "package:moxxyv2/xmpp/managers/handlers.dart";
2022-01-09 22:38:28 +00:00
import "package:moxxyv2/xmpp/stringxml.dart";
final stanza1 = Stanza.iq(children: [
XMLNode.xmlns(tag: "tag", xmlns: "owo")
]);
final stanza2 = Stanza.message(children: [
2022-01-09 22:38:28 +00:00
XMLNode.xmlns(tag: "some-other-tag", xmlns: "owo")
]);
void main() {
test("match all", () {
final handler = StanzaHandler(callback: (_) async => true);
2022-01-09 22:38:28 +00:00
expect(handler.matches(Stanza.iq()), true);
expect(handler.matches(Stanza.message()), true);
expect(handler.matches(Stanza.presence()), true);
expect(handler.matches(stanza1), true);
expect(handler.matches(stanza2), true);
});
test("xmlns matching", () {
final handler = StanzaHandler(callback: (_) async => true, tagXmlns: "owo");
2022-01-09 22:38:28 +00:00
expect(handler.matches(Stanza.iq()), false);
expect(handler.matches(Stanza.message()), false);
expect(handler.matches(Stanza.presence()), false);
expect(handler.matches(stanza1), true);
expect(handler.matches(stanza2), true);
});
test("stanzaTag matching", () {
bool run = false;
final handler = StanzaHandler(callback: (_) async {
run = true;
return true;
}, stanzaTag: "iq");
2022-01-09 22:38:28 +00:00
expect(handler.matches(Stanza.iq()), true);
expect(handler.matches(Stanza.message()), false);
expect(handler.matches(Stanza.presence()), false);
expect(handler.matches(stanza1), true);
expect(handler.matches(stanza2), false);
handler.callback(stanza2);
expect(run, true);
2022-01-09 22:38:28 +00:00
});
test("tagName matching", () {
final handler = StanzaHandler(callback: (_) async => true, tagName: "tag");
2022-01-09 22:38:28 +00:00
expect(handler.matches(Stanza.iq()), false);
expect(handler.matches(Stanza.message()), false);
expect(handler.matches(Stanza.presence()), false);
expect(handler.matches(stanza1), true);
expect(handler.matches(stanza2), false);
});
test("combined matching", () {
final handler = StanzaHandler(callback: (_) async => true, tagName: "tag", stanzaTag: "iq", tagXmlns: "owo");
2022-01-09 22:38:28 +00:00
expect(handler.matches(Stanza.iq()), false);
expect(handler.matches(Stanza.message()), false);
expect(handler.matches(Stanza.presence()), false);
expect(handler.matches(stanza1), true);
expect(handler.matches(stanza2), false);
});
}