Skip to content

Added Tests for Classes #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions test/classes_tests/test_global.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:test/test.dart';
import '../classes/Global.dart';

void main() {
group('Global', () {
test('Initial device list should be empty', () {
expect(Global.devices, isEmpty);
});

test('Initial connected devices list should be empty', () {
expect(Global.connectedDevices, isEmpty);
});

test('Initial nearbyService should be null', () {
expect(Global.nearbyService, isNull);
});

test('Initial subscription should be null', () {
expect(Global.subscription, isNull);
});

test('Initial receivedDataSubscription should be null', () {
expect(Global.receivedDataSubscription, isNull);
});

test('Initial messages list should not be empty', () {
expect(Global.messages, isNotEmpty);
});

test('Initial publicKeys map should be empty', () {
expect(Global.publicKeys, isEmpty);
});

test('Initial conversations map should be empty', () {
expect(Global.conversations, isEmpty);
});

test('Initial myName should be an empty string', () {
expect(Global.myName, isEmpty);
});

test('Initial cache map should be empty', () {
expect(Global.cache, isEmpty);
});
});
}
22 changes: 22 additions & 0 deletions test/classes_tests/test_msg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:test/test.dart';
import '../classes/Msg.dart';

void main() {
group('Msg', () {
test('Initialization', () {
final msg = Msg("Test Message", "sent", "2023-01-01", "1");

expect(msg.message, "Test Message");
expect(msg.msgtype, "sent");
expect(msg.timestamp, "2023-01-01");
expect(msg.id, "1");
expect(msg.ack, "false");
});

test('Acknowledgment Default Value', () {
final msg = Msg("Test Message", "sent", "2023-01-01", "1");

expect(msg.ack, "false");
});
});
}
25 changes: 25 additions & 0 deletions test/classes_tests/test_payload.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:test/test.dart';
import '../classes/Payload.dart';

void main() {
group('Payload and Ack Tests', () {
test('Payload Initialization', () {
final payload = Payload("1", "sender", "receiver", "message", "timestamp");

expect(payload.id, "1");
expect(payload.sender, "sender");
expect(payload.receiver, "receiver");
expect(payload.message, "message");
expect(payload.timestamp, "timestamp");
expect(payload.broadcast, true);
expect(payload.type, "Payload");
});

test('Ack Initialization', () {
final ack = Ack("1");

expect(ack.id, "1");
expect(ack.type, "Ack");
});
});
}