Skip to content

Commit 6b1f9af

Browse files
committed
store test: Test handling of customProfileFields
1 parent 221ba81 commit 6b1f9af

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/model/store_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,48 @@ void main() {
563563
});
564564
});
565565

566+
group('PerAccountStore.customProfileFields', () {
567+
test('update clobbers old list', () async {
568+
final store = eg.store(initialSnapshot: eg.initialSnapshot(
569+
customProfileFields: [
570+
eg.customProfileField(0, CustomProfileFieldType.shortText),
571+
eg.customProfileField(1, CustomProfileFieldType.shortText),
572+
]));
573+
check(store.customProfileFields.map((f) => f.id)).deepEquals([0, 1]);
574+
575+
await store.handleEvent(CustomProfileFieldsEvent(id: 0, fields: [
576+
eg.customProfileField(0, CustomProfileFieldType.shortText),
577+
eg.customProfileField(2, CustomProfileFieldType.shortText),
578+
]));
579+
check(store.customProfileFields.map((f) => f.id)).deepEquals([0, 2]);
580+
});
581+
582+
test('sorts by displayInProfile', () async {
583+
// Sorts both the data from the initial snapshot…
584+
final store = eg.store(initialSnapshot: eg.initialSnapshot(
585+
customProfileFields: [
586+
eg.customProfileField(0, CustomProfileFieldType.shortText,
587+
displayInProfileSummary: false),
588+
eg.customProfileField(1, CustomProfileFieldType.shortText,
589+
displayInProfileSummary: true),
590+
eg.customProfileField(2, CustomProfileFieldType.shortText,
591+
displayInProfileSummary: false),
592+
]));
593+
check(store.customProfileFields.map((f) => f.id)).deepEquals([1, 0, 2]);
594+
595+
// … and from an event.
596+
await store.handleEvent(CustomProfileFieldsEvent(id: 0, fields: [
597+
eg.customProfileField(0, CustomProfileFieldType.shortText,
598+
displayInProfileSummary: false),
599+
eg.customProfileField(1, CustomProfileFieldType.shortText,
600+
displayInProfileSummary: false),
601+
eg.customProfileField(2, CustomProfileFieldType.shortText,
602+
displayInProfileSummary: true),
603+
]));
604+
check(store.customProfileFields.map((f) => f.id)).deepEquals([2, 0, 1]);
605+
});
606+
});
607+
566608
group('PerAccountStore.handleEvent', () {
567609
// Mostly this method just dispatches to ChannelStore and MessageStore etc.,
568610
// and so its tests generally live in the test files for those

0 commit comments

Comments
 (0)