Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extension/chrome/elements/pgp_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class PgpBlockView extends View {
};

public setHandlers = () => {
// Disable print button initially until printMailInfoHtml is ready
$('.pgp_print_button').prop('disabled', true).attr('data-test-print-ready', 'false');
$('.pgp_print_button').on(
'click',
this.setHandler(() => this.printModule.printPGPBlock())
Expand Down Expand Up @@ -148,6 +150,8 @@ export class PgpBlockView extends View {
if (data?.printMailInfo) {
Xss.sanitizeRender('.print_user_email', data.printMailInfo.userNameAndEmail);
this.printModule.printMailInfoHtml = data.printMailInfo.html;
// Enable print button now that data is ready
$('.pgp_print_button').prop('disabled', false).attr('data-test-print-ready', 'true');
}
if (data?.renderAsRegularContent) {
this.renderModule.renderAsRegularContent(data.renderAsRegularContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ export class PgpBlockViewPrintModule {
public printMailInfoHtml: string | undefined;

public printPGPBlock = async () => {
// If printMailInfoHtml is not yet prepared, wait briefly to handle race conditions
// printMailInfoHtml should always be set when this function is called
// because the print button is disabled until the data arrives
if (!this.printMailInfoHtml) {
for (let i = 0; i < 6 && !this.printMailInfoHtml; i++) {
await Time.sleep(200);
}
}
// If still not prepared, skip printing entirely
if (!this.printMailInfoHtml) {
// Last resort: inform the user
void Ui.modal.error('Unable to get metadata for this email. Please refresh the page and try again.');
Catch.reportErr('printMailInfoHtml not prepared!');
return;
Expand Down
5 changes: 3 additions & 2 deletions test/source/tests/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,15 +1183,16 @@ XZ8r4OC6sguP/yozWlkG+7dDxsgKQVBENeG6Lw==
})
);

// https://github.com/FlowCrypt/flowcrypt-browser/issues/6145
test.skip(
test(
'decrypt - print feature in pgp block',
testWithBrowser(async (t, browser) => {
const msgId = '18ecbf57e1dfb9b5';
const testPrintBlockInPage = async (page: ControllablePage) => {
await page.waitForIframes();
const pgpBlock = await page.getFrame(['pgp_block.htm']);
await pgpBlock.waitForSelTestState('ready');
// Wait for print button to be enabled (data-test-print-ready="true")
await pgpBlock.waitAll('[data-test="action-print"][data-test-print-ready="true"]', { timeout: 30 });
const expectedPrintDateString = new Date(1712818847000).toLocaleString();
const printPage = await browser.newPageTriggeredBy(t, () => pgpBlock.click('@action-print'));
await printPage.waitForContent('@print-date', expectedPrintDateString);
Expand Down
Loading