{"size": 2804, "ext": "js", "max_stars_repo_path": "packages/core/test/ElSpec.js", "max_stars_repo_name": "kraut-dps/zasada", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/core/test/ElSpec.js", "max_issues_repo_name": "kraut-dps/zasada", "max_issues_repo_issues_event_min_datetime": "2021-01-08T15:18:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-08T15:18:59.000Z", "max_forks_repo_path": "packages/core/test/ElSpec.js", "max_forks_repo_name": "kraut-dps/zasada", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 24.5964912281, "max_line_length": 86, "alphanum_fraction": 0.5759629101}
import oRoot, {Widget} from "./_support/bootstrap.js";

class WidgetTest extends Widget {
}

let oEl, oHelper;
describe( "El", () => {

	beforeAll( ( fnDone ) => {
		oRoot.core.init( ( oLinker ) => {
			oLinker.setWidgets( { WidgetTest } );
			oHelper = oRoot.test.oneHelper();
			oEl = oRoot.core.oneEl();
			fnDone();
		} );
	} );

	it( "find", async ( fnDone ) => {

		await oHelper.addHtmlAll(
			`<div class="widget _ _WidgetTest _WidgetTest-Bar">
				<div class="_WidgetTest-Foo"></div>
				<div class="_WidgetTest-Foo"></div>
			</div>`
		);

		const oWidget = oHelper.widget( '.widget', WidgetTest );

		const aFoos = oEl.find( oWidget, 'Foo[]' );

		// просто в качестве аргумента не строка а объект
		expect( oEl.find( oWidget, oEl.parse( 'Foo[]' ) ) ).toEqual( aFoos );

		const oElQuery = oRoot.core.newElQuery();
		oElQuery.id( 'Foo' );
		oElQuery.onlyFirst( false );

		// тоже самое, по другому собран объект запроса
		expect( oEl.find( oWidget, oElQuery ) ).toEqual( aFoos );

		// провека на то что в кеше сохранилось
		expect( oEl._findInCache( oWidget, oEl.parse( 'Foo' ) ) ).toEqual( [ aFoos[ 0 ] ] );

		oEl.resetCache( oWidget );
		expect( oEl._findInCache( oWidget, oEl.parse( 'Foo' ) ) ).toEqual( false );

		// теперь с выключенным кешом
		oEl.find( oWidget, '=Bar' );
		expect( oEl._findInCache( oWidget, oEl.parse( 'Bar' ) ) ).toEqual( false );

		// обязательный элемент
		try{
			oEl.find( oWidget, 'NotFound' );
			fail();
		} catch( e ) {}

		try{
			oEl.find( oWidget, 'NotFound?' );
		} catch( e ) {
			fail();
		}

		// проверка withFrom
		expect( oEl.find( oWidget, 'Bar[]' ).length ).toEqual( 1 );
		expect( oEl.find( oWidget, '>Bar[]?' ).length ).toEqual( 0 );

		try{
			oEl.find( oWidget, '[]' );
			fail();
		} catch( e ) {}

		fnDone();
	} );

	describe( ".parse()", () => {

		it( "only blockId", () => {
			let { sId, bOnlyFirst, bCanEmpty } = oEl.parse( 'BlockId' );
			expect( sId ).toBe( 'BlockId' );
			expect( bOnlyFirst ).toBe( true );
			expect( bCanEmpty ).toBe( false );
		} );

		it( "all", () => {
			let { sId, bOnlyFirst, bCanEmpty } = oEl.parse( 'BlockId[]' );
			expect( sId ).toBe( 'BlockId' );
			expect( bOnlyFirst ).toBe( false );
			expect( bCanEmpty ).toBe( false );
		} );
		
		it( "canEmpty", () => {
			let { sId, bOnlyFirst, bCanEmpty } = oEl.parse( 'BlockId?' );
			expect( sId ).toBe( 'BlockId' );
			expect( bOnlyFirst ).toBe( true );
			expect( bCanEmpty ).toBe( true );
		} );

		it( "canEmptyAll", () => {
			let { sId, bOnlyFirst, bCanEmpty } = oEl.parse( 'BlockId[]?' );
			expect( sId ).toBe( 'BlockId' );
			expect( bOnlyFirst ).toBe( false );
			expect( bCanEmpty ).toBe( true );
		} );
		
		it( "bad queue", ( done ) => {
			try{
				oEl.parse( '%BlockId]' );
				fail();
			} catch( e ) {
				done();
			}
		} );
	} );
} );