From d8553a619f7f017bf1a9ce16bf7c422442bda095 Mon Sep 17 00:00:00 2001 From: kielllll Date: Tue, 26 Nov 2024 07:54:17 +0800 Subject: [PATCH] fix: restrict owner redirect test --- .../advanced-checks/pdf-restriction.test.js | 126 ++--- tests/e2e/utilities/page-model/helpers/pdf.js | 442 ++++++++++++------ 2 files changed, 367 insertions(+), 201 deletions(-) diff --git a/tests/e2e/advanced-checks/pdf-restriction.test.js b/tests/e2e/advanced-checks/pdf-restriction.test.js index 233dc325c..e1ddb3b9b 100644 --- a/tests/e2e/advanced-checks/pdf-restriction.test.js +++ b/tests/e2e/advanced-checks/pdf-restriction.test.js @@ -1,7 +1,8 @@ -import { RequestLogger, Role } from 'testcafe'; +import { RequestLogger, Role, Selector, t } from 'testcafe'; import { admin, baseURL, editor } from '../auth'; import AdvancedCheck from '../utilities/page-model/helpers/advanced-check'; import Page from '../utilities/page-model/helpers/page'; +import PageModel from '../models/Page'; import Pdf from '../utilities/page-model/helpers/pdf'; import { getQueryParam } from '../utilities/page-model/helpers/search-params'; @@ -10,14 +11,14 @@ let downloadUrl; const advancedCheck = new AdvancedCheck(); const page = new Page(); const pdf = new Pdf(); -const downloadLogger = RequestLogger( downloadUrl, { +const downloadLogger = RequestLogger(downloadUrl, { logResponseBody: true, logResponseHeaders: true, -} ); +}); fixture`PDF Administrator & Non-Administrator - Restriction Test`; -test( 'should throw an error when a non-administrator user try to access a PDF generated by an admin', async ( t ) => { +test('should throw an error when a non-administrator user try to access a PDF generated by an admin', async (t) => { // Actions & Assertions await advancedCheck.navigateSection( 'gf_edit_forms&view=settings&subview=PDF&id=4' @@ -25,103 +26,108 @@ test( 'should throw an error when a non-administrator user try to access a PDF g pdfId = await advancedCheck.shortcodeBox.getAttribute( 'data-clipboard-text' ); - pdfId = pdfId.substring( 30, 43 ); + pdfId = pdfId.substring(30, 43); await t - .useRole( editor ) - .navigateTo( `${ baseURL }?gpdf=1&pid=${ pdfId }&lid=4` ) - .expect( advancedCheck.pdfRestrictionErrorMessage.exists ) + .useRole(editor) + .navigateTo(`${baseURL}?gpdf=1&pid=${pdfId}&lid=4`) + .expect(advancedCheck.pdfRestrictionErrorMessage.exists) .ok(); -} ); - -test( "should redirect to WP login page if 'Restrict Owner' is enabled", async ( t ) => { - // Actions & Assertions - await advancedCheck.toggleRestrictOwnerCheckbox( - 'gf_edit_forms&view=settings&subview=PDF&id=4' - ); - await page.navigatePage(); - await page.addNewPage(); - await page.navigatePage(); +}); + +test("should redirect to WP login page if 'Restrict Owner' is enabled", async (t) => { + // Actions + // Toggle restrict owner checkbox + await pdf.navigatePdf('4'); + // Navigate to pdf info + await t.click(Selector('td.name').find('a').withText('Sample')); + // check if it's publicly accessed then turn off + if (pdf.enablePdfSecurityCheckbox.value === 'Yes') { + await t.click(pdf.enablePublicAccessCheckbox); + } + await t.click(pdf.restrictOwnerCheckbox).click(pdf.saveSettings); + + // Create a new page await t - .click( page.testPageLink ) - .click( page.addBlockIcon ) - .typeText( page.searchBlock.filterVisible(), 'shortcode', { - paste: true, - } ) - .click( page.shortcodeLink ) - .typeText( - page.shortcodeTextarea, + .setNativeDialogHandler(() => true) + .navigateTo(`${baseURL}/wp-admin/edit.php?post_type=page`); + const name = 'Restrict Owner Enabled'; + const pageModel = new PageModel(name); + await pageModel.add(); + await pageModel.insertBlock('shortcode', { + target: '.block-editor-plain-text', + content: '[gravityform id="4" title="false" description="false" ajax="true" tabindex="49"]', - { paste: true } - ) - .click( page.updateButton ); + }); + await pageModel.saveChanges(); + await pageModel.publishChanges(); - pdfId = await getQueryParam( 'post' ); + // Visit the page as anon user + pdfId = await getQueryParam('post'); await t - .useRole( Role.anonymous() ) - .navigateTo( `${ baseURL }/?page_id=${ pdfId }` ) - .typeText( advancedCheck.textInputField, 'texttest', { paste: true } ) - .click( advancedCheck.submitButton ) - .useRole( admin ); + .useRole(Role.anonymous()) + .navigateTo(`${baseURL}/?page_id=${pdfId}`) + .typeText(advancedCheck.textInputField, 'texttest', { paste: true }) + .click(advancedCheck.submitButton) + .useRole(admin); - await pdf.navigate( 'gf_entries&id=4' ); - downloadUrl = await advancedCheck.viewEntryLink.getAttribute( 'href' ); + await pdf.navigate('gf_entries&id=4'); + downloadUrl = await advancedCheck.viewEntryLink.getAttribute('href'); downloadLogger.clear(); await t - .addRequestHooks( downloadLogger ) - .useRole( Role.anonymous() ) - .navigateTo( downloadUrl ) - .removeRequestHooks( downloadLogger ); + .addRequestHooks(downloadLogger) + .useRole(Role.anonymous()) + .navigateTo(downloadUrl) + .removeRequestHooks(downloadLogger); + // Assertions await t .expect( downloadLogger.contains( - ( r ) => - r.response.headers[ 'content-type' ] === 'application/pdf' + (r) => r.response.headers['content-type'] === 'application/pdf' ) ) .notOk() - .expect( advancedCheck.pdfRestrictionErrorMessage.exists ) + .expect(advancedCheck.pdfRestrictionErrorMessage.exists) .notOk() - .expect( advancedCheck.wpLoginForm.exists ) + .expect(advancedCheck.wpLoginForm.exists) .ok(); -} ); +}); -test( 'reset/clean previous tests saved data and ensure PDF can be viewed by default', async ( t ) => { +test('reset/clean previous tests saved data and ensure PDF can be viewed by default', async (t) => { // Actions & Assertions await advancedCheck.toggleRestrictOwnerCheckbox( 'gf_edit_forms&view=settings&subview=PDF&id=4' ); await t - .useRole( Role.anonymous() ) - .navigateTo( `${ baseURL }/?page_id=${ pdfId }` ); + .useRole(Role.anonymous()) + .navigateTo(`${baseURL}/?page_id=${pdfId}`); await advancedCheck.submitNewPdfEntry(); - await t.useRole( admin ); - await pdf.navigate( 'gf_entries&id=4' ); + await t.useRole(admin); + await pdf.navigate('gf_entries&id=4'); - downloadUrl = await advancedCheck.viewEntryLink.getAttribute( 'href' ); + downloadUrl = await advancedCheck.viewEntryLink.getAttribute('href'); await page.deleteTestPage(); - await t.useRole( Role.anonymous() ); + await t.useRole(Role.anonymous()); downloadLogger.clear(); await t - .addRequestHooks( downloadLogger ) - .navigateTo( downloadUrl ) - .wait( 500 ) - .removeRequestHooks( downloadLogger ); + .addRequestHooks(downloadLogger) + .navigateTo(downloadUrl) + .wait(500) + .removeRequestHooks(downloadLogger); // Assertions await t .expect( downloadLogger.contains( - ( r ) => - r.response.headers[ 'content-type' ] === 'application/pdf' + (r) => r.response.headers['content-type'] === 'application/pdf' ) ) .ok(); -} ); +}); diff --git a/tests/e2e/utilities/page-model/helpers/pdf.js b/tests/e2e/utilities/page-model/helpers/pdf.js index 8d166ddd6..66b44b19f 100644 --- a/tests/e2e/utilities/page-model/helpers/pdf.js +++ b/tests/e2e/utilities/page-model/helpers/pdf.js @@ -1,145 +1,305 @@ -import { Selector, t } from 'testcafe' -import { admin, baseURL } from '../../../auth' -import { selectBox } from './field' +import { Selector, t } from 'testcafe'; +import { admin, baseURL } from '../../../auth'; +import { selectBox } from './field'; class Pdf { - constructor () { - this.template = Selector('.alternate') - this.saveSettings = Selector('#submit-and-promo-container').find('input') - - // General - Template field - this.templateSelectBox = selectBox('gfpdf_settings_template large', 'gfpdf_settings[template]') - - // General - Filename field - this.filenameInputBox = Selector('#gfpdf-settings-field-wrapper-filename').find('[id="gfpdf_settings[filename]"]') - this.filenameMergeTagsOptionList = Selector('#gfpdf-settings-field-wrapper-filename').find('button.gform-dropdown__control') - - // General - Conditional Logic field - this.conditionalLogicCheckbox = Selector('#gfpdf-settings-field-wrapper-conditional').find('[id="gfpdf_conditional_logic"]') - - // Appearance - Paper Size field - this.paperSizeSelectBox = Selector('#gfpdf-settings-field-wrapper-pdf_size').find('[id="gfpdf_settings[pdf_size]"]') - - // Appearance - Paper Orientation field - this.paperOrientationSelectBox = selectBox('gfpdf_settings_orientation large', 'gfpdf_settings[orientation]') - - // Appearance - Custom Paper Size field - this.customPaperSizeLabel = Selector('#gfpdf-settings-field-wrapper-custom_pdf_size').find('[class^="gform-settings-panel__title"]').withText('Custom Paper Size') - - // Appearance - Font field - this.fontSelectBox = selectBox('gfpdf_settings_font ', 'gfpdf_settings[font]') - - // Appearance - Font Size field - this.fontSizeInputBox = selectBox('small-text gfpdf_settings_font_size ', 'gfpdf_settings[font_size]') - - // Appearance - Font Color field - this.fontColorSelectButton = Selector('#gfpdf-settings-field-wrapper-font_colour').find('button').withText('Select Color') - this.fontColorWpPickerContainerActive = Selector('#gfpdf-settings-field-wrapper-font_colour').find('[class^="wp-picker-container wp-picker-active"]') - this.fontColorWpColorPickerBox = Selector('#gfpdf-settings-field-wrapper-font_colour').find('[class^="iris-picker iris-border"]') - this.fontColorInputBox = Selector('#gfpdf-settings-field-wrapper-font_colour').find('[id="gfpdf_settings[font_colour]"]') - - // Appearance - Reverse Text (RTL) field - this.rtlCheckbox = Selector('#gfpdf-settings-field-wrapper-rtl').find('[id="gfpdf_settings[rtl]"]') - - // Template - Show Form Title field - this.showFormTitleCheckbox = Selector('#gfpdf-settings-field-wrapper-show_form_title').find('[id="gfpdf_settings[show_form_title]"]') - - // Template - Show Page Names field - this.showPageNamesCheckbox = Selector('#gfpdf-settings-field-wrapper-show_page_names').find('[id="gfpdf_settings[show_page_names]"]') - - // Template - Show HTML Fields field - this.showHtmlFieldsCheckbox = Selector('#gfpdf-settings-field-wrapper-show_html').find('[id="gfpdf_settings[show_html]"]') - - // Template - Show Section Break Description field - this.showSectionBreakDescriptionCheckbox = Selector('#gfpdf-settings-field-wrapper-show_section_content').find('[id="gfpdf_settings[show_section_content]"]') - - // Template - Enable Conditional Logic field - this.enableConditionalLogicCheckbox = Selector('#gfpdf-settings-field-wrapper-enable_conditional').find('[id="gfpdf_settings[enable_conditional]"]') - - // Template - Show Empty Fields field - this.showEmptyFieldsCheckbox = Selector('#gfpdf-settings-field-wrapper-show_empty').find('[id="gfpdf_settings[show_empty]"]') - - // Template - Background Color field - this.backgroundColorInputBox = Selector('#gfpdf-settings-field-wrapper-background_color').find('[id="gfpdf_settings[background_color]"]') - this.backgroundColorWpPickerContainerActive = Selector('#gfpdf-settings-field-wrapper-background_color').find('[class^="wp-picker-container wp-picker-active"]') - this.backgroundColorWpColorPickerBox = Selector('#gfpdf-settings-field-wrapper-font_colour').find('[class^="iris-picker iris-border"]') - this.backgroundColorSelectButton = Selector('#gfpdf-settings-field-wrapper-background_color').find('button').withText('Select Color') - - // Template - Background Image field - this.backgroundImageUploadBox = selectBox('regular-text gfpdf_settings_background_image ', 'gfpdf_settings[background_image]') - this.backgroundImageUploadFileButton = Selector('.gfpdf-upload-setting-container').find('input').withAttribute('type', 'button') - - // Template - Header field - this.headerWpEditorBox = Selector('#gfpdf-settings-field-wrapper-header').find('[id="wp-gfpdf_settings_header-editor-container"]') - this.headerWpEditorBoxTextPanelLink = Selector('#gfpdf-settings-field-wrapper-header').find('.wp-editor-tabs').find('button').withText('Text') - this.headerWpEditorBoxContentArea = Selector('#gfpdf-settings-field-wrapper-header').find('[class^="gfpdf_settings_header"]') - - // Template - First Page Header field - this.firstPageHeaderCheckbox = Selector('#gfpdf-settings-field-wrapper-first_header').find('[class^="gfpdf-input-toggle"]') - this.firstPageHeaderWpEditorBox = Selector('#gfpdf-settings-field-wrapper-first_header').find('[id="wp-gfpdf_settings_first_header-editor-container"]') - this.firstPageHeaderWpEditorBoxTextPanelLink = Selector('#gfpdf-settings-field-wrapper-first_header').find('.wp-editor-tabs').find('button').withText('Text') - this.firstPageHeaderWpEditorBoxContentArea = Selector('#gfpdf-settings-field-wrapper-first_header').find('[class^="gfpdf_settings_first_header"]') - - // Template - Footer field - this.footerWpEditorBox = Selector('#gfpdf-settings-field-wrapper-footer').find('[id="wp-gfpdf_settings_footer-editor-container"]') - this.footerWpEditorBoxTextPanelLink = Selector('#gfpdf-settings-field-wrapper-footer').find('.wp-editor-tabs').find('button').withText('Text') - this.footerWpEditorBoxContentArea = Selector('#gfpdf-settings-field-wrapper-footer').find('[class^="gfpdf_settings_footer"]') - - // Template - First Page Footer field - this.firstPageFooterCheckbox = Selector('#gfpdf-settings-field-wrapper-first_footer').find('[class^="gfpdf-input-toggle"]') - this.firstPageFooterWpEditorBox = Selector('#gfpdf-settings-field-wrapper-first_footer').find('[id="wp-gfpdf_settings_first_footer-editor-container"]') - this.firstPageFooterWpEditorBoxTextPanelLink = Selector('#gfpdf-settings-field-wrapper-first_footer').find('.wp-editor-tabs').find('button').withText('Text') - this.firstPageFooterWpEditorBoxContentArea = Selector('#gfpdf-settings-field-wrapper-first_footer').find('[class^="gfpdf_settings_first_footer"]') - - // Advanced - Format field - this.formatStandardCheckbox = Selector('#gfpdf-settings-field-wrapper-format').find('[id="gfpdf_settings[format][Standard]"]') - this.formatPdfA1bCheckbox = Selector('#gfpdf-settings-field-wrapper-format').find('[id="gfpdf_settings[format][PDFA1B]"]') - this.formatPdfX1aCheckbox = Selector('#gfpdf-settings-field-wrapper-format').find('[id="gfpdf_settings[format][PDFX1A]"]') - this.enablePdfSecurityField = Selector('#gfpdf-settings-field-wrapper-security') - this.enablePdfSecurityCheckbox = Selector('#gfpdf-settings-field-wrapper-security').find('[id="gfpdf_settings[security]"]') - this.passwordField = Selector('#gfpdf-settings-field-wrapper-password') - this.privilegesField = Selector('#gfpdf-settings-field-wrapper-privileges') - - // Advanced - Enable PDF Security field - this.enablePdfSecurityCheckbox = Selector('#gfpdf-settings-field-wrapper-security').find('[id="gfpdf_settings[security]"]') - - // Advanced - Password field - this.passwordInputBox = Selector('#gfpdf-settings-field-wrapper-password').find('[id="gfpdf_settings[password]"]') - this.passwordMergeTagsOptionList = Selector('#gfpdf-settings-field-wrapper-password').find('button.gform-dropdown__control') - - // Advanced - Privileges field - this.copyCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][copy]"]') - this.printLowResolutionCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][print]"]') - this.printHighResolutionCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][print-highres]"]') - this.modifyCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][modify]"]') - this.annotateCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][annot-forms]"]') - this.fillFormsCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][fill-forms]"]') - this.extractCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][extract]"]') - this.assembleCheckbox = Selector('#gfpdf-settings-field-wrapper-privileges').find('[id="gfpdf_settings[privileges][assemble]"]') - - // Advanced - Image DPI field - this.imageDpiInputBox = Selector('#gfpdf-settings-field-wrapper-image_dpi').find('[id="gfpdf_settings[image_dpi]"]') - - // Advanced - Enable Public Access field - this.enablePublicAccessCheckbox = Selector('#gfpdf-settings-field-wrapper-public_access').find('[id="gfpdf_settings[public_access]"]') - - // Advanced - Restrict Owner field - this.restrictOwnerCheckbox = Selector('#gfpdf-settings-field-wrapper-restrict_owner').find('[id="gfpdf_settings[restrict_owner]"]') - } - - async navigatePdfSection (uri) { - await this.navigate(uri) - await t.click(Selector('#the-list') - .find('a') - .nth(0) - .withText('Sample')) - } - - async navigate (uri) { - await t - .setNativeDialogHandler(() => true) - .navigateTo(`${baseURL}/wp-admin/admin.php?page=${uri}`) - } + constructor() { + this.template = Selector('.alternate'); + this.saveSettings = Selector('#submit-and-promo-container').find( + 'input' + ); + + // General - Template field + this.templateSelectBox = selectBox( + 'gfpdf_settings_template large', + 'gfpdf_settings[template]' + ); + + // General - Filename field + this.filenameInputBox = Selector( + '#gfpdf-settings-field-wrapper-filename' + ).find('[id="gfpdf_settings[filename]"]'); + this.filenameMergeTagsOptionList = Selector( + '#gfpdf-settings-field-wrapper-filename' + ).find('button.gform-dropdown__control'); + + // General - Conditional Logic field + this.conditionalLogicCheckbox = Selector( + '#gfpdf-settings-field-wrapper-conditional' + ).find('[id="gfpdf_conditional_logic"]'); + + // Appearance - Paper Size field + this.paperSizeSelectBox = Selector( + '#gfpdf-settings-field-wrapper-pdf_size' + ).find('[id="gfpdf_settings[pdf_size]"]'); + + // Appearance - Paper Orientation field + this.paperOrientationSelectBox = selectBox( + 'gfpdf_settings_orientation large', + 'gfpdf_settings[orientation]' + ); + + // Appearance - Custom Paper Size field + this.customPaperSizeLabel = Selector( + '#gfpdf-settings-field-wrapper-custom_pdf_size' + ) + .find('[class^="gform-settings-panel__title"]') + .withText('Custom Paper Size'); + + // Appearance - Font field + this.fontSelectBox = selectBox( + 'gfpdf_settings_font ', + 'gfpdf_settings[font]' + ); + + // Appearance - Font Size field + this.fontSizeInputBox = selectBox( + 'small-text gfpdf_settings_font_size ', + 'gfpdf_settings[font_size]' + ); + + // Appearance - Font Color field + this.fontColorSelectButton = Selector( + '#gfpdf-settings-field-wrapper-font_colour' + ) + .find('button') + .withText('Select Color'); + this.fontColorWpPickerContainerActive = Selector( + '#gfpdf-settings-field-wrapper-font_colour' + ).find('[class^="wp-picker-container wp-picker-active"]'); + this.fontColorWpColorPickerBox = Selector( + '#gfpdf-settings-field-wrapper-font_colour' + ).find('[class^="iris-picker iris-border"]'); + this.fontColorInputBox = Selector( + '#gfpdf-settings-field-wrapper-font_colour' + ).find('[id="gfpdf_settings[font_colour]"]'); + + // Appearance - Reverse Text (RTL) field + this.rtlCheckbox = Selector('#gfpdf-settings-field-wrapper-rtl').find( + '[id="gfpdf_settings[rtl]"]' + ); + + // Template - Show Form Title field + this.showFormTitleCheckbox = Selector( + '#gfpdf-settings-field-wrapper-show_form_title' + ).find('[id="gfpdf_settings[show_form_title]"]'); + + // Template - Show Page Names field + this.showPageNamesCheckbox = Selector( + '#gfpdf-settings-field-wrapper-show_page_names' + ).find('[id="gfpdf_settings[show_page_names]"]'); + + // Template - Show HTML Fields field + this.showHtmlFieldsCheckbox = Selector( + '#gfpdf-settings-field-wrapper-show_html' + ).find('[id="gfpdf_settings[show_html]"]'); + + // Template - Show Section Break Description field + this.showSectionBreakDescriptionCheckbox = Selector( + '#gfpdf-settings-field-wrapper-show_section_content' + ).find('[id="gfpdf_settings[show_section_content]"]'); + + // Template - Enable Conditional Logic field + this.enableConditionalLogicCheckbox = Selector( + '#gfpdf-settings-field-wrapper-enable_conditional' + ).find('[id="gfpdf_settings[enable_conditional]"]'); + + // Template - Show Empty Fields field + this.showEmptyFieldsCheckbox = Selector( + '#gfpdf-settings-field-wrapper-show_empty' + ).find('[id="gfpdf_settings[show_empty]"]'); + + // Template - Background Color field + this.backgroundColorInputBox = Selector( + '#gfpdf-settings-field-wrapper-background_color' + ).find('[id="gfpdf_settings[background_color]"]'); + this.backgroundColorWpPickerContainerActive = Selector( + '#gfpdf-settings-field-wrapper-background_color' + ).find('[class^="wp-picker-container wp-picker-active"]'); + this.backgroundColorWpColorPickerBox = Selector( + '#gfpdf-settings-field-wrapper-font_colour' + ).find('[class^="iris-picker iris-border"]'); + this.backgroundColorSelectButton = Selector( + '#gfpdf-settings-field-wrapper-background_color' + ) + .find('button') + .withText('Select Color'); + + // Template - Background Image field + this.backgroundImageUploadBox = selectBox( + 'regular-text gfpdf_settings_background_image ', + 'gfpdf_settings[background_image]' + ); + this.backgroundImageUploadFileButton = Selector( + '.gfpdf-upload-setting-container' + ) + .find('input') + .withAttribute('type', 'button'); + + // Template - Header field + this.headerWpEditorBox = Selector( + '#gfpdf-settings-field-wrapper-header' + ).find('[id="wp-gfpdf_settings_header-editor-container"]'); + this.headerWpEditorBoxTextPanelLink = Selector( + '#gfpdf-settings-field-wrapper-header' + ) + .find('.wp-editor-tabs') + .find('button') + .withText('Text'); + this.headerWpEditorBoxContentArea = Selector( + '#gfpdf-settings-field-wrapper-header' + ).find('[class^="gfpdf_settings_header"]'); + + // Template - First Page Header field + this.firstPageHeaderCheckbox = Selector( + '#gfpdf-settings-field-wrapper-first_header' + ).find('[class^="gfpdf-input-toggle"]'); + this.firstPageHeaderWpEditorBox = Selector( + '#gfpdf-settings-field-wrapper-first_header' + ).find('[id="wp-gfpdf_settings_first_header-editor-container"]'); + this.firstPageHeaderWpEditorBoxTextPanelLink = Selector( + '#gfpdf-settings-field-wrapper-first_header' + ) + .find('.wp-editor-tabs') + .find('button') + .withText('Text'); + this.firstPageHeaderWpEditorBoxContentArea = Selector( + '#gfpdf-settings-field-wrapper-first_header' + ).find('[class^="gfpdf_settings_first_header"]'); + + // Template - Footer field + this.footerWpEditorBox = Selector( + '#gfpdf-settings-field-wrapper-footer' + ).find('[id="wp-gfpdf_settings_footer-editor-container"]'); + this.footerWpEditorBoxTextPanelLink = Selector( + '#gfpdf-settings-field-wrapper-footer' + ) + .find('.wp-editor-tabs') + .find('button') + .withText('Text'); + this.footerWpEditorBoxContentArea = Selector( + '#gfpdf-settings-field-wrapper-footer' + ).find('[class^="gfpdf_settings_footer"]'); + + // Template - First Page Footer field + this.firstPageFooterCheckbox = Selector( + '#gfpdf-settings-field-wrapper-first_footer' + ).find('[class^="gfpdf-input-toggle"]'); + this.firstPageFooterWpEditorBox = Selector( + '#gfpdf-settings-field-wrapper-first_footer' + ).find('[id="wp-gfpdf_settings_first_footer-editor-container"]'); + this.firstPageFooterWpEditorBoxTextPanelLink = Selector( + '#gfpdf-settings-field-wrapper-first_footer' + ) + .find('.wp-editor-tabs') + .find('button') + .withText('Text'); + this.firstPageFooterWpEditorBoxContentArea = Selector( + '#gfpdf-settings-field-wrapper-first_footer' + ).find('[class^="gfpdf_settings_first_footer"]'); + + // Advanced - Format field + this.formatStandardCheckbox = Selector( + '#gfpdf-settings-field-wrapper-format' + ).find('[id="gfpdf_settings[format][Standard]"]'); + this.formatPdfA1bCheckbox = Selector( + '#gfpdf-settings-field-wrapper-format' + ).find('[id="gfpdf_settings[format][PDFA1B]"]'); + this.formatPdfX1aCheckbox = Selector( + '#gfpdf-settings-field-wrapper-format' + ).find('[id="gfpdf_settings[format][PDFX1A]"]'); + this.enablePdfSecurityField = Selector( + '#gfpdf-settings-field-wrapper-security' + ); + this.enablePdfSecurityCheckbox = Selector( + '#gfpdf-settings-field-wrapper-security' + ).find('[id="gfpdf_settings[security]"]'); + this.passwordField = Selector('#gfpdf-settings-field-wrapper-password'); + this.privilegesField = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ); + + // Advanced - Enable PDF Security field + this.enablePdfSecurityCheckbox = Selector( + '#gfpdf-settings-field-wrapper-security' + ).find('[id="gfpdf_settings[security]"]'); + + // Advanced - Password field + this.passwordInputBox = Selector( + '#gfpdf-settings-field-wrapper-password' + ).find('[id="gfpdf_settings[password]"]'); + this.passwordMergeTagsOptionList = Selector( + '#gfpdf-settings-field-wrapper-password' + ).find('button.gform-dropdown__control'); + + // Advanced - Privileges field + this.copyCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][copy]"]'); + this.printLowResolutionCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][print]"]'); + this.printHighResolutionCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][print-highres]"]'); + this.modifyCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][modify]"]'); + this.annotateCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][annot-forms]"]'); + this.fillFormsCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][fill-forms]"]'); + this.extractCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][extract]"]'); + this.assembleCheckbox = Selector( + '#gfpdf-settings-field-wrapper-privileges' + ).find('[id="gfpdf_settings[privileges][assemble]"]'); + + // Advanced - Image DPI field + this.imageDpiInputBox = Selector( + '#gfpdf-settings-field-wrapper-image_dpi' + ).find('[id="gfpdf_settings[image_dpi]"]'); + + // Advanced - Enable Public Access field + this.enablePublicAccessCheckbox = Selector( + '#gfpdf-settings-field-wrapper-public_access' + ).find('[id="gfpdf_settings[public_access]"]'); + + // Advanced - Restrict Owner field + this.restrictOwnerCheckbox = Selector( + '#gfpdf-settings-field-wrapper-restrict_owner' + ).find('[id="gfpdf_settings[restrict_owner]"]'); + } + + async navigatePdfSection(uri) { + await this.navigate(uri); + await t.click( + Selector('#the-list').find('a').nth(0).withText('Sample') + ); + } + + async navigate(uri) { + await t + .setNativeDialogHandler(() => true) + .navigateTo(`${baseURL}/wp-admin/admin.php?page=${uri}`); + } + + /** + * Navigates to pdf section with a given id + * @param { string | number } id + * + * @return {Promise} none + */ + async navigatePdf(id) { + await t + .setNativeDialogHandler(() => true) + .navigateTo( + `${baseURL}/wp-admin/admin.php?page=gf_edit_forms&view=settings&subview=PDF&id=${id}` + ); + } } -export default Pdf +export default Pdf;