1
1
// @flow strict-local
2
2
import deepFreeze from 'deep-freeze' ;
3
3
import { HOME_NARROW } from '../../utils/narrow' ;
4
- import { streamNameOfStreamMessage } from '../../utils/recipient' ;
5
4
6
5
import * as eg from '../../__tests__/lib/exampleData' ;
7
6
import { constructMessageActionButtons , constructTopicActionButtons } from '../messageActionSheet' ;
@@ -62,10 +61,11 @@ describe('constructActionButtons', () => {
62
61
} ) ;
63
62
64
63
describe ( 'constructTopicActionButtons' , ( ) => {
65
- const streamMessage = eg . streamMessage ( ) ;
66
- const streamName = streamNameOfStreamMessage ( streamMessage ) ;
64
+ const stream = eg . makeStream ( ) ;
65
+ const streamMessage = eg . streamMessage ( { stream } ) ;
67
66
const topic = streamMessage . subject ;
68
67
const streamId = streamMessage . stream_id ;
68
+ const streams = deepFreeze ( new Map ( [ [ streamMessage . stream_id , stream ] ] ) ) ;
69
69
70
70
const baseState = ( ( ) => {
71
71
const r = ( state , action ) => reducer ( state , action , eg . plusReduxState ) ;
@@ -77,8 +77,7 @@ describe('constructTopicActionButtons', () => {
77
77
test ( 'show mark as read if topic is unread' , ( ) => {
78
78
const unreadStreams = baseState . streams ;
79
79
const buttons = constructTopicActionButtons ( {
80
- backgroundData : { ...baseBackgroundData , unreadStreams } ,
81
- streamName,
80
+ backgroundData : { ...baseBackgroundData , streams, unreadStreams } ,
82
81
streamId,
83
82
topic,
84
83
} ) ;
@@ -87,19 +86,17 @@ describe('constructTopicActionButtons', () => {
87
86
88
87
test ( 'do not show mark as read if topic is read' , ( ) => {
89
88
const buttons = constructTopicActionButtons ( {
90
- backgroundData : baseBackgroundData ,
91
- streamName,
89
+ backgroundData : { ...baseBackgroundData , streams } ,
92
90
streamId,
93
91
topic,
94
92
} ) ;
95
93
expect ( buttonTitles ( buttons ) ) . not . toContain ( 'Mark topic as read' ) ;
96
94
} ) ;
97
95
98
96
test ( 'show Unmute topic option if topic is muted' , ( ) => {
99
- const mute = deepFreeze ( [ [ streamName , topic ] ] ) ;
97
+ const mute = deepFreeze ( [ [ stream . name , topic ] ] ) ;
100
98
const buttons = constructTopicActionButtons ( {
101
- backgroundData : { ...baseBackgroundData , mute } ,
102
- streamName,
99
+ backgroundData : { ...baseBackgroundData , streams, mute } ,
103
100
streamId,
104
101
topic,
105
102
} ) ;
@@ -108,30 +105,27 @@ describe('constructTopicActionButtons', () => {
108
105
109
106
test ( 'show mute topic option if topic is not muted' , ( ) => {
110
107
const buttons = constructTopicActionButtons ( {
111
- backgroundData : { ...baseBackgroundData , mute : [ ] } ,
112
- streamName,
108
+ backgroundData : { ...baseBackgroundData , streams, mute : [ ] } ,
113
109
streamId,
114
110
topic,
115
111
} ) ;
116
112
expect ( buttonTitles ( buttons ) ) . toContain ( 'Mute topic' ) ;
117
113
} ) ;
118
114
119
115
test ( 'show Unmute stream option if stream is not in home view' , ( ) => {
120
- const subscriptions = [ { ...eg . subscription , in_home_view : false } ] ;
116
+ const subscriptions = [ { ...eg . subscription , in_home_view : false , ... stream } ] ;
121
117
const buttons = constructTopicActionButtons ( {
122
- backgroundData : { ...baseBackgroundData , subscriptions } ,
123
- streamName,
118
+ backgroundData : { ...baseBackgroundData , subscriptions, streams } ,
124
119
streamId,
125
120
topic,
126
121
} ) ;
127
122
expect ( buttonTitles ( buttons ) ) . toContain ( 'Unmute stream' ) ;
128
123
} ) ;
129
124
130
125
test ( 'show mute stream option if stream is in home view' , ( ) => {
131
- const subscriptions = [ { ...eg . subscription , in_home_view : true } ] ;
126
+ const subscriptions = [ { ...eg . subscription , in_home_view : true , ... stream } ] ;
132
127
const buttons = constructTopicActionButtons ( {
133
- backgroundData : { ...baseBackgroundData , subscriptions } ,
134
- streamName,
128
+ backgroundData : { ...baseBackgroundData , subscriptions, streams } ,
135
129
streamId,
136
130
topic,
137
131
} ) ;
@@ -141,8 +135,7 @@ describe('constructTopicActionButtons', () => {
141
135
test ( 'show delete topic option if current user is an admin' , ( ) => {
142
136
const ownUser = { ...eg . selfUser , is_admin : true } ;
143
137
const buttons = constructTopicActionButtons ( {
144
- backgroundData : { ...baseBackgroundData , ownUser } ,
145
- streamName,
138
+ backgroundData : { ...baseBackgroundData , ownUser, streams } ,
146
139
streamId,
147
140
topic,
148
141
} ) ;
@@ -151,8 +144,7 @@ describe('constructTopicActionButtons', () => {
151
144
152
145
test ( 'do not show delete topic option if current user is not an admin' , ( ) => {
153
146
const buttons = constructTopicActionButtons ( {
154
- backgroundData : baseBackgroundData ,
155
- streamName,
147
+ backgroundData : { ...baseBackgroundData , streams } ,
156
148
streamId,
157
149
topic,
158
150
} ) ;
0 commit comments