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' ;
@@ -46,10 +45,11 @@ describe('constructActionButtons', () => {
46
45
} ) ;
47
46
48
47
describe ( 'constructTopicActionButtons' , ( ) => {
49
- const streamMessage = eg . streamMessage ( ) ;
50
- const streamName = streamNameOfStreamMessage ( streamMessage ) ;
48
+ const stream = eg . makeStream ( ) ;
49
+ const streamMessage = eg . streamMessage ( { stream } ) ;
51
50
const topic = streamMessage . subject ;
52
51
const streamId = streamMessage . stream_id ;
52
+ const streams = deepFreeze ( new Map ( [ [ stream . stream_id , stream ] ] ) ) ;
53
53
54
54
const baseState = ( ( ) => {
55
55
const r = ( state , action ) => reducer ( state , action , eg . plusReduxState ) ;
@@ -61,8 +61,7 @@ describe('constructTopicActionButtons', () => {
61
61
test ( 'show mark as read if topic is unread' , ( ) => {
62
62
const unread = baseState ;
63
63
const buttons = constructTopicActionButtons ( {
64
- backgroundData : { ...eg . backgroundData , unread } ,
65
- streamName,
64
+ backgroundData : { ...eg . backgroundData , streams, unread } ,
66
65
streamId,
67
66
topic,
68
67
} ) ;
@@ -71,19 +70,17 @@ describe('constructTopicActionButtons', () => {
71
70
72
71
test ( 'do not show mark as read if topic is read' , ( ) => {
73
72
const buttons = constructTopicActionButtons ( {
74
- backgroundData : eg . backgroundData ,
75
- streamName,
73
+ backgroundData : { ...eg . backgroundData , streams } ,
76
74
streamId,
77
75
topic,
78
76
} ) ;
79
77
expect ( buttonTitles ( buttons ) ) . not . toContain ( 'Mark topic as read' ) ;
80
78
} ) ;
81
79
82
80
test ( 'show Unmute topic option if topic is muted' , ( ) => {
83
- const mute = deepFreeze ( [ [ streamName , topic ] ] ) ;
81
+ const mute = deepFreeze ( [ [ stream . name , topic ] ] ) ;
84
82
const buttons = constructTopicActionButtons ( {
85
- backgroundData : { ...eg . backgroundData , mute } ,
86
- streamName,
83
+ backgroundData : { ...eg . backgroundData , streams, mute } ,
87
84
streamId,
88
85
topic,
89
86
} ) ;
@@ -92,30 +89,27 @@ describe('constructTopicActionButtons', () => {
92
89
93
90
test ( 'show mute topic option if topic is not muted' , ( ) => {
94
91
const buttons = constructTopicActionButtons ( {
95
- backgroundData : { ...eg . backgroundData , mute : [ ] } ,
96
- streamName,
92
+ backgroundData : { ...eg . backgroundData , streams, mute : [ ] } ,
97
93
streamId,
98
94
topic,
99
95
} ) ;
100
96
expect ( buttonTitles ( buttons ) ) . toContain ( 'Mute topic' ) ;
101
97
} ) ;
102
98
103
99
test ( 'show Unmute stream option if stream is not in home view' , ( ) => {
104
- const subscriptions = [ { ...eg . subscription , in_home_view : false } ] ;
100
+ const subscriptions = [ { ...eg . subscription , in_home_view : false , ... stream } ] ;
105
101
const buttons = constructTopicActionButtons ( {
106
- backgroundData : { ...eg . backgroundData , subscriptions } ,
107
- streamName,
102
+ backgroundData : { ...eg . backgroundData , subscriptions, streams } ,
108
103
streamId,
109
104
topic,
110
105
} ) ;
111
106
expect ( buttonTitles ( buttons ) ) . toContain ( 'Unmute stream' ) ;
112
107
} ) ;
113
108
114
109
test ( 'show mute stream option if stream is in home view' , ( ) => {
115
- const subscriptions = [ { ...eg . subscription , in_home_view : true } ] ;
110
+ const subscriptions = [ { ...eg . subscription , in_home_view : true , ... stream } ] ;
116
111
const buttons = constructTopicActionButtons ( {
117
- backgroundData : { ...eg . backgroundData , subscriptions } ,
118
- streamName,
112
+ backgroundData : { ...eg . backgroundData , subscriptions, streams } ,
119
113
streamId,
120
114
topic,
121
115
} ) ;
@@ -125,8 +119,7 @@ describe('constructTopicActionButtons', () => {
125
119
test ( 'show delete topic option if current user is an admin' , ( ) => {
126
120
const ownUser = { ...eg . selfUser , is_admin : true } ;
127
121
const buttons = constructTopicActionButtons ( {
128
- backgroundData : { ...eg . backgroundData , ownUser } ,
129
- streamName,
122
+ backgroundData : { ...eg . backgroundData , ownUser, streams } ,
130
123
streamId,
131
124
topic,
132
125
} ) ;
@@ -135,8 +128,7 @@ describe('constructTopicActionButtons', () => {
135
128
136
129
test ( 'do not show delete topic option if current user is not an admin' , ( ) => {
137
130
const buttons = constructTopicActionButtons ( {
138
- backgroundData : eg . backgroundData ,
139
- streamName,
131
+ backgroundData : { ...eg . backgroundData , streams } ,
140
132
streamId,
141
133
topic,
142
134
} ) ;
0 commit comments