@@ -14,26 +14,59 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ import { MatrixEvent , Room } from "matrix-js-sdk/src/matrix" ;
18
+
17
19
import { createTestClient , mkStubRoom , REPEATABLE_DATE } from "../../test-utils" ;
18
20
import { ExportType , IExportOptions } from "../../../src/utils/exportUtils/exportUtils" ;
19
21
import PlainTextExporter from "../../../src/utils/exportUtils/PlainTextExport" ;
22
+ import SettingsStore from "../../../src/settings/SettingsStore" ;
23
+
24
+ class TestablePlainTextExporter extends PlainTextExporter {
25
+ public async testCreateOutput ( events : MatrixEvent [ ] ) : Promise < string > {
26
+ return this . createOutput ( events ) ;
27
+ }
28
+ }
20
29
21
30
describe ( "PlainTextExport" , ( ) => {
31
+ let stubOptions : IExportOptions ;
32
+ let stubRoom : Room ;
22
33
beforeEach ( ( ) => {
23
34
jest . useFakeTimers ( ) ;
24
35
jest . setSystemTime ( REPEATABLE_DATE ) ;
25
- } ) ;
26
-
27
- it ( "should have a Matrix-branded destination file name" , ( ) => {
28
36
const roomName = "My / Test / Room: Welcome" ;
29
37
const client = createTestClient ( ) ;
30
- const stubOptions : IExportOptions = {
38
+ stubOptions = {
31
39
attachmentsIncluded : false ,
32
40
maxSize : 50000000 ,
33
41
} ;
34
- const stubRoom = mkStubRoom ( "!myroom:example.org" , roomName , client ) ;
42
+ stubRoom = mkStubRoom ( "!myroom:example.org" , roomName , client ) ;
43
+ } ) ;
44
+
45
+ it ( "should have a Matrix-branded destination file name" , ( ) => {
35
46
const exporter = new PlainTextExporter ( stubRoom , ExportType . Timeline , stubOptions , ( ) => { } ) ;
36
47
37
48
expect ( exporter . destinationFileName ) . toMatchSnapshot ( ) ;
38
49
} ) ;
50
+
51
+ it . each ( [
52
+ [ 24 , false , "Fri, Apr 16 2021 17:20:00 - @alice:example.com: Hello, world!\n" ] ,
53
+ [ 12 , true , "Fri, Apr 16 2021 5:20:00PM - @alice:example.com: Hello, world!\n" ] ,
54
+ ] ) ( "should return text with %i hr time format" , async ( hour : number , setting : boolean , expectedMessage : string ) => {
55
+ jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation ( ( settingName : string ) =>
56
+ settingName === "showTwelveHourTimestamps" ? setting : undefined ,
57
+ ) ;
58
+ const events : MatrixEvent [ ] = [
59
+ new MatrixEvent ( {
60
+ type : "m.room.message" ,
61
+ content : {
62
+ body : "Hello, world!" ,
63
+ } ,
64
+ sender : "@alice:example.com" ,
65
+ origin_server_ts : 1618593600000 ,
66
+ } ) ,
67
+ ] ;
68
+ const exporter = new TestablePlainTextExporter ( stubRoom , ExportType . Timeline , stubOptions , ( ) => { } ) ;
69
+ const output = await exporter . testCreateOutput ( events ) ;
70
+ expect ( output ) . toBe ( expectedMessage ) ;
71
+ } ) ;
39
72
} ) ;
0 commit comments