@@ -139,5 +139,47 @@ describe("SettingsStore", () => {
139
139
140
140
expect ( room . getAccountData ) . not . toHaveBeenCalled ( ) ;
141
141
} ) ;
142
+
143
+ describe ( "Migrate media preview configuration" , ( ) => {
144
+ beforeEach ( ( ) => {
145
+ client . getAccountData = jest . fn ( ) . mockImplementation ( ( type ) => {
146
+ if ( type === "im.vector.web.settings" ) {
147
+ return {
148
+ getContent : jest . fn ( ) . mockReturnValue ( {
149
+ showImages : false ,
150
+ showAvatarsOnInvites : false ,
151
+ } ) ,
152
+ } ;
153
+ } else {
154
+ return undefined ;
155
+ }
156
+ } ) ;
157
+ } ) ;
158
+
159
+ it ( "migrates media preview configuration" , async ( ) => {
160
+ client . setAccountData = jest . fn ( ) ;
161
+ SettingsStore . runMigrations ( false ) ;
162
+ client . emit ( ClientEvent . Sync , SyncState . Prepared , null ) ;
163
+ expect ( client . setAccountData ) . toHaveBeenCalledWith ( "io.element.msc4278.media_preview_config" , {
164
+ invite_avatars : "off" ,
165
+ media_previews : "off" ,
166
+ } ) ;
167
+ } ) ;
168
+
169
+ it ( "does not migrate media preview configuration if the session is fresh" , async ( ) => {
170
+ client . setAccountData = jest . fn ( ) ;
171
+ SettingsStore . runMigrations ( true ) ;
172
+ client . emit ( ClientEvent . Sync , SyncState . Prepared , null ) ;
173
+ expect ( client . setAccountData ) . not . toHaveBeenCalled ( ) ;
174
+ } ) ;
175
+
176
+ it ( "does not migrate media preview configuration if the account data is already set" , async ( ) => {
177
+ client . setAccountData = jest . fn ( ) ;
178
+ client . getAccountData = jest . fn ( ) . mockReturnValue ( { } ) ;
179
+ SettingsStore . runMigrations ( false ) ;
180
+ client . emit ( ClientEvent . Sync , SyncState . Prepared , null ) ;
181
+ expect ( client . setAccountData ) . not . toHaveBeenCalled ( ) ;
182
+ } ) ;
183
+ } ) ;
142
184
} ) ;
143
185
} ) ;
0 commit comments