Skip to content

Commit 8d3584b

Browse files
Merge pull request #462 from adityashirsatrao007/test/gsod-modal-new
test: add unit tests for GsodModalNew
2 parents 1c1a2e0 + 0b3dafb commit 8d3584b

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

test/gsod_modal_new_test.dart

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:opso/modals/gsod/gsod_modal_new.dart';
3+
4+
void main() {
5+
group('GsodModalNew', () {
6+
final tModal = GsodModalNew(
7+
organizationName: 'TestOrg',
8+
organizationUrl: 'https://testorg.com',
9+
docsPage: 'Documentation',
10+
docsPageUrl: 'https://testorg.com/docs',
11+
budget: '10000',
12+
budgetUrl: 'https://testorg.com/budget',
13+
acceptedProjectProposal: 'Test Proposal',
14+
acceptedProjectProposalUrl: 'https://testorg.com/proposal',
15+
caseStudy: 'Test Case Study',
16+
caseStudyUrl: 'https://testorg.com/case-study',
17+
year: 2023,
18+
);
19+
20+
test('constructor sets all fields correctly', () {
21+
expect(tModal.organizationName, 'TestOrg');
22+
expect(tModal.organizationUrl, 'https://testorg.com');
23+
expect(tModal.docsPage, 'Documentation');
24+
expect(tModal.budget, '10000');
25+
expect(tModal.acceptedProjectProposal, 'Test Proposal');
26+
expect(tModal.caseStudy, 'Test Case Study');
27+
expect(tModal.year, 2023);
28+
});
29+
30+
test('copyWith updates selected fields', () {
31+
final updated = tModal.copyWith(organizationName: 'NewOrg', year: 2024);
32+
expect(updated.organizationName, 'NewOrg');
33+
expect(updated.year, 2024);
34+
expect(updated.budget, tModal.budget);
35+
expect(updated.docsPage, tModal.docsPage);
36+
});
37+
38+
test('copyWith with no args returns equivalent object', () {
39+
final copy = tModal.copyWith();
40+
expect(copy.organizationName, tModal.organizationName);
41+
expect(copy.year, tModal.year);
42+
});
43+
44+
test('toMap returns correct map', () {
45+
final map = tModal.toMap();
46+
expect(map['organization_name'], 'TestOrg');
47+
expect(map['organization_url'], 'https://testorg.com');
48+
expect(map['budget'], '10000');
49+
expect(map['year'], 2023);
50+
});
51+
52+
test('fromMap constructs correctly', () {
53+
final map = {
54+
'organization_name': 'FromMap Org',
55+
'organization_url': 'https://frommap.com',
56+
'docs_page': 'Docs',
57+
'docs_page_url': 'https://frommap.com/docs',
58+
'budget': '5000',
59+
'budget_url': 'https://frommap.com/budget',
60+
'accepted_project_proposal': 'Proposal',
61+
'accepted_project_proposal_url': 'https://frommap.com/proposal',
62+
'case_study': 'Case',
63+
'case_study_url': 'https://frommap.com/case',
64+
'year': 2022,
65+
};
66+
final modal = GsodModalNew.fromMap(map);
67+
expect(modal.organizationName, 'FromMap Org');
68+
expect(modal.budget, '5000');
69+
expect(modal.year, 2022);
70+
});
71+
72+
test('fromMap handles missing fields with defaults', () {
73+
final modal = GsodModalNew.fromMap({});
74+
expect(modal.organizationName, '');
75+
expect(modal.budget, '');
76+
expect(modal.year, 0);
77+
});
78+
79+
test('equality operator works correctly', () {
80+
final other = GsodModalNew(
81+
organizationName: 'TestOrg',
82+
organizationUrl: 'https://testorg.com',
83+
docsPage: 'Documentation',
84+
docsPageUrl: 'https://testorg.com/docs',
85+
budget: '10000',
86+
budgetUrl: 'https://testorg.com/budget',
87+
acceptedProjectProposal: 'Test Proposal',
88+
acceptedProjectProposalUrl: 'https://testorg.com/proposal',
89+
caseStudy: 'Test Case Study',
90+
caseStudyUrl: 'https://testorg.com/case-study',
91+
year: 2023,
92+
);
93+
expect(tModal == other, isTrue);
94+
});
95+
96+
test('inequality when fields differ', () {
97+
final other = tModal.copyWith(year: 2024);
98+
expect(tModal == other, isFalse);
99+
});
100+
101+
test('hashCode is consistent for equal objects', () {
102+
final other = tModal.copyWith();
103+
expect(tModal.hashCode, equals(other.hashCode));
104+
});
105+
106+
test('toJson returns valid JSON string', () {
107+
final jsonStr = tModal.toJson();
108+
expect(jsonStr, isA<String>());
109+
expect(jsonStr.contains('TestOrg'), isTrue);
110+
});
111+
112+
test('toString contains key fields', () {
113+
final str = tModal.toString();
114+
expect(str, contains('TestOrg'));
115+
expect(str, contains('10000'));
116+
expect(str, contains('2023'));
117+
});
118+
});
119+
}

0 commit comments

Comments
 (0)