- 
                Notifications
    You must be signed in to change notification settings 
- Fork 348
Respect realm setting for mandatory topics #1296
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      8decc4e
              
                store test: Check for data consistency when adding account
              
              
                PIG208 3098349
              
                store: Add realmMandatoryTopics realm setting
              
              
                PIG208 9e5f803
              
                compose test [nfc]: Remove unused prepareComposeBox param
              
              
                PIG208 f76b003
              
                compose test [nfc]: Rename param from user to otherUsers
              
              
                PIG208 f1646c4
              
                compose: Respect realm setting for mandatory topics
              
              
                PIG208 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -44,9 +44,9 @@ void main() { | |
| Future<void> prepareComposeBox(WidgetTester tester, { | ||
| required Narrow narrow, | ||
| User? selfUser, | ||
| int? realmWaitingPeriodThreshold, | ||
| List<User> users = const [], | ||
| List<User> otherUsers = const [], | ||
| 
      Comment on lines
    
      -48
     to 
      +47
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the commit message says  | ||
| List<ZulipStream> streams = const [], | ||
| bool? mandatoryTopics, | ||
| }) async { | ||
| if (narrow case ChannelNarrow(:var streamId) || TopicNarrow(: var streamId)) { | ||
| assert(streams.any((stream) => stream.streamId == streamId), | ||
|  | @@ -56,11 +56,12 @@ void main() { | |
| selfUser ??= eg.selfUser; | ||
| final selfAccount = eg.account(user: selfUser); | ||
| await testBinding.globalStore.add(selfAccount, eg.initialSnapshot( | ||
| realmWaitingPeriodThreshold: realmWaitingPeriodThreshold)); | ||
| realmMandatoryTopics: mandatoryTopics, | ||
| )); | ||
|  | ||
| store = await testBinding.globalStore.perAccount(selfAccount.id); | ||
|  | ||
| await store.addUsers([selfUser, ...users]); | ||
| await store.addUsers([selfUser, ...otherUsers]); | ||
| await store.addStreams(streams); | ||
| connection = store.connection as FakeApiConnection; | ||
|  | ||
|  | @@ -560,6 +561,60 @@ void main() { | |
| }); | ||
| }); | ||
|  | ||
| group('sending to empty topic', () { | ||
| late ZulipStream channel; | ||
|  | ||
| Future<void> setupAndTapSend(WidgetTester tester, { | ||
| required String topicInputText, | ||
| required bool mandatoryTopics, | ||
| }) async { | ||
| TypingNotifier.debugEnable = false; | ||
| addTearDown(TypingNotifier.debugReset); | ||
|  | ||
| channel = eg.stream(); | ||
| final narrow = ChannelNarrow(channel.streamId); | ||
| await prepareComposeBox(tester, | ||
| narrow: narrow, streams: [channel], | ||
| mandatoryTopics: mandatoryTopics); | ||
|  | ||
| await enterTopic(tester, narrow: narrow, topic: topicInputText); | ||
| await tester.enterText(contentInputFinder, 'test content'); | ||
| await tester.tap(find.byIcon(ZulipIcons.send)); | ||
| await tester.pump(); | ||
| } | ||
|  | ||
| void checkMessageNotSent(WidgetTester tester) { | ||
| check(connection.takeRequests()).isEmpty(); | ||
| checkErrorDialog(tester, | ||
| expectedTitle: 'Message not sent', | ||
| expectedMessage: 'Topics are required in this organization.'); | ||
| } | ||
|  | ||
| testWidgets('empty topic -> "(no topic)"', (tester) async { | ||
| await setupAndTapSend(tester, | ||
| topicInputText: '', | ||
| mandatoryTopics: false); | ||
| check(connection.lastRequest).isA<http.Request>() | ||
| ..method.equals('POST') | ||
| ..url.path.equals('/api/v1/messages') | ||
| ..bodyFields['topic'].equals('(no topic)'); | ||
| }); | ||
|  | ||
| testWidgets('if topics are mandatory, reject empty topic', (tester) async { | ||
| await setupAndTapSend(tester, | ||
| topicInputText: '', | ||
| mandatoryTopics: true); | ||
| checkMessageNotSent(tester); | ||
| }); | ||
|  | ||
| testWidgets('if topics are mandatory, reject "(no topic)"', (tester) async { | ||
| await setupAndTapSend(tester, | ||
| topicInputText: '(no topic)', | ||
| mandatoryTopics: true); | ||
| checkMessageNotSent(tester); | ||
| }); | ||
| }); | ||
|  | ||
| group('uploads', () { | ||
| void checkAppearsLoading(WidgetTester tester, bool expected) { | ||
| final sendButtonElement = tester.element(find.ancestor( | ||
|  | @@ -748,15 +803,15 @@ void main() { | |
| testWidgets('compose box replaced with a banner', (tester) async { | ||
| final deactivatedUser = eg.user(isActive: false); | ||
| await prepareComposeBox(tester, narrow: dmNarrowWith(deactivatedUser), | ||
| users: [deactivatedUser]); | ||
| otherUsers: [deactivatedUser]); | ||
| checkComposeBox(isShown: false); | ||
| }); | ||
|  | ||
| testWidgets('active user becomes deactivated -> ' | ||
| 'compose box is replaced with a banner', (tester) async { | ||
| final activeUser = eg.user(isActive: true); | ||
| await prepareComposeBox(tester, narrow: dmNarrowWith(activeUser), | ||
| users: [activeUser]); | ||
| otherUsers: [activeUser]); | ||
| checkComposeBox(isShown: true); | ||
|  | ||
| await changeUserStatus(tester, user: activeUser, isActive: false); | ||
|  | @@ -767,7 +822,7 @@ void main() { | |
| 'banner is replaced with the compose box', (tester) async { | ||
| final deactivatedUser = eg.user(isActive: false); | ||
| await prepareComposeBox(tester, narrow: dmNarrowWith(deactivatedUser), | ||
| users: [deactivatedUser]); | ||
| otherUsers: [deactivatedUser]); | ||
| checkComposeBox(isShown: false); | ||
|  | ||
| await changeUserStatus(tester, user: deactivatedUser, isActive: true); | ||
|  | @@ -779,15 +834,15 @@ void main() { | |
| testWidgets('compose box replaced with a banner', (tester) async { | ||
| final deactivatedUsers = [eg.user(isActive: false), eg.user(isActive: false)]; | ||
| await prepareComposeBox(tester, narrow: groupDmNarrowWith(deactivatedUsers), | ||
| users: deactivatedUsers); | ||
| otherUsers: deactivatedUsers); | ||
| checkComposeBox(isShown: false); | ||
| }); | ||
|  | ||
| testWidgets('at least one user becomes deactivated -> ' | ||
| 'compose box is replaced with a banner', (tester) async { | ||
| final activeUsers = [eg.user(isActive: true), eg.user(isActive: true)]; | ||
| await prepareComposeBox(tester, narrow: groupDmNarrowWith(activeUsers), | ||
| users: activeUsers); | ||
| otherUsers: activeUsers); | ||
| checkComposeBox(isShown: true); | ||
|  | ||
| await changeUserStatus(tester, user: activeUsers[0], isActive: false); | ||
|  | @@ -798,7 +853,7 @@ void main() { | |
| 'banner is replaced with the compose box', (tester) async { | ||
| final deactivatedUsers = [eg.user(isActive: false), eg.user(isActive: false)]; | ||
| await prepareComposeBox(tester, narrow: groupDmNarrowWith(deactivatedUsers), | ||
| users: deactivatedUsers); | ||
| otherUsers: deactivatedUsers); | ||
| checkComposeBox(isShown: false); | ||
|  | ||
| await changeUserStatus(tester, user: deactivatedUsers[0], isActive: true); | ||
|  | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit-message nit:
For readability, I like use just the first 9 characters of a commit ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump on truncating commit IDs to 9 characters :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed that. Fixed!