fix: Set conditional wrapping for big messages on PDF transcript's react template (#32311)
parent
3b3275f686
commit
ad86761209
@ -0,0 +1,9 @@ |
||||
--- |
||||
"@rocket.chat/meteor": patch |
||||
"@rocket.chat/core-services": patch |
||||
"@rocket.chat/omnichannel-services": patch |
||||
"@rocket.chat/pdf-worker": patch |
||||
--- |
||||
|
||||
Fixed multiple issues with PDF generation logic when a quoted message was too big to fit in one single page. This was causing an internal infinite loop within the library (as it tried to make it fit, failing and then trying to fit on next page where the same happened thus causing a loop). |
||||
The library was not able to break down some nested views and thus was trying to fit the whole quote on one single page. Logic was updated to allow wrapping of the contents when messages are quoted (so they can span multiple lines) and removed a bunch of unnecesary views from the code. |
||||
@ -0,0 +1,5 @@ |
||||
export default { |
||||
preset: 'ts-jest', |
||||
errorOnDeprecated: true, |
||||
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/src/strategies/', '<rootDir>/src/templates/'], |
||||
}; |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,73 @@ |
||||
import fs from 'fs'; |
||||
|
||||
import { PdfWorker } from './index'; |
||||
import { |
||||
bigConversationData, |
||||
dataWithASingleMessageButAReallyLongMessage, |
||||
dataWithMultipleMessagesAndABigMessage, |
||||
dataWithASingleMessageAndAnImage, |
||||
} from './worker.fixtures'; |
||||
|
||||
const streamToBuffer = async (stream: NodeJS.ReadableStream) => { |
||||
const chunks: (string | Buffer)[] = []; |
||||
for await (const chunk of stream) { |
||||
chunks.push(chunk); |
||||
} |
||||
|
||||
return Buffer.concat(chunks as Buffer[]); |
||||
}; |
||||
|
||||
const pdfWorker = new PdfWorker('chat-transcript'); |
||||
|
||||
describe('PdfWorker', () => { |
||||
it('should fail to instantiate if no mode is provided', () => { |
||||
// @ts-expect-error - testing
|
||||
expect(() => new PdfWorker('')).toThrow(); |
||||
}); |
||||
it('should fail to instantiate if mode is invalid', () => { |
||||
// @ts-expect-error - testing
|
||||
expect(() => new PdfWorker('invalid')).toThrow(); |
||||
}); |
||||
it('should properly instantiate', () => { |
||||
const newWorker = new PdfWorker('chat-transcript'); |
||||
|
||||
expect(newWorker).toBeInstanceOf(PdfWorker); |
||||
expect(newWorker.mode).toBe('chat-transcript'); |
||||
}); |
||||
it('should generate a pdf transcript for a big bunch of messages', async () => { |
||||
const stream = await pdfWorker.renderToStream({ data: bigConversationData }); |
||||
const buffer = await streamToBuffer(stream); |
||||
|
||||
expect(buffer).toBeTruthy(); |
||||
}); |
||||
it('should generate a pdf transcript for a single message, but a really long message', async () => { |
||||
const stream = await pdfWorker.renderToStream({ data: dataWithASingleMessageButAReallyLongMessage }); |
||||
const buffer = await streamToBuffer(stream); |
||||
|
||||
expect(buffer).toBeTruthy(); |
||||
}); |
||||
|
||||
it('should generate a pdf transcript of a single message with an image', async () => { |
||||
const stream = await pdfWorker.renderToStream({ data: dataWithASingleMessageAndAnImage }); |
||||
const buffer = await streamToBuffer(stream); |
||||
|
||||
fs.writeFileSync('test.pdf', buffer); |
||||
expect(buffer).toBeTruthy(); |
||||
}); |
||||
|
||||
it('should generate a pdf transcript for multiple messages, one big message and 2 small messages', async () => { |
||||
const stream = await pdfWorker.renderToStream({ data: dataWithMultipleMessagesAndABigMessage }); |
||||
const buffer = await streamToBuffer(stream); |
||||
|
||||
expect(buffer).toBeTruthy(); |
||||
}); |
||||
|
||||
describe('isMimeTypeValid', () => { |
||||
it('should return true if mimeType is valid', () => { |
||||
expect(pdfWorker.isMimeTypeValid('image/png')).toBe(true); |
||||
}); |
||||
it('should return false if mimeType is not valid', () => { |
||||
expect(pdfWorker.isMimeTypeValid('image/svg')).toBe(false); |
||||
}); |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue