[FIX] Katex is not respecting the 'Katex_Enabled' setting (#26542)
parent
0b8ebaeba8
commit
aa02a99d1f
@ -0,0 +1,86 @@ |
||||
import { renderHook } from '@testing-library/react-hooks'; |
||||
import { expect } from 'chai'; |
||||
import proxyquire from 'proxyquire'; |
||||
import sinon from 'sinon'; |
||||
|
||||
const date = new Date('2021-10-27T00:00:00.000Z'); |
||||
const baseMessage = { |
||||
ts: date, |
||||
u: { |
||||
_id: 'userId', |
||||
name: 'userName', |
||||
username: 'userName', |
||||
}, |
||||
msg: 'message', |
||||
rid: 'roomId', |
||||
_id: 'messageId', |
||||
_updatedAt: date, |
||||
urls: [], |
||||
}; |
||||
|
||||
const baseStubs = { |
||||
'./useAutotranslateLanguage': { |
||||
useAutotranslateLanguage: (): boolean => false, |
||||
}, |
||||
'@rocket.chat/ui-contexts': { |
||||
useSetting: (): boolean => false, |
||||
}, |
||||
}; |
||||
|
||||
describe('useParsedMessage', () => { |
||||
it('should call the parse function with message and parse options parameters if all settings is false', () => { |
||||
const messageParser = sinon.spy(); |
||||
const { useParsedMessage } = proxyquire.noCallThru().load('./useParsedMessage', { |
||||
...baseStubs, |
||||
'@rocket.chat/message-parser': { |
||||
parse: messageParser, |
||||
}, |
||||
}); |
||||
renderHook(() => useParsedMessage(baseMessage)); |
||||
|
||||
expect(messageParser.calledOnceWith(baseMessage.msg, { colors: false, emoticons: true })).to.be.true; |
||||
}); |
||||
|
||||
it('should call the parse function with katex in options parameters if Katex_Enabled is true', () => { |
||||
const messageParser = sinon.spy(); |
||||
const { useParsedMessage } = proxyquire.noCallThru().load('./useParsedMessage', { |
||||
...baseStubs, |
||||
'@rocket.chat/ui-contexts': { |
||||
useSetting: (setting: string): boolean => setting === 'Katex_Enabled', |
||||
}, |
||||
'@rocket.chat/message-parser': { |
||||
parse: messageParser, |
||||
}, |
||||
}); |
||||
renderHook(() => useParsedMessage(baseMessage)); |
||||
|
||||
expect( |
||||
messageParser.calledOnceWith(baseMessage.msg, { |
||||
colors: false, |
||||
emoticons: true, |
||||
katex: { dollarSyntax: false, parenthesisSyntax: false }, |
||||
}), |
||||
).to.be.true; |
||||
}); |
||||
|
||||
it('should call the parse function without katex in options parameters if Katex_Enabled is false', () => { |
||||
const messageParser = sinon.spy(); |
||||
const { useParsedMessage } = proxyquire.noCallThru().load('./useParsedMessage', { |
||||
...baseStubs, |
||||
'@rocket.chat/ui-contexts': { |
||||
useSetting: (setting: string): boolean => setting !== 'Katex_Enabled', |
||||
}, |
||||
'@rocket.chat/message-parser': { |
||||
parse: messageParser, |
||||
}, |
||||
}); |
||||
renderHook(() => useParsedMessage(baseMessage)); |
||||
|
||||
expect( |
||||
messageParser.calledOnceWith(baseMessage.msg, { |
||||
colors: true, |
||||
emoticons: true, |
||||
}), |
||||
).to.be.true; |
||||
}); |
||||
}); |
||||
@ -1,9 +0,0 @@ |
||||
import mock from 'mock-require'; |
||||
|
||||
mock('meteor/meteor', { |
||||
Meteor: { |
||||
absoluteUrl() { |
||||
return 'http://localhost:3000/'; |
||||
}, |
||||
}, |
||||
}); |
||||
@ -1,61 +1,30 @@ |
||||
import mock from 'mock-require'; |
||||
import proxyquire from 'proxyquire'; |
||||
import _ from 'underscore'; |
||||
import s from 'underscore.string'; |
||||
|
||||
_.mixin(s.exports()); |
||||
|
||||
mock('meteor/meteor', { |
||||
Meteor: { |
||||
absoluteUrl() { |
||||
return 'http://localhost:3000/'; |
||||
const mocks = { |
||||
'meteor/meteor': { |
||||
'Meteor': { |
||||
absoluteUrl() { |
||||
return 'http://localhost:3000/'; |
||||
}, |
||||
}, |
||||
'@global': true, |
||||
}, |
||||
}); |
||||
|
||||
mock('meteor/blaze', { |
||||
Blaze: {}, |
||||
}); |
||||
|
||||
mock('../../../../app/settings', { |
||||
settings: { |
||||
get(setting) { |
||||
switch (setting) { |
||||
case 'DeepLink_Url': |
||||
return 'https://go.rocket.chat'; |
||||
case 'Markdown_SupportSchemesForLink': |
||||
return 'http,https'; |
||||
case 'Markdown_Parser': |
||||
return 'original'; |
||||
case 'Markdown_Headers': |
||||
// case 'Markdown_Marked_GFM':
|
||||
// case 'Markdown_Marked_Tables':
|
||||
// case 'Markdown_Marked_Breaks':
|
||||
// case 'Markdown_Marked_Pedantic':
|
||||
// case 'Markdown_Marked_SmartLists':
|
||||
// case 'Markdown_Marked_Smartypants':
|
||||
return true; |
||||
default: |
||||
throw new Error(`Missing setting mock ${setting}`); |
||||
} |
||||
'meteor/random': { |
||||
'Random': { |
||||
id() { |
||||
return Math.random().toString().replace('0.', 'A'); |
||||
}, |
||||
}, |
||||
'@global': true, |
||||
}, |
||||
}); |
||||
}; |
||||
|
||||
mock('../../callbacks', { |
||||
callbacks: { |
||||
add() {}, |
||||
priority: { |
||||
HIGH: 1, |
||||
}, |
||||
}, |
||||
}); |
||||
|
||||
mock('meteor/random', { |
||||
Random: { |
||||
id() { |
||||
return Math.random().toString().replace('0.', 'A'); |
||||
}, |
||||
}, |
||||
}); |
||||
export const { Markdown } = proxyquire.noCallThru().load('../../../../app/markdown/lib/markdown', mocks); |
||||
export const { original } = proxyquire.noCallThru().load('../../../../app/markdown/lib/parser/original/original', mocks); |
||||
export const { filtered } = proxyquire.noCallThru().load('../../../../app/markdown/lib/parser/filtered/filtered', mocks); |
||||
|
||||
global.s = s; |
||||
|
||||
@ -1,7 +0,0 @@ |
||||
import mock from 'mock-require'; |
||||
|
||||
mock('/app/emoji', { |
||||
emoji: { |
||||
list: {}, |
||||
}, |
||||
}); |
||||
Loading…
Reference in new issue