Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test content parsing; use Diagnosticable; write docs for ContentNode etc. #205

Merged
merged 14 commits into from
Jun 27, 2023

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Jun 27, 2023

This lays all the foundations we need in order to write tests for our content-parsing code, and then does so for all the existing code.

We'll want such tests for #71, which will add a new form of complication to that code. We'll also want it as we implement more features in the content parsing in general.

To get helpful debugging output when tests fail, we use the Diagnosticable class from Flutter to produce readable printouts of the content nodes:
https://api.flutter.dev/flutter/foundation/Diagnosticable-mixin.html
https://api.flutter.dev/flutter/foundation/Diagnosticable/debugFillProperties.html

Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM! Small comments below, then please merge at will.

Comment on lines 201 to 205
// We don't actually seem to need this information.
// We don't actually seem to need this information in code. Instead,
// the inner text already shows how to communicate it to the user.
// (E.g., silent mentions' text lacks a leading "@".)
// final UserMentionType mentionType;
// final bool isSilent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! The added explanation does help. 🙂

I wonder, though: does the inner text really make these two fields unnecessary? It seems convenient to have this information in this nice, structured way.

  • How can we distinguish a user mention from a group mention at least as efficiently as this? The inner text will just be the name of a user group or a user, like "mobile" or "Chris Bobbe", right? So we'll have to look in our data structures for the answer, and to do that efficiently we'd at least have to maintain dictionaries keyed by those names.
  • I think I've discovered a case where the inner text of a silent mention could start with "@": consider a silent mention of a user group that starts with "@".

(Hmm, and might we need to recognize wildcard mentions too, like @all?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely if/when we end up adding code that cares whether it's silent, or to a group, etc., we'll want to record that on the node, based on the classes the HTML element has. I wouldn't want to go inspect the text for an "@" to try to infer that (except as part of some regrettably-necessary workaround).

In particular I think we'll need to distinguish user vs. group when we go to do #157, the message-list redesign. In the pre-2023 design, though, both kinds of mentions are styled the same way, with the same gray-to-white gradient.

Looks confusing! We should maybe not allow user-group names (or user names, for that matter) to start with an "@".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks confusing! We should maybe not allow user-group names (or user names, for that matter) to start with an "@".

Started https://chat.zulip.org/#narrow/stream/9-issues/topic/.22.40.22.20in.20user.20group.20name/near/1599913 .

extension InlineContainerNodeChecks on Subject<InlineContainerNode> {
Subject<List<InlineContentNode>> get nodes => has((n) => n.nodes, 'nodes');
}

// TODO write similar extensions for the rest of the content node classes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content test: Extend equalsNode to cover all node types

Is this TODO still needed at this commit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yeah — looks like it's not.

There are some node classes with fields that aren't covered here — but those are classes with structural ==, and it's not clear we'll ever want Subject getters for them.

gnprice added 14 commits June 27, 2023 16:24
I wasn't sure what this comment meant when I came across it recently,
even though I wrote it myself.  Today I was writing tests for this
code and saw what the data looks like, and the meaning became clear.
Expand the comment so that it's hopefully clear to other readers
without having to see the data.
This abstraction doesn't pull a lot of weight yet, but it will
when we start tracking LinkNode descendants, for zulip#71.
As their new common superclass BlockInlineContainerNode shows,
these two have a lot in common.
@gnprice gnprice merged commit 99d5659 into zulip:main Jun 27, 2023
@gnprice gnprice deleted the pr-content-test branch June 27, 2023 23:25
@gnprice
Copy link
Member Author

gnprice commented Jun 27, 2023

Thanks for the review! Merged, with those tweaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants