@@ -1488,6 +1488,43 @@ void main() {
14881488 });
14891489 });
14901490
1491+ group ('handle content parsing into subclasses of ZulipMessageContent' , () {
1492+ test ('ZulipContent' , () async {
1493+ final stream = eg.stream ();
1494+ await prepare (narrow: ChannelNarrow (stream.streamId));
1495+ await prepareMessages (foundOldest: true , messages: []);
1496+
1497+ await store.handleEvent (MessageEvent (id: 0 ,
1498+ message: eg.streamMessage (stream: stream)));
1499+ // Each [checkNotifiedOnce] call ensures there's been a [checkInvariants]
1500+ // call, where the [ContentNode] gets checked. The additional checks to
1501+ // make this test explicit.
1502+ checkNotifiedOnce ();
1503+ check (model).messages.single.poll.isNull ();
1504+ check (model).contents.single.isA <ZulipContent >();
1505+ });
1506+
1507+ test ('PollContent' , () async {
1508+ final stream = eg.stream ();
1509+ await prepare (narrow: ChannelNarrow (stream.streamId));
1510+ await prepareMessages (foundOldest: true , messages: []);
1511+
1512+ await store.handleEvent (MessageEvent (id: 0 , message: eg.streamMessage (
1513+ stream: stream,
1514+ sender: eg.selfUser,
1515+ submessages: [
1516+ eg.submessage (senderId: eg.selfUser.userId,
1517+ content: eg.pollWidgetData (question: 'question' , options: ['A' ])),
1518+ ])));
1519+ // Each [checkNotifiedOnce] call ensures there's been a [checkInvariants]
1520+ // call, where the value of the [Poll] gets checked. The additional
1521+ // checks make this test explicit.
1522+ checkNotifiedOnce ();
1523+ check (model).messages.single.poll.isNotNull ();
1524+ check (model).contents.single.isA <PollContent >();
1525+ });
1526+ });
1527+
14911528 test ('recipient headers are maintained consistently' , () async {
14921529 // TODO test date separators are maintained consistently too
14931530 // This tests the code that maintains the invariant that recipient headers
@@ -1741,6 +1778,11 @@ void checkInvariants(MessageListView model) {
17411778
17421779 check (model).contents.length.equals (model.messages.length);
17431780 for (int i = 0 ; i < model.contents.length; i++ ) {
1781+ final poll = model.messages[i].poll;
1782+ if (poll != null ) {
1783+ check (model).contents[i].isA <PollContent >().poll.identicalTo (poll);
1784+ continue ;
1785+ }
17441786 check (model.contents[i]).isA <ZulipContent >()
17451787 .equalsNode (parseContent (model.messages[i].content));
17461788 }
0 commit comments