Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should display non-template reusable blocks in the reusable blocks management screen', async () => {
const titleSelector = '.page-title .row-title';
await visitAdminPage( 'edit.php', 'post_type=wp_block' );
await page.waitForSelector( titleSelector );
// Check that it is untitled
const title = await page.$eval(
titleSelector,
( element ) => element.innerText,
);
expect( title ).toBe( 'Untitled Reusable Block' );
} );
export async function enrollStudent( postId, studentId ) {
await visitAdminPage( 'post.php', `post=${ postId }&action=edit` );
await setSelect2Option( '#llms-add-student-select', studentId );
await click( '#llms-enroll-students' );
// Lazy waiting for ajax save.
await page.waitFor( 2000 );
}
async function trashExistingPosts() {
await switchUserToAdmin();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
await visitAdminPage( 'edit.php' );
// If this selector doesn't exist there are no posts for us to delete.
const bulkSelector = await page.$( '#bulk-action-selector-top' );
if ( ! bulkSelector ) {
return;
}
// Select all posts.
await page.waitForSelector( '#cb-select-all-1' );
await page.click( '#cb-select-all-1' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-top', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
await page.click( '#doaction' );
await page.waitForXPath(
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
export async function createAccessPlan( { postId = null, price = 0.00, title = 'Test Plan' } ) {
postId = postId || await createCourse();
await visitAdminPage( 'post.php', `post=${ postId }&action=edit` );
await click( '#llms-new-access-plan' );
await page.waitFor( 500 );
const selector = '#llms-access-plans .llms-access-plan';
await fillField( `${ selector }:last-child input.llms-plan-title`, title );
if ( price > 0 ) {
await fillField( `${ selector }:last-child input.llms-plan-price`, price );
} else {
await click( `${ selector }:last-child input[type="checkbox"][data-controller-id="llms-plan-is-free"]` );
}
await clickAndWait( '#llms-save-access-plans' );
export async function createCoupon( { code = null, discount = '10%' } ) {
code = code || Math.random().toString( 36 ).slice( 2 );
await visitAdminPage( 'post-new.php', `post_type=llms_coupon&post_title=${ code }` );
await page.select( '#_llms_discount_type', discount.includes( '%' ) ? 'percent' : 'dollar' );
await fillField( '#_llms_coupon_amount', discount.replace( '%', '' ).replace( '$', '' ) );
await clickAndWait( '#publish' );
return code;
}
export async function createUser( opts ) {
await visitAdminPage( 'user-new.php' );
const login = `mock_${ Math.random().toString( 36 ).slice( 2 ) }`;
opts = Object.assign( {
user_login: login,
email: `${login}@mock.tld`,
role: 'student',
password: `${ Math.random().toString( 36 ).slice( 2 ) }${ Math.random().toString( 36 ).slice( 2 ) }`
}, opts );
await forEach( opts, async ( key, val ) => {
if ( 'role' === key ) {
await page.select( '#role', val );
} else if ( 'password' === key ) {
export async function deactivateExperience( experience ) {
await visitAdminPage( 'admin.php', 'page=amp-options' );
const selector = `#${ experience }_experience`;
const isChecked = await page.$eval( selector, ( el ) => el.matches( `:checked` ) );
if ( ! isChecked ) {
return;
}
await page.click( selector );
await Promise.all( [
page.click( '#submit' ),
page.waitForNavigation(),
] );
}
export async function goToOnboardingWizard() {
await visitAdminPage( 'index.php' );
await expect( page ).not.toMatchElement( '#amp-onboarding-wizard' );
await visitAdminPage( 'admin.php', 'page=amp-onboarding-wizard' );
await expect( page ).toMatchElement( '#amp-onboarding-wizard' );
}
export async function visitSettingsPage( { tab = null, section = null } = {} ) {
await visitAdminPage( 'admin.php', new URLSearchParams( { page: 'llms-settings', tab, section } ).toString() );
}