How to use properties method in ng-mocks

Best JavaScript code snippet using ng-mocks

tablepropertiesui.js

Source:tablepropertiesui.js Github

copy

Full Screen

1/**2 * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license4 */5/* globals document, Event */6import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';7import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';8import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';9import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';10import Undo from '@ckeditor/ckeditor5-undo/src/undo';11import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';12import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';13import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';14import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';15import Table from '../../src/table';16import TablePropertiesEditing from '../../src/tableproperties/tablepropertiesediting';17import TablePropertiesUI from '../../src/tableproperties/tablepropertiesui';18import TablePropertiesUIView from '../../src/tableproperties/ui/tablepropertiesview';19import { defaultColors } from '../../src/utils/ui/table-properties';20describe( 'table properties', () => {21 describe( 'TablePropertiesUI', () => {22 let editor, editorElement, contextualBalloon,23 tablePropertiesUI, tablePropertiesView, tablePropertiesButton,24 clock;25 testUtils.createSinonSandbox();26 beforeEach( () => {27 clock = sinon.useFakeTimers();28 editorElement = document.createElement( 'div' );29 document.body.appendChild( editorElement );30 return ClassicTestEditor31 .create( editorElement, {32 plugins: [ Table, TablePropertiesEditing, TablePropertiesUI, Paragraph, Undo ],33 initialData: '<table><tr><td>foo</td></tr></table><p>bar</p>'34 } )35 .then( newEditor => {36 editor = newEditor;37 tablePropertiesUI = editor.plugins.get( TablePropertiesUI );38 tablePropertiesButton = editor.ui.componentFactory.create( 'tableProperties' );39 contextualBalloon = editor.plugins.get( ContextualBalloon );40 tablePropertiesView = tablePropertiesUI.view;41 // There is no point to execute BalloonPanelView attachTo and pin methods so lets override it.42 testUtils.sinon.stub( contextualBalloon.view, 'attachTo' ).returns( {} );43 testUtils.sinon.stub( contextualBalloon.view, 'pin' ).returns( {} );44 } );45 } );46 afterEach( () => {47 clock.restore();48 editorElement.remove();49 return editor.destroy();50 } );51 it( 'should be named', () => {52 expect( TablePropertiesUI.pluginName ).to.equal( 'TablePropertiesUI' );53 } );54 it( 'should load ContextualBalloon', () => {55 expect( editor.plugins.get( ContextualBalloon ) ).to.be.instanceOf( ContextualBalloon );56 } );57 describe( 'constructor()', () => {58 it( 'should define table.tableProperties config', () => {59 expect( editor.config.get( 'table.tableProperties' ) ).to.deep.equal( {60 borderColors: defaultColors,61 backgroundColors: defaultColors62 } );63 } );64 } );65 describe( 'init()', () => {66 it( 'should set a batch', () => {67 expect( tablePropertiesUI._undoStepBatch ).to.be.null;68 } );69 describe( '#view', () => {70 it( 'should be created', () => {71 expect( tablePropertiesUI.view ).to.be.instanceOf( TablePropertiesUIView );72 } );73 it( 'should be rendered', () => {74 expect( tablePropertiesUI.view.isRendered ).to.be.true;75 } );76 it( 'should get the border colors configurations', () => {77 expect( tablePropertiesView.options.borderColors ).to.have.length( 15 );78 } );79 it( 'should get the background colors configurations', () => {80 expect( tablePropertiesView.options.backgroundColors ).to.have.length( 15 );81 } );82 } );83 describe( 'toolbar button', () => {84 it( 'should be registered', () => {85 expect( tablePropertiesButton ).to.be.instanceOf( ButtonView );86 } );87 it( 'should have a label', () => {88 expect( tablePropertiesButton.label ).to.equal( 'Table properties' );89 } );90 it( 'should have a tooltip', () => {91 expect( tablePropertiesButton.tooltip ).to.be.true;92 } );93 it( 'should call #_showView upon #execute', () => {94 const spy = testUtils.sinon.stub( tablePropertiesUI, '_showView' ).returns( {} );95 tablePropertiesButton.fire( 'execute' );96 sinon.assert.calledOnce( spy );97 } );98 it( 'should be disabled if all of the table properties commands are disabled', () => {99 [100 'tableBorderStyle',101 'tableBorderColor',102 'tableBorderWidth',103 'tableBackgroundColor',104 'tableWidth',105 'tableHeight',106 'tableAlignment'107 ].forEach( command => {108 editor.commands.get( command ).isEnabled = false;109 } );110 expect( tablePropertiesButton.isEnabled ).to.be.false;111 editor.commands.get( 'tableBackgroundColor' ).isEnabled = true;112 expect( tablePropertiesButton.isEnabled ).to.be.true;113 } );114 } );115 } );116 describe( 'destroy()', () => {117 it( 'should destroy the #view', () => {118 const spy = sinon.spy( tablePropertiesView, 'destroy' );119 tablePropertiesUI.destroy();120 sinon.assert.calledOnce( spy );121 } );122 } );123 describe( 'Properties #view', () => {124 beforeEach( () => {125 editor.model.change( writer => {126 writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );127 } );128 } );129 it( 'should hide on #submit', () => {130 tablePropertiesButton.fire( 'execute' );131 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );132 tablePropertiesView.fire( 'submit' );133 expect( contextualBalloon.visibleView ).to.be.null;134 } );135 describe( '#cancel event', () => {136 // https://github.com/ckeditor/ckeditor5/issues/6180137 it( 'should not undo if it there were no changes made to the property fields', () => {138 const spy = sinon.spy( editor, 'execute' );139 // Show the view. New batch will be created.140 tablePropertiesButton.fire( 'execute' );141 // Cancel the view immediately.142 tablePropertiesView.fire( 'cancel' );143 sinon.assert.notCalled( spy );144 } );145 it( 'should undo the entire batch of changes if there were some', () => {146 const spy = sinon.spy( editor, 'execute' );147 // Show the view. New batch will be created.148 tablePropertiesButton.fire( 'execute' );149 // Do the changes like a user.150 tablePropertiesView.borderStyle = 'dotted';151 tablePropertiesView.backgroundColor = 'red';152 expect( getModelData( editor.model ) ).to.equal(153 '<table backgroundColor="red" borderStyle="dotted">' +154 '<tableRow>' +155 '<tableCell>' +156 '<paragraph>[]foo</paragraph>' +157 '</tableCell>' +158 '</tableRow>' +159 '</table>' +160 '<paragraph>bar</paragraph>'161 );162 tablePropertiesView.fire( 'cancel' );163 expect( getModelData( editor.model ) ).to.equal(164 '<table>' +165 '<tableRow>' +166 '<tableCell>' +167 '<paragraph>[]foo</paragraph>' +168 '</tableCell>' +169 '</tableRow>' +170 '</table>' +171 '<paragraph>bar</paragraph>'172 );173 sinon.assert.calledWith( spy, 'undo', tablePropertiesUI._undoStepBatch );174 } );175 it( 'should hide the view', () => {176 tablePropertiesButton.fire( 'execute' );177 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );178 tablePropertiesView.fire( 'cancel' );179 expect( contextualBalloon.visibleView ).to.be.null;180 } );181 } );182 it( 'should hide on the Esc key press', () => {183 const keyEvtData = {184 keyCode: keyCodes.esc,185 preventDefault: sinon.spy(),186 stopPropagation: sinon.spy()187 };188 tablePropertiesButton.fire( 'execute' );189 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );190 tablePropertiesView.keystrokes.press( keyEvtData );191 expect( contextualBalloon.visibleView ).to.be.null;192 } );193 it( 'should hide if the table is no longer selected on EditorUI#update', () => {194 tablePropertiesButton.fire( 'execute' );195 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );196 editor.model.change( writer => {197 // Set selection in the paragraph.198 writer.setSelection( editor.model.document.getRoot().getChild( 1 ), 0 );199 } );200 expect( contextualBalloon.visibleView ).to.be.null;201 } );202 it( 'should reposition if table is still selected on on EditorUI#update', () => {203 tablePropertiesButton.fire( 'execute' );204 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );205 editor.model.change( writer => {206 writer.insertText( 'qux', editor.model.document.selection.getFirstPosition() );207 } );208 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );209 } );210 it( 'should hide if clicked outside the balloon', () => {211 tablePropertiesButton.fire( 'execute' );212 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );213 document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );214 expect( contextualBalloon.visibleView ).to.be.null;215 } );216 describe( 'property changes', () => {217 beforeEach( () => {218 tablePropertiesUI._undoStepBatch = 'foo';219 } );220 describe( '#borderStyle', () => {221 it( 'should affect the editor state', () => {222 const spy = testUtils.sinon.stub( editor, 'execute' );223 tablePropertiesView.borderStyle = 'dotted';224 sinon.assert.calledOnce( spy );225 sinon.assert.calledWithExactly( spy, 'tableBorderStyle', { value: 'dotted', batch: 'foo' } );226 } );227 } );228 describe( '#borderColor', () => {229 it( 'should affect the editor state', () => {230 const spy = testUtils.sinon.stub( editor, 'execute' );231 tablePropertiesView.borderColor = '#FFAAFF';232 sinon.assert.calledOnce( spy );233 sinon.assert.calledWithExactly( spy, 'tableBorderColor', { value: '#FFAAFF', batch: 'foo' } );234 } );235 it( 'should display an error message if value is invalid', () => {236 const spy = testUtils.sinon.stub( editor, 'execute' );237 // First, let's pass an invalid value and check what happens.238 tablePropertiesView.borderColor = '42';239 clock.tick( 500 );240 expect( tablePropertiesView.borderColorInput.errorText ).to.match( /^The color is invalid/ );241 sinon.assert.notCalled( spy );242 // And now let's pass a valid value and check if the error text will be gone.243 tablePropertiesView.borderColor = '#AAA';244 clock.tick( 500 );245 expect( tablePropertiesView.borderColorInput.errorText ).to.be.null;246 sinon.assert.calledWithExactly( spy, 'tableBorderColor', { value: '#AAA', batch: 'foo' } );247 } );248 } );249 describe( '#borderWidth', () => {250 it( 'should affect the editor state', () => {251 const spy = testUtils.sinon.stub( editor, 'execute' );252 tablePropertiesView.borderWidth = '12px';253 sinon.assert.calledOnce( spy );254 sinon.assert.calledWithExactly( spy, 'tableBorderWidth', { value: '12px', batch: 'foo' } );255 } );256 it( 'should display an error message if value is invalid', () => {257 const spy = testUtils.sinon.stub( editor, 'execute' );258 // First, let's pass an invalid value and check what happens.259 tablePropertiesView.borderWidth = 'wrong';260 clock.tick( 500 );261 expect( tablePropertiesView.borderWidthInput.errorText ).to.match( /^The value is invalid/ );262 sinon.assert.notCalled( spy );263 // And now let's pass a valid value and check if the error text will be gone.264 tablePropertiesView.borderWidth = '3em';265 clock.tick( 500 );266 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;267 sinon.assert.calledWithExactly( spy, 'tableBorderWidth', { value: '3em', batch: 'foo' } );268 } );269 } );270 describe( '#backgroundColor', () => {271 it( 'should affect the editor state', () => {272 const spy = testUtils.sinon.stub( editor, 'execute' );273 tablePropertiesView.backgroundColor = '#FFAAFF';274 sinon.assert.calledOnce( spy );275 sinon.assert.calledWithExactly( spy, 'tableBackgroundColor', { value: '#FFAAFF', batch: 'foo' } );276 } );277 it( 'should display an error message if value is invalid', () => {278 const spy = testUtils.sinon.stub( editor, 'execute' );279 // First, let's pass an invalid value and check what happens.280 tablePropertiesView.backgroundColor = '42';281 clock.tick( 500 );282 expect( tablePropertiesView.backgroundInput.errorText ).to.match( /^The color is invalid/ );283 sinon.assert.notCalled( spy );284 // And now let's pass a valid value and check if the error text will be gone.285 tablePropertiesView.backgroundColor = '#AAA';286 clock.tick( 500 );287 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;288 sinon.assert.calledWithExactly( spy, 'tableBackgroundColor', { value: '#AAA', batch: 'foo' } );289 } );290 } );291 describe( '#width', () => {292 it( 'should affect the editor state', () => {293 const spy = testUtils.sinon.stub( editor, 'execute' );294 tablePropertiesView.width = '12px';295 sinon.assert.calledOnce( spy );296 sinon.assert.calledWithExactly( spy, 'tableWidth', { value: '12px', batch: 'foo' } );297 } );298 it( 'should display an error message if value is invalid', () => {299 const spy = testUtils.sinon.stub( editor, 'execute' );300 // First, let's pass an invalid value and check what happens.301 tablePropertiesView.width = 'wrong';302 clock.tick( 500 );303 expect( tablePropertiesView.widthInput.errorText ).to.match( /^The value is invalid/ );304 sinon.assert.notCalled( spy );305 // And now let's pass a valid value and check if the error text will be gone.306 tablePropertiesView.width = '3em';307 clock.tick( 500 );308 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;309 sinon.assert.calledWithExactly( spy, 'tableWidth', { value: '3em', batch: 'foo' } );310 } );311 } );312 describe( '#height', () => {313 it( 'should affect the editor state', () => {314 const spy = testUtils.sinon.stub( editor, 'execute' );315 tablePropertiesView.height = '12px';316 sinon.assert.calledOnce( spy );317 sinon.assert.calledWithExactly( spy, 'tableHeight', { value: '12px', batch: 'foo' } );318 } );319 it( 'should display an error message if value is invalid', () => {320 const spy = testUtils.sinon.stub( editor, 'execute' );321 // First, let's pass an invalid value and check what happens.322 tablePropertiesView.height = 'wrong';323 clock.tick( 500 );324 expect( tablePropertiesView.heightInput.errorText ).to.match( /^The value is invalid/ );325 sinon.assert.notCalled( spy );326 // And now let's pass a valid value and check if the error text will be gone.327 tablePropertiesView.height = '3em';328 clock.tick( 500 );329 expect( tablePropertiesView.backgroundInput.errorText ).to.be.null;330 sinon.assert.calledWithExactly( spy, 'tableHeight', { value: '3em', batch: 'foo' } );331 } );332 } );333 describe( '#alignment', () => {334 it( 'should affect the editor state', () => {335 const spy = testUtils.sinon.stub( editor, 'execute' );336 tablePropertiesView.alignment = 'right';337 sinon.assert.calledOnce( spy );338 sinon.assert.calledWithExactly( spy, 'tableAlignment', { value: 'right', batch: 'foo' } );339 } );340 } );341 it( 'should not display an error text if user managed to fix the value before the UI timeout', () => {342 // First, let's pass an invalid value.343 tablePropertiesView.borderColor = '#';344 clock.tick( 100 );345 // Then the user managed to quickly type the correct value.346 tablePropertiesView.borderColor = '#aaa';347 clock.tick( 400 );348 // Because they were quick, they should see no error349 expect( tablePropertiesView.borderColorInput.errorText ).to.be.null;350 } );351 it( 'should not affect the editor state if internal property has changed', () => {352 const spy = testUtils.sinon.stub( editor, 'execute' );353 tablePropertiesView.set( 'internalProp', 'foo' );354 tablePropertiesView.internalProp = 'bar';355 sinon.assert.notCalled( spy );356 } );357 } );358 } );359 describe( 'Showing the #view', () => {360 beforeEach( () => {361 editor.model.change( writer => {362 writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );363 } );364 } );365 it( 'should create a new undoable batch for further #view cancel', () => {366 tablePropertiesButton.fire( 'execute' );367 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );368 const firstBatch = tablePropertiesUI._undoStepBatch;369 expect( firstBatch ).to.be.instanceOf( Batch );370 tablePropertiesView.fire( 'submit' );371 expect( contextualBalloon.visibleView ).to.be.null;372 tablePropertiesButton.fire( 'execute' );373 const secondBatch = tablePropertiesUI._undoStepBatch;374 expect( secondBatch ).to.be.instanceOf( Batch );375 expect( firstBatch ).to.not.equal( secondBatch );376 } );377 describe( 'initial data', () => {378 it( 'should be set from the command values', () => {379 editor.commands.get( 'tableBorderStyle' ).value = 'a';380 editor.commands.get( 'tableBorderColor' ).value = 'b';381 editor.commands.get( 'tableBorderWidth' ).value = 'c';382 editor.commands.get( 'tableBackgroundColor' ).value = 'd';383 editor.commands.get( 'tableWidth' ).value = 'e';384 editor.commands.get( 'tableHeight' ).value = 'f';385 editor.commands.get( 'tableAlignment' ).value = 'g';386 tablePropertiesButton.fire( 'execute' );387 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );388 expect( tablePropertiesView ).to.include( {389 borderStyle: 'a',390 borderColor: 'b',391 borderWidth: 'c',392 backgroundColor: 'd',393 width: 'e',394 height: 'f',395 alignment: 'g'396 } );397 } );398 it( 'should use default values when command has no value', () => {399 editor.commands.get( 'tableBorderStyle' ).value = null;400 editor.commands.get( 'tableBorderColor' ).value = null;401 editor.commands.get( 'tableBorderWidth' ).value = null;402 editor.commands.get( 'tableBackgroundColor' ).value = null;403 editor.commands.get( 'tableWidth' ).value = null;404 editor.commands.get( 'tableHeight' ).value = null;405 editor.commands.get( 'tableAlignment' ).value = null;406 tablePropertiesButton.fire( 'execute' );407 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );408 expect( tablePropertiesView ).to.include( {409 borderStyle: '',410 borderColor: '',411 borderWidth: '',412 backgroundColor: '',413 width: '',414 height: '',415 alignment: ''416 } );417 } );418 } );419 it( 'should focus the form view', () => {420 const spy = testUtils.sinon.spy( tablePropertiesView, 'focus' );421 tablePropertiesButton.fire( 'execute' );422 sinon.assert.calledOnce( spy );423 } );424 } );425 describe( 'Hiding the #view', () => {426 beforeEach( () => {427 editor.model.change( writer => {428 writer.setSelection( editor.model.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 0 ), 0 );429 } );430 } );431 it( 'should stop listening to EditorUI#update', () => {432 const spy = testUtils.sinon.spy( tablePropertiesUI, 'stopListening' );433 tablePropertiesButton.fire( 'execute' );434 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );435 tablePropertiesView.fire( 'submit' );436 expect( contextualBalloon.visibleView ).to.be.null;437 sinon.assert.calledOnce( spy );438 sinon.assert.calledWithExactly( spy, editor.ui, 'update' );439 } );440 it( 'should focus the editing view so the focus is not lost', () => {441 const spy = testUtils.sinon.spy( editor.editing.view, 'focus' );442 tablePropertiesButton.fire( 'execute' );443 expect( contextualBalloon.visibleView ).to.equal( tablePropertiesView );444 tablePropertiesView.fire( 'submit' );445 sinon.assert.calledOnce( spy );446 } );447 } );448 } );...

Full Screen

Full Screen

additional_properties.js

Source:additional_properties.js Github

copy

Full Screen

1// @tags: [requires_non_retryable_commands]2/**3 * Tests for the JSON Schema 'additionalProperties' keyword.4 */5(function() {6 "use strict";7 load("jstests/libs/assert_schema_match.js");8 const coll = db.schema_allowed_properties;9 // Tests for {additionalProperties:false} at the top level.10 assertSchemaMatch(11 coll, {properties: {_id: {}, a: {}}, additionalProperties: false}, {_id: 1}, true);12 assertSchemaMatch(13 coll, {properties: {_id: {}, a: {}}, additionalProperties: false}, {_id: 1, a: 1}, true);14 assertSchemaMatch(15 coll, {properties: {_id: {}, a: {}}, additionalProperties: false}, {_id: 1, b: 1}, false);16 assertSchemaMatch(coll,17 {properties: {_id: {}, a: {}}, additionalProperties: false},18 {_id: 1, a: 1, b: 1},19 false);20 // Tests for {additionalProperties:true} at the top level.21 assertSchemaMatch(22 coll, {properties: {_id: {}, a: {}}, additionalProperties: true}, {_id: 1}, true);23 assertSchemaMatch(24 coll, {properties: {_id: {}, a: {}}, additionalProperties: true}, {_id: 1, a: 1}, true);25 assertSchemaMatch(26 coll, {properties: {_id: {}, a: {}}, additionalProperties: true}, {_id: 1, b: 1}, true);27 assertSchemaMatch(coll,28 {properties: {_id: {}, a: {}}, additionalProperties: true},29 {_id: 1, a: 1, b: 1},30 true);31 // Tests for additionalProperties with a nested schema at the top level.32 assertSchemaMatch(coll,33 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},34 {_id: 1},35 true);36 assertSchemaMatch(coll,37 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},38 {_id: 1, a: 1},39 true);40 assertSchemaMatch(coll,41 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},42 {_id: 1, b: 1},43 true);44 assertSchemaMatch(coll,45 {properties: {_id: {}, a: {}}, additionalProperties: {type: "number"}},46 {_id: 1, b: "str"},47 false);48 // Tests for additionalProperties together with patternProperties at the top level.49 assertSchemaMatch(coll,50 {51 properties: {_id: {}, a: {}},52 patternProperties: {"^b": {type: "string"}},53 additionalProperties: {type: "number"}54 },55 {_id: 1},56 true);57 assertSchemaMatch(coll,58 {59 properties: {_id: {}, a: {}},60 patternProperties: {"^b": {type: "string"}},61 additionalProperties: {type: "number"}62 },63 {_id: 1, a: 1},64 true);65 assertSchemaMatch(coll,66 {67 properties: {_id: {}, a: {}},68 patternProperties: {"^b": {type: "string"}},69 additionalProperties: {type: "number"}70 },71 {_id: 1, a: 1, ba: "str"},72 true);73 assertSchemaMatch(coll,74 {75 properties: {_id: {}, a: {}},76 patternProperties: {"^b": {type: "string"}},77 additionalProperties: {type: "number"}78 },79 {_id: 1, a: 1, ba: "str", other: 1},80 true);81 assertSchemaMatch(coll,82 {83 properties: {_id: {}, a: {}},84 patternProperties: {"^b": {type: "string"}},85 additionalProperties: {type: "number"}86 },87 {_id: 1, a: 1, ba: "str", other: "str"},88 false);89 assertSchemaMatch(coll,90 {91 properties: {_id: {}, a: {}},92 patternProperties: {"^b": {type: "string"}},93 additionalProperties: {type: "number"}94 },95 {_id: 1, a: 1, ba: 1, other: 1},96 false);97 assertSchemaMatch(coll,98 {99 properties: {_id: {}, a: {}},100 patternProperties: {"^b": {type: "string"}},101 additionalProperties: false102 },103 {_id: 1, a: 1, ba: "str"},104 true);105 assertSchemaMatch(coll,106 {107 properties: {_id: {}, a: {}},108 patternProperties: {"^b": {type: "string"}},109 additionalProperties: false110 },111 {_id: 1, a: 1, ba: "str", other: 1},112 false);113 // Tests for {additionalProperties:false} in a nested schema.114 assertSchemaMatch(115 coll, {properties: {obj: {properties: {a: {}}, additionalProperties: false}}}, {}, true);116 assertSchemaMatch(coll,117 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},118 {obj: 1},119 true);120 assertSchemaMatch(coll,121 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},122 {obj: {}},123 true);124 assertSchemaMatch(coll,125 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},126 {obj: {a: 1}},127 true);128 assertSchemaMatch(coll,129 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},130 {obj: {a: 1, b: 1}},131 false);132 assertSchemaMatch(coll,133 {properties: {obj: {properties: {a: {}}, additionalProperties: false}}},134 {obj: {b: 1}},135 false);136 // Tests for {additionalProperties:true} in a nested schema.137 assertSchemaMatch(coll,138 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},139 {obj: {}},140 true);141 assertSchemaMatch(coll,142 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},143 {obj: {a: 1}},144 true);145 assertSchemaMatch(coll,146 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},147 {obj: {a: 1, b: 1}},148 true);149 assertSchemaMatch(coll,150 {properties: {obj: {properties: {a: {}}, additionalProperties: true}}},151 {obj: {b: 1}},152 true);153 // Tests for additionalProperties whose value is a nested schema, which is itself contained154 // within a nested schema.155 assertSchemaMatch(156 coll,157 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},158 {},159 true);160 assertSchemaMatch(161 coll,162 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},163 {obj: 1},164 true);165 assertSchemaMatch(166 coll,167 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},168 {obj: {}},169 true);170 assertSchemaMatch(171 coll,172 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},173 {obj: {a: 1}},174 true);175 assertSchemaMatch(176 coll,177 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},178 {obj: {a: 1, b: 1}},179 true);180 assertSchemaMatch(181 coll,182 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},183 {obj: {a: 1, b: "str"}},184 false);185 assertSchemaMatch(186 coll,187 {properties: {obj: {properties: {a: {}}, additionalProperties: {type: "number"}}}},188 {obj: {b: "str"}},189 false);190 // Tests for additionalProperties together with patternProperties, both inside a nested schema.191 assertSchemaMatch(coll,192 {193 properties: {194 obj: {195 properties: {a: {}},196 patternProperties: {"^b": {type: "string"}},197 additionalProperties: {type: "number"}198 }199 }200 },201 {obj: {}},202 true);203 assertSchemaMatch(coll,204 {205 properties: {206 obj: {207 properties: {a: {}},208 patternProperties: {"^b": {type: "string"}},209 additionalProperties: {type: "number"}210 }211 }212 },213 {obj: {a: 1, ba: "str", c: 1}},214 true);215 assertSchemaMatch(coll,216 {217 properties: {218 obj: {219 properties: {a: {}},220 patternProperties: {"^b": {type: "string"}},221 additionalProperties: {type: "number"}222 }223 }224 },225 {obj: {a: 1, ba: 1, c: 1}},226 false);227 assertSchemaMatch(coll,228 {229 properties: {230 obj: {231 properties: {a: {}},232 patternProperties: {"^b": {type: "string"}},233 additionalProperties: {type: "number"}234 }235 }236 },237 {obj: {a: 1, ba: 1, c: "str"}},238 false);...

Full Screen

Full Screen

ObjectMakr-0.2.2.js

Source:ObjectMakr-0.2.2.js Github

copy

Full Screen

1var ObjectMakr;2(function (ObjectMakr_1) {3 "use strict";4 /**5 * An factory for JavaScript classes that automates the process of6 * setting constructors' prototypal inheritance. A sketch of class inheritance7 * and a listing of properties for each class is taken in, and dynamically8 * accessible constructors keyed by String names are made available.9 */10 var ObjectMakr = (function () {11 /**12 * Initializes a new instance of the ObjectMakr class.13 *14 * @param settings Settings to be used for initialization.15 */16 function ObjectMakr(settings) {17 if (typeof settings === "undefined") {18 throw new Error("No settings object given to ObjectMakr.");19 }20 if (typeof settings.inheritance === "undefined") {21 throw new Error("No inheritance given to ObjectMakr.");22 }23 this.inheritance = settings.inheritance;24 this.properties = settings.properties || {};25 this.doPropertiesFull = settings.doPropertiesFull;26 this.indexMap = settings.indexMap;27 this.onMake = settings.onMake;28 this.functions = {};29 if (this.doPropertiesFull) {30 this.propertiesFull = {};31 }32 if (this.indexMap) {33 this.processProperties(this.properties);34 }35 this.processFunctions(this.inheritance, Object, "Object");36 }37 /* Simple gets38 */39 /**40 * @returns The complete inheritance mapping.41 */42 ObjectMakr.prototype.getInheritance = function () {43 return this.inheritance;44 };45 /**46 * @returns The complete properties mapping.47 */48 ObjectMakr.prototype.getProperties = function () {49 return this.properties;50 };51 /**52 * @returns The properties for a particular class.53 */54 ObjectMakr.prototype.getPropertiesOf = function (title) {55 return this.properties[title];56 };57 /**58 * @returns Full properties, if doPropertiesFull is true.59 */60 ObjectMakr.prototype.getFullProperties = function () {61 return this.propertiesFull;62 };63 /**64 * @returns Full properties for a particular class, if65 * doPropertiesFull is true.66 */67 ObjectMakr.prototype.getFullPropertiesOf = function (title) {68 return this.doPropertiesFull ? this.propertiesFull[title] : undefined;69 };70 /**71 * @returns The full mapping of class constructors.72 */73 ObjectMakr.prototype.getFunctions = function () {74 return this.functions;75 };76 /**77 * @param name The name of a class to retrieve.78 * @returns The constructor for the given class.79 */80 ObjectMakr.prototype.getFunction = function (name) {81 return this.functions[name];82 };83 /**84 * @param type The name of a class to check for.85 * @returns Whether that class exists.86 */87 ObjectMakr.prototype.hasFunction = function (name) {88 return this.functions.hasOwnProperty(name);89 };90 /**91 * @returns The optional mapping of indices.92 */93 ObjectMakr.prototype.getIndexMap = function () {94 return this.indexMap;95 };96 /* Core usage97 */98 /**99 * Creates a new instance of the specified type and returns it.100 * If desired, any settings are applied to it (deep copy using proliferate).101 *102 * @param name The name of the type to initialize a new instance of.103 * @param [settings] Additional attributes to add to the new instance.104 * @returns A newly created instance of the specified type.105 */106 ObjectMakr.prototype.make = function (name, settings) {107 var output;108 // Make sure the type actually exists in Functions109 if (!this.functions.hasOwnProperty(name)) {110 throw new Error("Unknown type given to ObjectMakr: " + name);111 }112 // Create the new object, copying any given settings113 output = new this.functions[name]();114 if (settings) {115 this.proliferate(output, settings);116 }117 // onMake triggers are handled respecting doPropertiesFull.118 if (this.onMake && output[this.onMake]) {119 output[this.onMake](output, name, settings, (this.doPropertiesFull ? this.propertiesFull : this.properties)[name]);120 }121 return output;122 };123 /* Core parsing124 */125 /**126 * Parser that calls processPropertyArray on all properties given as arrays127 *128 * @param properties Type properties for classes to create.129 * @remarks Only call this if indexMap is given as an array130 */131 ObjectMakr.prototype.processProperties = function (properties) {132 var name;133 // For each of the given properties:134 for (name in properties) {135 if (properties.hasOwnProperty(name)) {136 // If it's an Array, replace it with a mapped version137 if (properties[name] instanceof Array) {138 properties[name] = this.processPropertyArray(properties[name]);139 }140 }141 }142 };143 /**144 * Creates an output properties object with the mapping shown in indexMap145 *146 * @param properties An Array with indiced versions of properties147 * @example148 * this.indexMap = ["width", "height"];149 * this.processPropertyArray([7, 14]);150 * // { "width": 7, "height": 14 }151 */152 ObjectMakr.prototype.processPropertyArray = function (properties) {153 var output = {}, i;154 // For each [i] in properties, set that property as under indexMap[i]155 for (i = properties.length - 1; i >= 0; --i) {156 output[this.indexMap[i]] = properties[i];157 }158 return output;159 };160 /**161 * Recursive parser to generate each Function, starting from the base.162 *163 * @param base An object whose keys are the names of Functions to164 * made, and whose values are objects whose keys are165 * for children that inherit from these Functions166 * @param parent The parent class Function of the classes about to be made.167 * @param [parentName] The name of the parent class to be inherited from,168 * if it is a generated one (and not Object itself).169 */170 ObjectMakr.prototype.processFunctions = function (base, parent, parentName) {171 var name, ref;172 // For each name in the current object:173 for (name in base) {174 if (base.hasOwnProperty(name)) {175 this.functions[name] = (new Function());176 // This sets the Function as inheriting from the parent177 this.functions[name].prototype = new parent();178 this.functions[name].prototype.constructor = this.functions[name];179 // Add each property from properties to the Function prototype180 for (ref in this.properties[name]) {181 if (this.properties[name].hasOwnProperty(ref)) {182 this.functions[name].prototype[ref] = this.properties[name][ref];183 }184 }185 // If the entire property tree is being mapped, copy everything186 // from both this and its parent to its equivalent187 if (this.doPropertiesFull) {188 this.propertiesFull[name] = {};189 if (parentName) {190 for (ref in this.propertiesFull[parentName]) {191 if (this.propertiesFull[parentName].hasOwnProperty(ref)) {192 this.propertiesFull[name][ref] = this.propertiesFull[parentName][ref];193 }194 }195 }196 for (ref in this.properties[name]) {197 if (this.properties[name].hasOwnProperty(ref)) {198 this.propertiesFull[name][ref] = this.properties[name][ref];199 }200 }201 }202 this.processFunctions(base[name], this.functions[name], name);203 }204 }205 };206 /* Utilities207 */208 /**209 * Proliferates all members of the donor to the recipient recursively, as210 * a deep copy.211 *212 * @param recipient An object receiving the donor's members.213 * @param donor An object whose members are copied to recipient.214 * @param [noOverride] If recipient properties may be overriden (by default, false).215 */216 ObjectMakr.prototype.proliferate = function (recipient, donor, noOverride) {217 var setting, i;218 // For each attribute of the donor:219 for (i in donor) {220 // If noOverride is specified, don't override if it already exists221 if (noOverride && recipient.hasOwnProperty(i)) {222 continue;223 }224 // If it's an object, recurse on a new version of it225 setting = donor[i];226 if (typeof setting === "object") {227 if (!recipient.hasOwnProperty(i)) {228 recipient[i] = new setting.constructor();229 }230 this.proliferate(recipient[i], setting, noOverride);231 }232 else {233 // Regular primitives are easy to copy otherwise234 recipient[i] = setting;235 }236 }237 return recipient;238 };239 return ObjectMakr;240 })();241 ObjectMakr_1.ObjectMakr = ObjectMakr;...

Full Screen

Full Screen

AndroidProject.js

Source:AndroidProject.js Github

copy

Full Screen

1/**2 Licensed to the Apache Software Foundation (ASF) under one3 or more contributor license agreements. See the NOTICE file4 distributed with this work for additional information5 regarding copyright ownership. The ASF licenses this file6 to you under the Apache License, Version 2.0 (the7 "License"); you may not use this file except in compliance8 with the License. You may obtain a copy of the License at9 http://www.apache.org/licenses/LICENSE-2.010 Unless required by applicable law or agreed to in writing,11 software distributed under the License is distributed on an12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13 KIND, either express or implied. See the License for the14 specific language governing permissions and limitations15 under the License.16*/17var fs = require('fs');18var path = require('path');19var properties_parser = require('properties-parser');20var AndroidManifest = require('./AndroidManifest');21var projectFileCache = {};22function addToPropertyList(projectProperties, key, value) {23 var i = 1;24 while (projectProperties.get(key + '.' + i))25 i++;26 projectProperties.set(key + '.' + i, value);27 projectProperties.dirty = true;28}29function removeFromPropertyList(projectProperties, key, value) {30 var i = 1;31 var currentValue;32 while ((currentValue = projectProperties.get(key + '.' + i))) {33 if (currentValue === value) {34 while ((currentValue = projectProperties.get(key + '.' + (i + 1)))) {35 projectProperties.set(key + '.' + i, currentValue);36 i++;37 }38 projectProperties.set(key + '.' + i);39 break;40 }41 i++;42 }43 projectProperties.dirty = true;44}45function getRelativeLibraryPath (parentDir, subDir) {46 var libraryPath = path.relative(parentDir, subDir);47 return (path.sep == '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;48}49function AndroidProject(projectDir) {50 this._propertiesEditors = {};51 this._subProjectDirs = {};52 this._dirty = false;53 this.projectDir = projectDir;54 this.platformWww = path.join(this.projectDir, 'platform_www');55 this.www = path.join(this.projectDir, 'assets/www');56}57AndroidProject.getProjectFile = function (projectDir) {58 if (!projectFileCache[projectDir]) {59 projectFileCache[projectDir] = new AndroidProject(projectDir);60 }61 return projectFileCache[projectDir];62};63AndroidProject.purgeCache = function (projectDir) {64 if (projectDir) {65 delete projectFileCache[projectDir];66 } else {67 projectFileCache = {};68 }69};70/**71 * Reads the package name out of the Android Manifest file72 *73 * @param {String} projectDir The absolute path to the directory containing the project74 *75 * @return {String} The name of the package76 */77AndroidProject.prototype.getPackageName = function() {78 return new AndroidManifest(path.join(this.projectDir, 'AndroidManifest.xml')).getPackageId();79};80AndroidProject.prototype.getCustomSubprojectRelativeDir = function(plugin_id, src) {81 // All custom subprojects are prefixed with the last portion of the package id.82 // This is to avoid collisions when opening multiple projects in Eclipse that have subprojects with the same name.83 var packageName = this.getPackageName();84 var lastDotIndex = packageName.lastIndexOf('.');85 var prefix = packageName.substring(lastDotIndex + 1);86 var subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));87 return subRelativeDir;88};89AndroidProject.prototype.addSubProject = function(parentDir, subDir) {90 var parentProjectFile = path.resolve(parentDir, 'project.properties');91 var subProjectFile = path.resolve(subDir, 'project.properties');92 var parentProperties = this._getPropertiesFile(parentProjectFile);93 // TODO: Setting the target needs to happen only for pre-3.7.0 projects94 if (fs.existsSync(subProjectFile)) {95 var subProperties = this._getPropertiesFile(subProjectFile);96 subProperties.set('target', parentProperties.get('target'));97 subProperties.dirty = true;98 this._subProjectDirs[subDir] = true;99 }100 addToPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));101 this._dirty = true;102};103AndroidProject.prototype.removeSubProject = function(parentDir, subDir) {104 var parentProjectFile = path.resolve(parentDir, 'project.properties');105 var parentProperties = this._getPropertiesFile(parentProjectFile);106 removeFromPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));107 delete this._subProjectDirs[subDir];108 this._dirty = true;109};110AndroidProject.prototype.addGradleReference = function(parentDir, subDir) {111 var parentProjectFile = path.resolve(parentDir, 'project.properties');112 var parentProperties = this._getPropertiesFile(parentProjectFile);113 addToPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));114 this._dirty = true;115};116AndroidProject.prototype.removeGradleReference = function(parentDir, subDir) {117 var parentProjectFile = path.resolve(parentDir, 'project.properties');118 var parentProperties = this._getPropertiesFile(parentProjectFile);119 removeFromPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));120 this._dirty = true;121};122AndroidProject.prototype.addSystemLibrary = function(parentDir, value) {123 var parentProjectFile = path.resolve(parentDir, 'project.properties');124 var parentProperties = this._getPropertiesFile(parentProjectFile);125 addToPropertyList(parentProperties, 'cordova.system.library', value);126 this._dirty = true;127};128AndroidProject.prototype.removeSystemLibrary = function(parentDir, value) {129 var parentProjectFile = path.resolve(parentDir, 'project.properties');130 var parentProperties = this._getPropertiesFile(parentProjectFile);131 removeFromPropertyList(parentProperties, 'cordova.system.library', value);132 this._dirty = true;133};134AndroidProject.prototype.write = function() {135 if (!this._dirty) {136 return;137 }138 this._dirty = false;139 for (var filename in this._propertiesEditors) {140 var editor = this._propertiesEditors[filename];141 if (editor.dirty) {142 fs.writeFileSync(filename, editor.toString());143 editor.dirty = false;144 }145 }146};147AndroidProject.prototype._getPropertiesFile = function (filename) {148 if (!this._propertiesEditors[filename]) {149 if (fs.existsSync(filename)) {150 this._propertiesEditors[filename] = properties_parser.createEditor(filename);151 } else {152 this._propertiesEditors[filename] = properties_parser.createEditor();153 }154 }155 return this._propertiesEditors[filename];156};...

Full Screen

Full Screen

translation_properties.js

Source:translation_properties.js Github

copy

Full Screen

1// -*- mode: Javascript; js-indent-level: 4; -*-2// Copyright 2013 Massachusetts Institute of Technology. All rights reserved.3/**4 * @fileoverview Visual blocks editor for App Inventor5 * Methods to handle Internationalization for AI2 Blockseditor.6 *7 * @author mckinney@mit.edu (Andrew F. McKinney)8 */9'use strict';10goog.provide('Blockly.TranslationProperties');11Blockly.TranslationProperties.map = {};12Blockly.TranslationProperties.rwState = {13 READ_ONLY: 0,14 READ_WRITE: 1,15 WRITE_ONLY: 216}17Blockly.TranslationProperties.haveType = function (typeName) {18 return Blockly.TranslationProperties.map[typeName] != undefined;19}20Blockly.TranslationProperties.haveProperty = function (typeName, propertyName) {21 if (!Blockly.TranslationProperties.haveType(typeName)) {22 return false;23 }24 return Blockly.TranslationProperties.map[typeName][propertyName] != undefined;25}26Blockly.TranslationProperties.addProperty = function (typeName, propertyName, propertyValue, rw) {27 if (!Blockly.TranslationProperties.haveType(typeName)) {28 Blockly.TranslationProperties.map[typeName] = {};29 }30 if (!Blockly.TranslationProperties.haveProperty(typeName, propertyName)) {31 Blockly.TranslationProperties.map[typeName][propertyName] = [propertyValue, rw];32 }33}34/**35 * propertyList is an array list of property with format [propertyValue, propertyName, rw]36 */37Blockly.TranslationProperties.addProperties = function (typeName, propertyList) {38 for (var i = 0; i < propertyList.length; i++) {39 var propertyValue = propertyList[i][0];40 var propertyName = propertyList[i][1];41 var rw = propertyList[i][2];42 Blockly.TranslationProperties.addProperty(typeName, propertyName, propertyValue, rw);43 }44}45Blockly.TranslationProperties.updateProperty = function (typeName, propertyName, propertyValue) {46 if (Blockly.TranslationProperties.haveProperty(typeName, propertyName)) {47 var rw = Blockly.TranslationProperties.map[typeName][propertyName][1];48 Blockly.TranslationProperties.map[typeName][propertyName] = [propertyValue, rw];49 }50}51/**52 * propertyList is an array list of property with format [propertyValue, propertyName, rw]53 */54Blockly.TranslationProperties.updateProperties = function (typeName, propertyList) {55 for (var i = 0; i < propertyList.length; i++) {56 var propertyValue = propertyList[i][0];57 var propertyName = propertyList[i][1];58 Blockly.TranslationProperties.updateProperty(typeName, propertyName, propertyValue);59 }60}61Blockly.TranslationProperties.getProperty = function (typeName, propertyName) {62 if (!Blockly.TranslationProperties.haveProperty(typeName, propertyName)) {63 return [];64 }65 var propItem = [Blockly.TranslationProperties.map[typeName][propertyName][0], propertyName];66 return propItem;67}68/**69 * Return all properties (getter + setter methods)70 */71Blockly.TranslationProperties.getAllProperties = function (typeName) {72 if (!Blockly.TranslationProperties.haveType(typeName)) {73 return [];74 }75 var propList = [];76 for (var propertyName in Blockly.TranslationProperties.map[typeName]) {77 var propItem = Blockly.TranslationProperties.getProperty(typeName, propertyName);78 propList.push(propItem);79 }80 return propList;81}82/**83 * Return properties of setter method84 */85Blockly.TranslationProperties.getAllPropertiesSetter = function (typeName) {86 if (!Blockly.TranslationProperties.haveType(typeName)) {87 return [];88 }89 var propList = [];90 for (var propertyName in Blockly.TranslationProperties.map[typeName]) {91 var propValues = Blockly.TranslationProperties.map[typeName][propertyName];92 if (propValues[1] == Blockly.TranslationProperties.rwState.READ_WRITE ||93 propValues[1] == Blockly.TranslationProperties.rwState.WRITE_ONLY) {94 var propItem = [propValues[0], propertyName];95 propList.push(propItem);96 }97 }98 return propList;99}100/**101 * Return properties of getter method102 */103Blockly.TranslationProperties.getAllPropertiesGetter = function (typeName) {104 if (!Blockly.TranslationProperties.haveType(typeName)) {105 return [];106 }107 var propList = [];108 for (var propertyName in Blockly.TranslationProperties.map[typeName]) {109 var propValues = Blockly.TranslationProperties.map[typeName][propertyName];110 if (propValues[1] == Blockly.TranslationProperties.rwState.READ_WRITE ||111 propValues[1] == Blockly.TranslationProperties.rwState.READ_ONLY) {112 var propItem = [propValues[0], propertyName];113 propList.push(propItem);114 }115 }116 return propList;117}118/**119 * Update property map for a component of the given type120 * { "name": "COMPONENT-TYPE-NAME",121 * "blockProperties": [122 * { "key": "PROPERTY-NAME",123 * "value": "PROPERTY-VALUE",124 * "rw": "read-only"|"read-write"|"write-only"|"invisible"},*125 * ]126 * }127 */128Blockly.TranslationProperties.updateComponentMap = function (typeDescription) {129 var typeName = typeDescription.name;130 for (var i = 0, propType; propType = typeDescription.blockProperties[i]; i++) {131 Blockly.TranslationProperties.updateProperty(typeName, propType.key, propType.value);132 }133}134/**135 * Update property map136 *137 * typeJsonString has the following format (where upper-case strings are138 * non-terminals and lower-case strings are literals):139 * [140 * { "name": "COMPONENT-TYPE-NAME",141 * "blockProperties": [142 * { "key": "PROPERTY-NAME",143 * "value": "PROPERTY-VALUE",144 * "rw": "read-only"|"read-write"|"write-only"|"invisible"},*145 * ]146 * },+147 * ]148 */149Blockly.TranslationProperties.updateMap = function (jsonString) {150 var components = JSON.parse(jsonString);151 for (var i = 0, typeDescription; typeDescription = components[i]; i++) {152 Blockly.TranslationProperties.updateComponentMap(typeDescription);153 }...

Full Screen

Full Screen

json.test.js

Source:json.test.js Github

copy

Full Screen

1/* eslint-disable */2import GenerateSchema from '../../generate-schema';3var simple = require('./fixtures/simple');4var advanced = require('./fixtures/advanced');5describe('JSON', function () {6 describe('Schema Checks', function () {7 var schema;8 beforeEach(function () {9 schema = GenerateSchema(simple);10 });11 it('.$schema should not exist', function () {12 expect(schema).not.toHaveProperty('$schema');13 });14 it('.type should exist', function () {15 expect(schema).toHaveProperty('type');16 });17 });18 describe('Item Checks', function () {19 var schema;20 beforeEach(function () {21 schema = GenerateSchema(advanced);22 });23 it('.items should be an object', function () {24 expect(schema.items).toBeObject();25 });26 it('.items.required should be an array', function () {27 expect(schema.items.required).toBeArray();28 expect(schema.items.required).toStrictEqual([29 'id',30 'name',31 'price',32 'dimensions',33 'warehouseLocation',34 ]);35 });36 it('.items.properties.tags should be an object', function () {37 expect(schema.items.properties.tags).toBeObject();38 });39 it('.items.properties.id should be of type [integer]', function () {40 expect(schema.items.properties.id.type).toBe('integer');41 });42 it('.items.properties.price should be of type [number]', function () {43 expect(schema.items.properties.price.type).toBe('number');44 });45 it('.items.properties.dimensions.properties.length should be of type [integer, number]', function () {46 expect(47 schema.items.properties.dimensions.properties.length.type,48 ).toStrictEqual(['integer', 'number']);49 });50 });51 describe('Property Checks', function () {52 var schema;53 beforeEach(function () {54 schema = GenerateSchema(simple);55 });56 it('.properties should exist', function () {57 expect(schema).toHaveProperty('properties');58 });59 it('.properties should be an object', function () {60 expect(schema.properties).toBeObject();61 });62 it('.properties.id should be of type [integer]', function () {63 expect(schema.properties.id.type).toBe('integer');64 });65 it('.properties.slug should be of type [string]', function () {66 expect(schema.properties.slug.type).toBe('string');67 });68 it('.properties.admin should be of type [boolean]', function () {69 expect(schema.properties.admin.type).toBe('boolean');70 });71 it('.properties.avatar should be of type [null]', function () {72 expect(schema.properties.avatar.type).toBe('null');73 });74 it('.properties.date should be of type [string]', function () {75 expect(schema.properties.date.type).toBe('string');76 expect(schema.properties.date.format).toBe('date-time');77 });78 it('.properties.article should be of type [object]', function () {79 expect(schema.properties.article.type).toBe('object');80 });81 it('.properties.article.properties should be of type [object]', function () {82 expect(schema.properties.article.properties).toBeObject();83 });84 it('.properties.article.properties.title should be of type [string]', function () {85 expect(schema.properties.article.properties.title.type).toBe('string');86 });87 it('.properties.article.properties.description should be of type [string]', function () {88 expect(schema.properties.article.properties.description.type).toBe(89 'string',90 );91 });92 it('.properties.article.properties.body should be of type [string]', function () {93 expect(schema.properties.article.properties.body.type).toBe('string');94 });95 it('.properties.comments should be of type [array]', function () {96 expect(schema.properties.comments.type).toBe('array');97 });98 it('.properties.comments.items should be of type [object]', function () {99 expect(schema.properties.comments.items).toBeObject();100 });101 it('.properties.comments.items.properties.body should be of type [string, null]', function () {102 expect(schema.properties.comments.items.properties.body.type[0]).toBe(103 'string',104 );105 expect(schema.properties.comments.items.properties.body.type[1]).toBe(106 'null',107 );108 });109 });...

Full Screen

Full Screen

min_max_properties.js

Source:min_max_properties.js Github

copy

Full Screen

1// @tags: [requires_non_retryable_commands]2/**3 * Tests for the JSON Schema 'minProperties' and 'maxProperties' keywords.4 */5(function() {6 "use strict";7 load("jstests/libs/assert_schema_match.js");8 const coll = db.jstests_schema_min_max_properties;9 // Test that {minProperties: 0} matches any object.10 assertSchemaMatch(coll, {minProperties: 0}, {}, true);11 assertSchemaMatch(coll, {minProperties: 0}, {a: 1}, true);12 assertSchemaMatch(coll, {minProperties: 0}, {a: 1, b: 2}, true);13 // Test that {maxProperties: 0} matches nothing, since objects always must have the "_id" field14 // when inserted into a collection.15 assertSchemaMatch(coll, {maxProperties: 0}, {}, false);16 assertSchemaMatch(coll, {maxProperties: 0}, {a: 1}, false);17 assertSchemaMatch(coll, {maxProperties: 0}, {a: 1, b: 2}, false);18 // Test top-level minProperties greater than 0.19 assertSchemaMatch(coll, {minProperties: 2}, {_id: 0}, false);20 assertSchemaMatch(coll, {minProperties: 2}, {_id: 0, a: 1}, true);21 assertSchemaMatch(coll, {minProperties: 2}, {_id: 0, a: 1, b: 2}, true);22 // Test top-level maxProperties greater than 0.23 assertSchemaMatch(coll, {maxProperties: 2}, {_id: 0}, true);24 assertSchemaMatch(coll, {maxProperties: 2}, {_id: 0, a: 1}, true);25 assertSchemaMatch(coll, {maxProperties: 2}, {_id: 0, a: 1, b: 2}, false);26 // Test nested maxProperties greater than 0.27 assertSchemaMatch(coll, {properties: {a: {maxProperties: 1}}}, {a: 1}, true);28 assertSchemaMatch(coll, {properties: {a: {maxProperties: 1}}}, {a: {}}, true);29 assertSchemaMatch(coll, {properties: {a: {maxProperties: 1}}}, {a: {b: 1}}, true);30 assertSchemaMatch(coll, {properties: {a: {maxProperties: 1}}}, {a: {b: 1, c: 1}}, false);31 // Test nested maxProperties of 0.32 assertSchemaMatch(coll, {properties: {a: {maxProperties: 0}}}, {a: {}}, true);33 assertSchemaMatch(coll, {properties: {a: {maxProperties: 0}}}, {a: {b: 1}}, false);34 // Test nested minProperties greater than 0.35 assertSchemaMatch(coll, {properties: {a: {minProperties: 1}}}, {a: 1}, true);36 assertSchemaMatch(coll, {properties: {a: {minProperties: 1}}}, {a: {}}, false);37 assertSchemaMatch(coll, {properties: {a: {minProperties: 1}}}, {a: {b: 1}}, true);38 assertSchemaMatch(coll, {properties: {a: {minProperties: 1}}}, {a: {b: 1, c: 1}}, true);...

Full Screen

Full Screen

ContactName.js

Source:ContactName.js Github

copy

Full Screen

1/*2 *3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 *20*/21function toFormattedName(properties) {22 var formatted = "";23 if (properties && properties.givenName) {24 formatted = properties.givenName;25 if (properties && properties.familyName) {26 formatted += " " + properties.familyName;27 }28 }29 return formatted;30}31var ContactName = function (properties) {32 this.familyName = properties && properties.familyName ? properties.familyName : "";33 this.givenName = properties && properties.givenName ? properties.givenName : "";34 this.formatted = toFormattedName(properties);35 this.middleName = properties && properties.middleName ? properties.middleName : "";36 this.honorificPrefix = properties && properties.honorificPrefix ? properties.honorificPrefix : "";37 this.honorificSuffix = properties && properties.honorificSuffix ? properties.honorificSuffix : "";38 this.phoneticFamilyName = properties && properties.phoneticFamilyName ? properties.phoneticFamilyName : "";39 this.phoneticGivenName = properties && properties.phoneticGivenName ? properties.phoneticGivenName : "";40};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { AppComponent } from './app.component';3import { AppModule } from './app.module';4describe('AppComponent', () => {5 beforeEach(() => MockBuilder(AppComponent, AppModule));6 it('should have a title', () => {7 const fixture = MockRender(AppComponent);8 const component = ngMocks.findInstance(AppComponent);9 expect(component.title).toEqual('ng-mocks');10 });11});12import { Component } from '@angular/core';13@Component({14})15export class AppComponent {16 title = 'ng-mocks';17 constructor() {18 this.title = 'ng-mocks';19 }20}21import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';22import { AppComponent } from './app.component';23import { AppModule } from './app.module';24describe('AppComponent', () => {25 beforeEach(() => MockBuilder(AppComponent, AppModule));26 it('should have a title', () => {27 const fixture = MockRender(AppComponent);28 const component = ngMocks.findInstance(AppComponent);29 expect(component.title).toEqual('ng-mocks');30 });31});32import { Component } from '@angular/core';33@Component({34})35export class AppComponent {36 title = 'ng-mocks';37 constructor() {38 this.title = 'ng-mocks';39 }40}41import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';42import { AppComponent } from './app.component';43import { AppModule } from './app

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { AppModule } from './app.module';3import { AppComponent } from './app.component';4describe('AppComponent', () => {5 beforeEach(() => MockBuilder(AppComponent, AppModule));6 it('should create the app', () => {7 const fixture = MockRender(AppComponent);8 const app = fixture.point.componentInstance;9 expect(app).toBeTruthy();10 });11 it('should have as title "ng-mocks"', () => {12 const fixture = MockRender(AppComponent);13 const app = fixture.point.componentInstance;14 expect(app.title).toEqual('ng-mocks');15 });16 it('should render title', () => {17 const fixture = MockRender(AppComponent);18 const compiled = fixture.point.nativeElement;19 expect(compiled.querySelector('.content span').textContent).toContain(20 );21 });22 it('should render title in a h1 tag', () => {23 const fixture = MockRender(AppComponent);24 const compiled = fixture.point.nativeElement;25 expect(compiled.querySelector('h1').textContent).toContain(26 );27 });28 it('should render title in a h1 tag using ngMocks', () => {29 const fixture = MockRender(AppComponent);30 const compiled = fixture.point.nativeElement;31 expect(ngMocks.formatText(ngMocks.find(compiled, 'h1'))).toContain(32 );33 });34});35import { Component } from '@angular/core';36@Component({37})38export class AppComponent {39 title = 'ng-mocks';40}41 Welcome to {{ title }}!42 src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cD

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { AppModule } from './app.module';3import { AppComponent } from './app.component';4beforeEach(() => MockBuilder(AppComponent, AppModule));5it('checks if the component is created', () => {6 const fixture = MockRender(AppComponent);7 const component = fixture.point.componentInstance;8 expect(component).toBeDefined();9});10it('checks if the component has the property', () => {11 const fixture = MockRender(AppComponent);12 const component = fixture.point.componentInstance;13 expect(component).toHaveProperty('title');14});15it('checks if the component has the property with specific value', () => {16 const fixture = MockRender(AppComponent);17 const component = fixture.point.componentInstance;18 expect(component).toHaveProperty('title', 'ng-mocks');19});20it('checks if the component has the property with specific value using ng-mocks', () => {21 const fixture = MockRender(AppComponent);22 const component = fixture.point.componentInstance;23 expect(ngMocks.formatInstance(component)).toHaveProperty('title', 'ng-mocks');24});25it('checks if the component has the property with specific value using ng-mocks', () => {26 const fixture = MockRender(AppComponent);27 const component = fixture.point.componentInstance;28 expect(ngMocks.formatInstance(component)).toHaveProperty('title', 'ng-mocks');29});30it('checks if the component has the property with specific value using ng-mocks', () => {31 const fixture = MockRender(AppComponent);32 const component = fixture.point.componentInstance;33 expect(ngMocks.formatInstance(component)).toHaveProperty('title', 'ng-mocks');34});35it('checks if the component has the property with specific value using ng-mocks', () => {36 const fixture = MockRender(AppComponent);37 const component = fixture.point.componentInstance;38 expect(ngMocks.formatInstance(component)).toHaveProperty('title', 'ng-mocks');39});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { AppComponent } from './app.component';3beforeEach(() => MockBuilder(AppComponent));4it('has a property', () => {5 const fixture = MockRender(AppComponent);6 expect(ngMocks.formatText(fixture)).toEqual('Hello World');7 expect(fixture.point.componentInstance).toHaveProperty('title', 'Hello World');8});9import { Component, Input } from '@angular/core';10@Component({11 template: '{{ title }}',12})13export class AppComponent {14 @Input() public title = 'Hello World';15}16import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';17import { AppComponent } from './app.component';18beforeEach(() => MockBuilder(AppComponent));19it('has a property', () => {20 const fixture = MockRender(AppComponent);21 expect(ngMocks.formatText(fixture)).toEqual('Hello World');22 expect(fixture.point.componentInstance).toHaveProperty('title', 'Hello World');23});24{{ title }}25import { Component, Input } from '@angular/core';26@Component({27 template: '{{ title }}',28})29export class AppComponent {30 @Input() public title = 'Hello World';31}32import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';33import { AppComponent } from './app.component';34beforeEach(() => MockBuilder(AppComponent));35it('has a property', () => {36 const fixture = MockRender(AppComponent);37 expect(ngMocks.formatText(fixture)).toEqual('Hello World');38 expect(fixture.point.componentInstance).toHaveProperty('title', 'Hello World');39});40{{ title }}41import { Component, Input } from '@angular/core';42@Component({43 template: '{{ title }}',44})45export class AppComponent {46 @Input() public title = 'Hello World';47}48import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';49import { AppComponent } from './app.component';50beforeEach(() => MockBuilder(AppComponent));51it('has a property', () => {52 const fixture = MockRender(AppComponent);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { MockBuilder, MockRender, ngMocks } = require('ng-mocks');2const { AppModule } = require('./app.module');3const { AppComponent } = require('./app.component');4describe('AppComponent', () => {5 beforeEach(() => MockBuilder(AppComponent).keep(AppModule));6 it('should create the app', () => {7 const fixture = MockRender(AppComponent);8 const app = fixture.point.componentInstance;9 expect(app).toBeTruthy();10 });11 it(`should have as title 'app'`, () => {12 const fixture = MockRender(AppComponent);13 const app = fixture.point.componentInstance;14 expect(app.title).toEqual('app');15 });16 it('should render title in a h1 tag', () => {17 const fixture = MockRender(AppComponent);18 const compiled = fixture.nativeElement;19 expect(compiled.querySelector('h1').textContent).toContain(20 );21 });22 it('should have a button', () => {23 const fixture = MockRender(AppComponent);24 const compiled = fixture.nativeElement;25 expect(compiled.querySelector('button')).toBeTruthy();26 });27 it('should have a button with a click event', () => {28 const fixture = MockRender(AppComponent);29 const compiled = fixture.nativeElement;30 expect(compiled.querySelector('button').click).toBeTruthy();31 });32 it('should have a button with a click event that calls a function', () => {33 const fixture = MockRender(AppComponent);34 const compiled = fixture.nativeElement;35 expect(compiled.querySelector('button').click).toBeTruthy();36 const app = fixture.point.componentInstance;37 spyOn(app, 'onClick');38 compiled.querySelector('button').click();39 expect(app.onClick).toHaveBeenCalled();40 });41});

Full Screen

Using AI Code Generation

copy

Full Screen

1const mock = ngMocks.findInstance(MyComponent);2const value = mock.properties().myProperty;3const mock = ngMocks.findInstance(MyComponent);4const value = mock.properties().myProperty;5const mock = ngMocks.findInstance(MyComponent);6const value = mock.properties().myProperty;7const mock = ngMocks.findInstance(MyComponent);8const value = mock.properties().myProperty;9const mock = ngMocks.findInstance(MyComponent);10const value = mock.properties().myProperty;11const mock = ngMocks.findInstance(MyComponent);12const value = mock.properties().myProperty;13const mock = ngMocks.findInstance(MyComponent);14const value = mock.properties().myProperty;15const mock = ngMocks.findInstance(MyComponent);16const value = mock.properties().myProperty;17const mock = ngMocks.findInstance(MyComponent);18const value = mock.properties().myProperty;19const mock = ngMocks.findInstance(MyComponent);20const value = mock.properties().myProperty;21const mock = ngMocks.findInstance(MyComponent);22const value = mock.properties().myProperty;23const mock = ngMocks.findInstance(MyComponent);24const value = mock.properties().myProperty;25const mock = ngMocks.findInstance(MyComponent);26const value = mock.properties().myProperty;27const mock = ngMocks.findInstance(MyComponent);28const value = mock.properties().myProperty;

Full Screen

Using AI Code Generation

copy

Full Screen

1const properties = ngMocks.properties('my-component');2expect(properties.myProperty).toEqual('myValue');3expect(properties.myOtherProperty).toEqual('myOtherValue');4const properties = ngMocks.properties('my-component');5expect(properties.myProperty).toEqual('myValue');6expect(properties.myOtherProperty).toEqual('myOtherValue');7const properties = ngMocks.properties('my-component');8expect(properties.myProperty).toEqual('myValue');9expect(properties.myOtherProperty).toEqual('myOtherValue');10const properties = ngMocks.properties('my-component');11expect(properties.myProperty).toEqual('myValue');12expect(properties.myOtherProperty).toEqual('myOtherValue');13const properties = ngMocks.properties('my-component');14expect(properties.myProperty).toEqual('myValue');15expect(properties.myOtherProperty).toEqual('myOtherValue');16const properties = ngMocks.properties('my-component');17expect(properties.myProperty).toEqual('myValue');18expect(properties.myOtherProperty).toEqual('myOtherValue');19const properties = ngMocks.properties('my-component');20expect(properties.myProperty).toEqual('myValue');21expect(properties.myOtherProperty).toEqual('myOtherValue');22const properties = ngMocks.properties('my-component');23expect(properties.myProperty).toEqual('myValue');24expect(properties.myOtherProperty).toEqual('myOtherValue');25const properties = ngMocks.properties('my-component');26expect(properties.myProperty).toEqual('myValue');27expect(properties.myOtherProperty).toEqual('myOtherValue');28const properties = ngMocks.properties('my-component');29expect(properties.myProperty).toEqual('myValue');30expect(properties.myOtherProperty).toEqual('myOtherValue');31const properties = ngMocks.properties('my-component');32expect(properties.myProperty).toEqual('myValue');33expect(properties.myOtherProperty).toEqual('myOtherValue');

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 const fixture = createComponent(TestComponent);4 expect(fixture).toBeDefined();5 });6});7@Component({8})9export class TestComponent implements OnInit {10 constructor() { }11 ngOnInit() {12 }13}14@NgModule({15 imports: [16})17export class TestModule { }18import { createComponent } from 'ng-mocks';19import { TestComponent } from './test.component';20import { TestModule } from './test.module';21describe('test', () => {22 it('test', () => {23 const fixture = createComponent(TestComponent, {24 imports: [TestModule]25 });26 expect(fixture).toBeDefined();27 });28});29'ng-mocks' can't find a declaration for 'TestComponent' in module 'TestModule' (TestModule -> TestComponent). ("TestComponent">TestComponent</app-test>30'ng-mocks' can't find a declaration for 'TestComponent' in module 'TestModule' (TestModule -> TestComponent). ("TestComponent">TestComponent</app-test>

Full Screen

Using AI Code Generation

copy

Full Screen

1import { } from '@angular/core/testing';2describe('test', () => {3 it('test', () => {4 const mock = MockRender(MyComponent);5 expect(mock.point.componentInstance).toBeTruthy();6 expect(mock.point.componentInstance).toHaveProperties({7 });8 });9});10import { Component } from '@angular/core';11@Component({12})13export class MyComponent {14 public prop1 = 'value1';15 public prop2 = 'value2';16}17import { } from '@angular/core/testing';18import { MockRender } from 'ng-mocks';19import { MyComponent } from './my-component.component';20describe('MyComponent', () => {21 it('should create', () => {22 const mock = MockRender(MyComponent);23 expect(mock.point.componentInstance).toBeTruthy();24 expect(mock.point.componentInstance).toHaveProperties({25 });26 });27});28 ✓ test (5ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1const mock = new MockRender(MyComponent);2mock.point.componentInstance.myProp = 'new value';3expect(mock.point.componentInstance.myProp).toEqual('new value');4import { MockBuilder, MockRender } from 'ng-mocks';5describe('MyComponent', () => {6 beforeEach(async () => {7 await MockBuilder(MyComponent);8 });9 it('should render a property', () => {10 const mock = MockRender(MyComponent);11 mock.point.componentInstance.myProp = 'new value';12 expect(mock.point.componentInstance.myProp).toEqual('new value');13 });14});15import { MockBuilder, MockRender } from 'ng-mocks';16describe('MyComponent', () => {17 beforeEach(async () => {18 await MockBuilder(MyComponent);19 });20 it('should render a property', () => {21 const mock = MockRender(MyComponent);22 mock.point.componentInstance.myProp = 'new value';23 expect(mock.point.componentInstance.myProp).toEqual('new value');24 });25});26import { MockBuilder, MockRender } from 'ng-mocks';27describe('MyComponent', () => {28 beforeEach(async () => {29 await MockBuilder(MyComponent);30 });31 it('should render a property', () => {32 const mock = MockRender(MyComponent);33 mock.point.componentInstance.myProp = 'new value';34 expect(mock.point.componentInstance.myProp).toEqual('new value');35 });36});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful