|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:resonance_network_wallet/utils/validators.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('Validators', () { |
| 6 | + test('isValidXStatusUrl should validate correct X and Twitter URLs', () { |
| 7 | + final validUrls = [ |
| 8 | + 'https://x.com/username/status/123456789012345', |
| 9 | + 'https://www.x.com/username/status/123456789012345', |
| 10 | + 'http://x.com/username/status/123456789012345', |
| 11 | + 'https://twitter.com/username/status/123456789012345', |
| 12 | + 'https://mobile.twitter.com/username/status/123456789012345', |
| 13 | + 'https://mobile.x.com/username/status/123456789012345', |
| 14 | + 'https://x.com/username/status/123456789012345?s=20', |
| 15 | + 'https://twitter.com/User_Name/status/1234567890', |
| 16 | + ]; |
| 17 | + |
| 18 | + for (final url in validUrls) { |
| 19 | + expect(Validators.isValidXStatusUrl(url), isTrue, reason: 'URL should be valid: $url'); |
| 20 | + } |
| 21 | + }); |
| 22 | + |
| 23 | + test('isValidXStatusUrl should reject invalid URLs', () { |
| 24 | + final invalidUrls = [ |
| 25 | + 'https://google.com', |
| 26 | + 'https://x.com/username', |
| 27 | + 'https://x.com/status/12345', // Missing username |
| 28 | + 'https://x.com/username/12345', // Missing status |
| 29 | + 'ftp://x.com/username/status/12345', // Invalid protocol |
| 30 | + 'https://other-domain.com/username/status/12345', |
| 31 | + '', |
| 32 | + 'random text', |
| 33 | + ]; |
| 34 | + |
| 35 | + for (final url in invalidUrls) { |
| 36 | + expect(Validators.isValidXStatusUrl(url), isFalse, reason: 'URL should be invalid: $url'); |
| 37 | + } |
| 38 | + }); |
| 39 | + }); |
| 40 | +} |
0 commit comments