TF-4370 Add description field to Label object

This commit is contained in:
dab246
2026-03-11 14:53:07 +07:00
committed by Dat H. Pham
parent 4c837ed9cf
commit 90ddbf5824
3 changed files with 156 additions and 0 deletions
+3
View File
@@ -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<String, dynamic> json) => _$LabelFromJson(json);
@@ -41,5 +43,6 @@ class Label with EquatableMixin {
keyword,
displayName,
color,
description,
];
}
+91
View File
@@ -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));
});
});
});
}
@@ -176,5 +176,67 @@ void main() {
// Assert
expect(call, throwsA(isA<DioException>()));
});
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<SetLabelResponse>(
invocation.methodCallId,
SetLabelResponse.deserialize,
);
// Assert
expect(parsed, isNotNull);
expect(parsed!.created![Id('A')]!.keyword?.value, equals('descTag'));
});
});
}