From 9ad8cb96b851b4d2d8a6f40c2f39353cb93a93d0 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 16 Apr 2018 15:30:19 -0400 Subject: [PATCH] Cmatch: Do not fail given __classes question * src/client/Cmatch.js (handleClassMatch): Rename from _handleClassMatch. Make protected. Check for truthy `vis'. * test/client/CmatchTest.js: Update accordingly. --- src/client/Cmatch.js | 12 +++++++--- test/client/CmatchTest.js | 47 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/client/Cmatch.js b/src/client/Cmatch.js index 4705e0c..2dc316c 100644 --- a/src/client/Cmatch.js +++ b/src/client/Cmatch.js @@ -150,7 +150,7 @@ module.exports = Class( 'Cmatch', return; } - _self._handleClassMatch( cmatch ); + _self.handleClassMatch( cmatch ); cmatchprot = false; } ); } ); @@ -224,7 +224,7 @@ module.exports = Class( 'Cmatch', }, - 'private _handleClassMatch': function( cmatch, force ) + 'virtual protected handleClassMatch': function( cmatch, force ) { force = !!force; @@ -268,6 +268,12 @@ module.exports = Class( 'Cmatch', || [] ); + // this should really only ever be the case for __classes + if ( !vis ) + { + continue; + } + // TODO: Figure out something better here. This is currently // needed for hiding statics---they are registered as exclusive // fields (`fields', above), but aren't actually fields (they're @@ -494,7 +500,7 @@ module.exports = Class( 'Cmatch', return this; } - this._handleClassMatch( this._cmatch, true ); + this.handleClassMatch( this._cmatch, true ); return this; }, diff --git a/test/client/CmatchTest.js b/test/client/CmatchTest.js index cfbfb14..10fdd39 100644 --- a/test/client/CmatchTest.js +++ b/test/client/CmatchTest.js @@ -25,13 +25,22 @@ const { expect } = require( 'chai' ); const Sut = require( '../../src/client/Cmatch' ) .extend( { - 'override constructor'( _, __, ___ ) {}, + 'override constructor'( class_matcher, program, client ) + { + this.__super( class_matcher || {}, program || {}, client || {} ); + }, // make public 'override public markShowHide'( field, visq, show, hide ) { return this.__super( field, visq, show, hide ); - } + }, + + // make public + 'override public handleClassMatch'( cmatch, force ) + { + this.__super( cmatch, force ); + }, } ); @@ -84,4 +93,38 @@ describe( "Cmatch", () => expect( visq.bar ).to.equal( barval ); } ); + + + /** + * __classes is always returned (at least at the time of writing) by + * TAME. here was a bug when it was recognized as a field (e.g. marked + * as an `external' in program.xml), + */ + it( "does not fail when __classes is a known field", () => + { + const cmatch = { + // populated by TAME, always + __classes: {}, + }; + + const field_names = { + __classes: true, + }; + + const mock_client = { + getUi: () => ( { + setCmatch() {}, + getCurrentStep: () => ( { + getStep: () => ( { + getExclusiveFieldNames: () => field_names, + } ) + } ) + } ), + getQuote: () => ( {} ), + }; + + Sut( {}, {}, mock_client ).handleClassMatch( + cmatch, false + ); + } ); } );