From 90ddbf5824c6f07b378476e7de9da6567ab24e0e Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 11 Mar 2026 14:53:07 +0700 Subject: [PATCH] TF-4370 Add `description` field to Label object --- labels/lib/model/label.dart | 3 + labels/test/method/model/label_test.dart | 91 +++++++++++++++++++ .../method/set/set_label_method_test.dart | 62 +++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 labels/test/method/model/label_test.dart diff --git a/labels/lib/model/label.dart b/labels/lib/model/label.dart index 6eed79996..f64cf3e2c 100644 --- a/labels/lib/model/label.dart +++ b/labels/lib/model/label.dart @@ -23,12 +23,14 @@ class Label with EquatableMixin { final KeyWordIdentifier? keyword; final String? displayName; final HexColor? color; + final String? description; Label({ this.id, this.keyword, this.displayName, this.color, + this.description, }); factory Label.fromJson(Map json) => _$LabelFromJson(json); @@ -41,5 +43,6 @@ class Label with EquatableMixin { keyword, displayName, color, + description, ]; } diff --git a/labels/test/method/model/label_test.dart b/labels/test/method/model/label_test.dart new file mode 100644 index 000000000..0adc8e245 --- /dev/null +++ b/labels/test/method/model/label_test.dart @@ -0,0 +1,91 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart'; +import 'package:labels/model/hex_color.dart'; +import 'package:labels/model/label.dart'; + +void main() { + group('Label', () { + group('fromJson', () { + test('should deserialize all fields correctly', () { + final json = { + "id": "123", + "keyword": "important", + "displayName": "Important", + "color": "#ff0000", + "description": "Important emails" + }; + + final label = Label.fromJson(json); + + expect(label.id, equals(Id('123'))); + expect(label.keyword, equals(KeyWordIdentifier('important'))); + expect(label.displayName, equals('Important')); + expect(label.color, equals(HexColor('#ff0000'))); + expect(label.description, equals('Important emails')); + }); + + test('should handle missing optional fields', () { + final json = { + "displayName": "Simple label", + }; + + final label = Label.fromJson(json); + + expect(label.id, isNull); + expect(label.keyword, isNull); + expect(label.color, isNull); + expect(label.description, isNull); + }); + }); + + group('toJson', () { + test('should serialize all fields correctly', () { + final label = Label( + id: Id('123'), + keyword: KeyWordIdentifier('important'), + displayName: 'Important', + color: HexColor('#ff0000'), + description: 'Important emails', + ); + + final json = label.toJson(); + + expect(json['id'], equals('123')); + expect(json['keyword'], equals('important')); + expect(json['displayName'], equals('Important')); + expect(json['color'], equals('#ff0000')); + expect(json['description'], equals('Important emails')); + }); + + test('should not include null fields', () { + final label = Label( + displayName: 'Label', + ); + + final json = label.toJson(); + + expect(json.containsKey('id'), isFalse); + expect(json.containsKey('keyword'), isFalse); + expect(json.containsKey('color'), isFalse); + expect(json.containsKey('description'), isFalse); + }); + }); + + group('equatable', () { + test('should support value equality', () { + final label1 = Label( + displayName: 'Test', + description: 'desc', + ); + + final label2 = Label( + displayName: 'Test', + description: 'desc', + ); + + expect(label1, equals(label2)); + }); + }); + }); +} diff --git a/labels/test/method/set/set_label_method_test.dart b/labels/test/method/set/set_label_method_test.dart index 55e19ab90..f5c839675 100644 --- a/labels/test/method/set/set_label_method_test.dart +++ b/labels/test/method/set/set_label_method_test.dart @@ -176,5 +176,67 @@ void main() { // Assert expect(call, throwsA(isA())); }); + + test('should include description when creating label', () async { + // Arrange + final dio = createDio(); + final adapter = DioAdapter(dio: dio); + + adapter.onPost( + '', + (server) => server.reply(200, { + "sessionState": "session-state", + "methodResponses": [ + [ + "Label/set", + { + "accountId": accountId.id.value, + "newState": "new", + "created": { + "A": {"id": "123", "keyword": "descTag"} + } + }, + "c0" + ] + ] + }), + data: buildPayload({ + "A": { + "displayName": "Tag with description", + "color": "#123456", + "description": "This is a test label" + } + }), + headers: createJMAPHeader(), + ); + + final builder = createBuilder(dio); + + final method = SetLabelMethod(accountId) + ..addCreate( + Id('A'), + Label( + displayName: "Tag with description", + color: HexColor("#123456"), + description: "This is a test label", + ), + ); + + final invocation = builder.invocation(method); + + // Act + final response = await (builder..usings(method.requiredCapabilities)) + .build() + .execute(); + + final parsed = response.parse( + invocation.methodCallId, + SetLabelResponse.deserialize, + ); + + // Assert + expect(parsed, isNotNull); + expect(parsed!.created![Id('A')]!.keyword?.value, equals('descTag')); + }); }); }