import {test} from '@jest/globals';
import {__runLogin} from './login.test';
import {jestState} from '../form.spec';

export async function __settingsSetDirExclusion() {
    await jestState.page.goto(
        jestState.envData.root + '/wp-admin/options-general.php?page=spbc&spbc_tab=settings_general',
        {waitUntil: 'load'},
    );

    let field = '#spbc_setting_scanner__dir_exclusions_view';
    await jestState.page.waitForSelector(field);
    await jestState.page.$eval( field, (element) => element.value = '');
    await jestState.page.click(field);
    await jestState.page.type(field, 'wp-content\nwp-admin\nwp-includes');

    await jestState.page.click('#spbc_settings_form [name="submit"]');
}

/**
 * Run tests.
 * This test is a wrapper for group of tests.
 * @param {boolean} doLogin
 * @return {void}
 */
export function groupSettingsSetDirExclusion(doLogin = true) {
    if (doLogin) {
        test('LOGIN', async () => {
            await __runLogin();
        }, jestState.globals.globalTimeout);
    }

    test('SETTINGS SET DIR EXCLUSION', async () => {
        await __settingsSetDirExclusion();
    }, jestState.globals.globalTimeout);
}
