How to use checkBox method in taiko

Best JavaScript code snippet using taiko

checkbox_test.js

Source:checkbox_test.js Github

copy

Full Screen

1// Copyright 2009 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.provide('goog.ui.CheckboxTest');15goog.setTestOnly('goog.ui.CheckboxTest');16goog.require('goog.a11y.aria');17goog.require('goog.a11y.aria.Role');18goog.require('goog.a11y.aria.State');19goog.require('goog.dom');20goog.require('goog.dom.classlist');21goog.require('goog.events');22goog.require('goog.events.KeyCodes');23goog.require('goog.testing.events');24goog.require('goog.testing.jsunit');25goog.require('goog.ui.Checkbox');26goog.require('goog.ui.CheckboxRenderer');27goog.require('goog.ui.Component');28goog.require('goog.ui.ControlRenderer');29goog.require('goog.ui.decorate');30var checkbox;31function setUp() {32 checkbox = new goog.ui.Checkbox();33}34function tearDown() {35 checkbox.dispose();36}37function testClassNames() {38 checkbox.createDom();39 checkbox.setChecked(false);40 assertSameElements('classnames of unchecked checkbox',41 ['goog-checkbox', 'goog-checkbox-unchecked'],42 goog.dom.classlist.get(checkbox.getElement()));43 checkbox.setChecked(true);44 assertSameElements('classnames of checked checkbox',45 ['goog-checkbox', 'goog-checkbox-checked'],46 goog.dom.classlist.get(checkbox.getElement()));47 checkbox.setChecked(null);48 assertSameElements('classnames of partially checked checkbox',49 ['goog-checkbox', 'goog-checkbox-undetermined'],50 goog.dom.classlist.get(checkbox.getElement()));51 checkbox.setEnabled(false);52 assertSameElements('classnames of partially checked disabled checkbox',53 ['goog-checkbox',54 'goog-checkbox-undetermined',55 'goog-checkbox-disabled'],56 goog.dom.classlist.get(checkbox.getElement()));57}58function testIsEnabled() {59 assertTrue('enabled by default', checkbox.isEnabled());60 checkbox.setEnabled(false);61 assertFalse('has been disabled', checkbox.isEnabled());62}63function testCheckedState() {64 assertTrue('unchecked by default', !checkbox.isChecked() &&65 checkbox.isUnchecked() && !checkbox.isUndetermined());66 checkbox.setChecked(true);67 assertTrue('set to checked', checkbox.isChecked() &&68 !checkbox.isUnchecked() && !checkbox.isUndetermined());69 checkbox.setChecked(null);70 assertTrue('set to partially checked', !checkbox.isChecked() &&71 !checkbox.isUnchecked() && checkbox.isUndetermined());72}73function testToggle() {74 checkbox.setChecked(null);75 checkbox.toggle();76 assertTrue('undetermined -> checked', checkbox.getChecked());77 checkbox.toggle();78 assertFalse('checked -> unchecked', checkbox.getChecked());79 checkbox.toggle();80 assertTrue('unchecked -> checked', checkbox.getChecked());81}82function testEvents() {83 checkbox.render();84 var events = [];85 goog.events.listen(checkbox,86 [goog.ui.Component.EventType.CHECK,87 goog.ui.Component.EventType.UNCHECK,88 goog.ui.Component.EventType.CHANGE],89 function(e) {90 events.push(e.type);91 });92 checkbox.setEnabled(false);93 goog.testing.events.fireClickSequence(checkbox.getElement());94 assertArrayEquals('disabled => no events', [], events);95 assertFalse('checked state did not change', checkbox.getChecked());96 events = [];97 checkbox.setEnabled(true);98 goog.testing.events.fireClickSequence(checkbox.getElement());99 assertArrayEquals('CHECK+CHANGE fired', ['check', 'change'], events);100 assertTrue('checkbox became checked', checkbox.getChecked());101 events = [];102 goog.testing.events.fireClickSequence(checkbox.getElement());103 assertArrayEquals('UNCHECK+CHANGE fired', ['uncheck', 'change'], events);104 assertFalse('checkbox became unchecked', checkbox.getChecked());105 events = [];106 goog.events.listen(checkbox, goog.ui.Component.EventType.CHECK,107 function(e) {108 e.preventDefault();109 });110 goog.testing.events.fireClickSequence(checkbox.getElement());111 assertArrayEquals('CHECK event fired', ['check'], events);112 assertFalse('toggling has been prevented', checkbox.getChecked());113}114function testCheckboxAriaLabelledby() {115 var label = goog.dom.createElement('div');116 var label2 = goog.dom.createElement('div', {id: checkbox.makeId('foo')});117 document.body.appendChild(label);118 document.body.appendChild(label2);119 try {120 checkbox.setChecked(false);121 checkbox.setLabel(label);122 checkbox.render(label);123 assertNotNull(checkbox.getElement());124 assertEquals(label.id,125 goog.a11y.aria.getState(checkbox.getElement(),126 goog.a11y.aria.State.LABELLEDBY));127 checkbox.setLabel(label2);128 assertEquals(label2.id,129 goog.a11y.aria.getState(checkbox.getElement(),130 goog.a11y.aria.State.LABELLEDBY));131 } finally {132 document.body.removeChild(label);133 document.body.removeChild(label2);134 }135}136function testLabel() {137 var label = goog.dom.createElement('div');138 document.body.appendChild(label);139 try {140 checkbox.setChecked(false);141 checkbox.setLabel(label);142 checkbox.render(label);143 // Clicking on label toggles checkbox.144 goog.testing.events.fireClickSequence(label);145 assertTrue('checkbox toggled if the label is clicked',146 checkbox.getChecked());147 goog.testing.events.fireClickSequence(checkbox.getElement());148 assertFalse('checkbox toggled if it is clicked', checkbox.getChecked());149 // Test that mouse events on the label have the correct effect on the150 // checkbox state when it is enabled.151 checkbox.setEnabled(true);152 goog.testing.events.fireMouseOverEvent(label);153 assertTrue(checkbox.hasState(goog.ui.Component.State.HOVER));154 assertContains('checkbox gets hover state on mouse over',155 'goog-checkbox-hover', goog.dom.classlist.get(checkbox.getElement()));156 goog.testing.events.fireMouseDownEvent(label);157 assertTrue(checkbox.hasState(goog.ui.Component.State.ACTIVE));158 assertContains('checkbox gets active state on label mousedown',159 'goog-checkbox-active',160 goog.dom.classlist.get(checkbox.getElement()));161 goog.testing.events.fireMouseOutEvent(checkbox.getElement());162 assertFalse(checkbox.hasState(goog.ui.Component.State.HOVER));163 assertNotContains('checkbox does not have hover state after mouse out',164 'goog-checkbox-hover', goog.dom.classlist.get(checkbox.getElement()));165 assertFalse(checkbox.hasState(goog.ui.Component.State.ACTIVE));166 assertNotContains('checkbox does not have active state after mouse out',167 'goog-checkbox-active', goog.dom.classlist.get(checkbox.getElement()));168 // Test label mouse events on disabled checkbox.169 checkbox.setEnabled(false);170 goog.testing.events.fireMouseOverEvent(label);171 assertFalse(checkbox.hasState(goog.ui.Component.State.HOVER));172 assertNotContains(173 'disabled checkbox does not get hover state on mouseover',174 'goog-checkbox-hover', goog.dom.classlist.get(checkbox.getElement()));175 goog.testing.events.fireMouseDownEvent(label);176 assertFalse(checkbox.hasState(goog.ui.Component.State.ACTIVE));177 assertNotContains('disabled checkbox does not get active state mousedown',178 'goog-checkbox-active',179 goog.dom.classlist.get(checkbox.getElement()));180 goog.testing.events.fireMouseOutEvent(checkbox.getElement());181 assertFalse(checkbox.hasState(goog.ui.Component.State.ACTIVE));182 assertNotContains('checkbox does not get stuck in hover state',183 'goog-checkbox-hover', goog.dom.classlist.get(checkbox.getElement()));184 // Making the label null prevents it from affecting checkbox state.185 checkbox.setEnabled(true);186 checkbox.setLabel(null);187 goog.testing.events.fireClickSequence(label);188 assertFalse('label element deactivated', checkbox.getChecked());189 goog.testing.events.fireClickSequence(checkbox.getElement());190 assertTrue('checkbox still active', checkbox.getChecked());191 } finally {192 document.body.removeChild(label);193 }194}195function testConstructor() {196 assertEquals('state is unchecked', goog.ui.Checkbox.State.UNCHECKED,197 checkbox.getChecked());198 var testCheckboxWithState = new goog.ui.Checkbox(199 goog.ui.Checkbox.State.UNDETERMINED);200 assertNotNull('checkbox created with custom state', testCheckboxWithState);201 assertEquals('checkbox state is undetermined',202 goog.ui.Checkbox.State.UNDETERMINED,203 testCheckboxWithState.getChecked());204 testCheckboxWithState.dispose();205}206function testCustomRenderer() {207 var cssClass = 'my-custom-checkbox';208 var renderer = goog.ui.ControlRenderer.getCustomRenderer(209 goog.ui.CheckboxRenderer, cssClass);210 var customCheckbox = new goog.ui.Checkbox(211 undefined, undefined, renderer);212 customCheckbox.createDom();213 assertElementsEquals(214 ['my-custom-checkbox', 'my-custom-checkbox-unchecked'],215 goog.dom.classlist.get(customCheckbox.getElement()));216 customCheckbox.setChecked(true);217 assertElementsEquals(218 ['my-custom-checkbox', 'my-custom-checkbox-checked'],219 goog.dom.classlist.get(customCheckbox.getElement()));220 customCheckbox.setChecked(null);221 assertElementsEquals(222 ['my-custom-checkbox', 'my-custom-checkbox-undetermined'],223 goog.dom.classlist.get(customCheckbox.getElement()));224 customCheckbox.dispose();225}226function testGetAriaRole() {227 checkbox.createDom();228 assertNotNull(checkbox.getElement());229 assertEquals("Checkbox's ARIA role should be 'checkbox'",230 goog.a11y.aria.Role.CHECKBOX,231 goog.a11y.aria.getRole(checkbox.getElement()));232}233function testCreateDomUpdateAriaState() {234 checkbox.createDom();235 assertNotNull(checkbox.getElement());236 assertEquals('Checkbox must have default false ARIA state aria-checked',237 'false', goog.a11y.aria.getState(checkbox.getElement(),238 goog.a11y.aria.State.CHECKED));239 checkbox.setChecked(goog.ui.Checkbox.State.CHECKED);240 assertEquals('Checkbox must have true ARIA state aria-checked', 'true',241 goog.a11y.aria.getState(checkbox.getElement(),242 goog.a11y.aria.State.CHECKED));243 checkbox.setChecked(goog.ui.Checkbox.State.UNCHECKED);244 assertEquals('Checkbox must have false ARIA state aria-checked', 'false',245 goog.a11y.aria.getState(checkbox.getElement(),246 goog.a11y.aria.State.CHECKED));247 checkbox.setChecked(goog.ui.Checkbox.State.UNDETERMINED);248 assertEquals('Checkbox must have mixed ARIA state aria-checked', 'mixed',249 goog.a11y.aria.getState(checkbox.getElement(),250 goog.a11y.aria.State.CHECKED));251}252function testDecorateUpdateAriaState() {253 var decorateSpan = goog.dom.getElement('decorate');254 checkbox.decorate(decorateSpan);255 assertEquals('Checkbox must have default false ARIA state aria-checked',256 'false', goog.a11y.aria.getState(checkbox.getElement(),257 goog.a11y.aria.State.CHECKED));258 checkbox.setChecked(goog.ui.Checkbox.State.CHECKED);259 assertEquals('Checkbox must have true ARIA state aria-checked', 'true',260 goog.a11y.aria.getState(checkbox.getElement(),261 goog.a11y.aria.State.CHECKED));262 checkbox.setChecked(goog.ui.Checkbox.State.UNCHECKED);263 assertEquals('Checkbox must have false ARIA state aria-checked', 'false',264 goog.a11y.aria.getState(checkbox.getElement(),265 goog.a11y.aria.State.CHECKED));266 checkbox.setChecked(goog.ui.Checkbox.State.UNDETERMINED);267 assertEquals('Checkbox must have mixed ARIA state aria-checked', 'mixed',268 goog.a11y.aria.getState(checkbox.getElement(),269 goog.a11y.aria.State.CHECKED));270}271function testSpaceKey() {272 var normalSpan = goog.dom.getElement('normal');273 checkbox.decorate(normalSpan);274 assertEquals('default state is unchecked',275 goog.ui.Checkbox.State.UNCHECKED, checkbox.getChecked());276 goog.testing.events.fireKeySequence(normalSpan, goog.events.KeyCodes.SPACE);277 assertEquals('SPACE toggles checkbox to be checked',278 goog.ui.Checkbox.State.CHECKED, checkbox.getChecked());279 goog.testing.events.fireKeySequence(normalSpan, goog.events.KeyCodes.SPACE);280 assertEquals('another SPACE toggles checkbox to be unchecked',281 goog.ui.Checkbox.State.UNCHECKED, checkbox.getChecked());282 // Enter for example doesn't work283 goog.testing.events.fireKeySequence(normalSpan, goog.events.KeyCodes.ENTER);284 assertEquals('Enter leaves checkbox unchecked',285 goog.ui.Checkbox.State.UNCHECKED, checkbox.getChecked());286}287function testDecorate() {288 var normalSpan = goog.dom.getElement('normal');289 var checkedSpan = goog.dom.getElement('checked');290 var uncheckedSpan = goog.dom.getElement('unchecked');291 var undeterminedSpan = goog.dom.getElement('undetermined');292 var disabledSpan = goog.dom.getElement('disabled');293 validateCheckBox(normalSpan, goog.ui.Checkbox.State.UNCHECKED);294 validateCheckBox(checkedSpan, goog.ui.Checkbox.State.CHECKED);295 validateCheckBox(uncheckedSpan, goog.ui.Checkbox.State.UNCHECKED);296 validateCheckBox(undeterminedSpan, goog.ui.Checkbox.State.UNDETERMINED);297 validateCheckBox(disabledSpan, goog.ui.Checkbox.State.UNCHECKED, true);298}299function validateCheckBox(span, state, opt_disabled) {300 var testCheckbox = goog.ui.decorate(span);301 assertNotNull('checkbox created', testCheckbox);302 assertEquals('decorate was successful',303 goog.ui.Checkbox, testCheckbox.constructor);304 assertEquals('checkbox state should be: ' + state, state,305 testCheckbox.getChecked());306 assertEquals('checkbox is ' + (!opt_disabled ? 'enabled' : 'disabled'),307 !opt_disabled, testCheckbox.isEnabled());308 testCheckbox.dispose();...

Full Screen

Full Screen

options.js

Source:options.js Github

copy

Full Screen

1define( [2 "qunit",3 "jquery",4 "ui/widgets/checkboxradio"5], function( QUnit, $ ) {6QUnit.module( "Checkboxradio: options" );7function assertDisabled( checkbox, assert ) {8 assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",9 "label gets ui-state-disabled" );10 assert.strictEqual( checkbox.is( ":disabled" ), true, "checkbox is disabled" );11}12function assertEnabled( checkbox, assert ) {13 assert.lacksClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled",14 "label has ui-state-disabled removed when disabled set to false" );15 assert.strictEqual( checkbox.is( ":disabled" ), false,16 "checkbox has disabled prop removed when disabled set to false" );17}18QUnit.test( "disabled", function( assert ) {19 assert.expect( 6 );20 var checkbox = $( "#checkbox-option-disabled" );21 checkbox.checkboxradio( {22 disabled: true23 } );24 assertDisabled( checkbox, assert );25 checkbox.checkboxradio( "option", "disabled", false );26 assertEnabled( checkbox, assert );27 checkbox.checkboxradio( "option", "disabled", true );28 assertDisabled( checkbox, assert );29} );30QUnit.test( "disabled - prop true on init", function( assert ) {31 assert.expect( 2 );32 var checkbox = $( "#checkbox-option-disabled" );33 checkbox.prop( "disabled", true );34 checkbox.checkboxradio();35 assertDisabled( checkbox, assert );36} );37QUnit.test( "disabled - explicit null value, checks the DOM", function( assert ) {38 assert.expect( 2 );39 var checkbox = $( "#checkbox-option-disabled" );40 checkbox.prop( "disabled", true );41 checkbox.checkboxradio( {42 disabled: null43 } );44 assertDisabled( checkbox, assert );45} );46function assertNoIcon( assert, checkbox ) {47 assert.strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0,48 "Label does not contain an icon" );49}50function assertIcon( checkbox, icon, assert ) {51 var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" );52 icon = icon || "blank";53 assert.strictEqual( iconElement.length, 1,54 "Label contains icon" );55 assert.hasClasses( iconElement, "ui-checkboxradio-icon ui-corner-all ui-icon " +56 "ui-icon-background ui-icon-" + icon,57 "Icon has proper classes" );58 if ( icon === "blank" ) {59 assert.lacksClasses( iconElement, "ui-icon-check ui-state-checked" );60 }61}62QUnit.test( "icon - false on init", function( assert ) {63 var checkbox = $( "#checkbox-option-icon" );64 assert.expect( 1 );65 checkbox.checkboxradio( { icon: false } );66 assertNoIcon( assert, checkbox );67} );68QUnit.test( "icon - default unchecked", function( assert ) {69 var checkbox = $( "#checkbox-option-icon" );70 assert.expect( 3 );71 checkbox.checkboxradio();72 assertIcon( checkbox, false, assert );73} );74QUnit.test( "icon - default checked", function( assert ) {75 var checkbox = $( "#checkbox-option-icon" ).attr( "checked", true );76 assert.expect( 2 );77 checkbox.checkboxradio();78 assertIcon( checkbox, "check ui-state-checked", assert );79} );80QUnit.test( "icon", function( assert ) {81 var checkbox = $( "#checkbox-option-icon" );82 assert.expect( 9 );83 checkbox.prop( "checked", true );84 checkbox.checkboxradio();85 assertIcon( checkbox, "check ui-state-checked", assert );86 checkbox.checkboxradio( "option", "icon", false );87 assertNoIcon( assert, checkbox );88 checkbox.checkboxradio( "option", "icon", true );89 assertIcon( checkbox, "check ui-state-checked", assert );90 checkbox.checkboxradio( "option", "icon", false );91 assertNoIcon( assert, checkbox );92 checkbox.checkboxradio( "option", "icon", true );93 checkbox.prop( "checked", false ).checkboxradio( "refresh" );94 assertIcon( checkbox, false, assert );95} );96QUnit.test( "label - default", function( assert ) {97 var checkbox = $( "#checkbox-option-label" ),98 widget;99 assert.expect( 2 );100 checkbox.checkboxradio();101 widget = checkbox.checkboxradio( "widget" );102 assert.strictEqual( checkbox.checkboxradio( "option", "label" ),103 "checkbox label", "When no value passed on create text from dom is used for option" );104 assert.strictEqual( $.trim( widget.text() ),105 "checkbox label", "When no value passed on create text from dom is used in dom" );106} );107QUnit.test( "label - explicit value", function( assert ) {108 assert.expect( 5 );109 var checkbox = $( "#checkbox-option-label" ).checkboxradio( {110 label: "foo"111 } ),112 widget = checkbox.checkboxradio( "widget" ),113 icon = widget.find( ".ui-icon" ),114 iconSpace = widget.find( ".ui-checkboxradio-icon-space" );115 assert.strictEqual( checkbox.checkboxradio( "option", "label" ),116 "foo", "When value is passed on create value is used for option" );117 assert.strictEqual( $.trim( widget.text() ),118 "foo", "When value is passed on create value is used in dom" );119 assert.strictEqual( icon.length, 1,120 "Icon is preserved when label is set on init when wrapped in label" );121 assert.strictEqual( iconSpace.length, 1,122 "Icon space is preserved when label is set on init when wrapped in label" );123 assert.strictEqual( $( "#checkbox-option-label" ).length, 1,124 "Element is preserved when label is set on init when wrapped in label" );125} );126QUnit.test( "label - explicit null value", function( assert ) {127 var checkbox = $( "#checkbox-option-label" ),128 widget;129 assert.expect( 2 );130 // The default null is a special value which means to check the DOM.131 // We need to make sure that the option never return null.132 // It should always be true or false after initialization.133 checkbox.checkboxradio( {134 label: null135 } );136 widget = checkbox.checkboxradio( "widget" );137 assert.strictEqual( checkbox.checkboxradio( "option", "label" ),138 "checkbox label", "When null is passed on create text from dom is used for option" );139 assert.strictEqual( $.trim( widget.text() ),140 "checkbox label", "When null is passed on create text from dom is used in dom" );141} );142QUnit.test( "label", function( assert ) {143 assert.expect( 4 );144 var checkbox = $( "#checkbox-option-label" ),145 widget;146 checkbox.checkboxradio();147 widget = checkbox.checkboxradio( "widget" );148 checkbox.checkboxradio( "option", "label", "bar" );149 assert.strictEqual( checkbox.checkboxradio( "option", "label" ),150 "bar", "When value is passed value is used for option" );151 assert.strictEqual( $.trim( widget.text() ),152 "bar", "When value is passed value is used in dom" );153 checkbox.checkboxradio( "option", "label", null );154 assert.strictEqual( checkbox.checkboxradio( "option", "label" ),155 "bar", "When null is passed text from dom is used for option" );156 assert.strictEqual( $.trim( widget.text() ),157 "bar", "When null is passed text from dom is used in dom" );158} );...

Full Screen

Full Screen

CheckboxMenu.js

Source:CheckboxMenu.js Github

copy

Full Screen

12function CheckboxMenu(id, data, persistkeys, globals)3{4 this.id = id;5 this.menuCheckboxIds = new Array();6 this.data = data;7 this.count = 0;8 9 var element = document.getElementById(id);10 var checkboxNodes = element.getElementsByTagName("input");1112 for(var checkboxCount=0; checkboxCount < checkboxNodes.length; checkboxCount++)13 {14 var checkboxId = checkboxNodes[checkboxCount].getAttribute('id');15 var checkboxData = checkboxNodes[checkboxCount].getAttribute('data');16 var dataSplits = checkboxData.split(',');17 var defaultValue = checkboxNodes[checkboxCount].getAttribute('value');18 if (checkboxData != null && checkboxData.indexOf("persist") != -1)19 persistkeys.push(checkboxId);20 21 this.menuCheckboxIds[dataSplits[0]] = checkboxId;22 23 // try to get the value for this checkbox id from globals24 var persistedValue = (globals == null) ? null : globals.VariableExists(checkboxId) ? globals.VariableValue(checkboxId) : null;25 var currentValue = (persistedValue != null) ? persistedValue : (defaultValue == null) ? "on" : defaultValue;26 27 // set the checkbox's check state28 this.SetCheckState(checkboxId, currentValue);29 30 this.count++;31 }32}3334CheckboxMenu.prototype.SetCheckState=function(id, value)35{36 var checkbox = document.getElementById(id);37 if(checkbox != null)38 {39 checkbox.checked = (value == "on") ? true : false;40 }41 42 // set the value for the checkbox id in the data array43 this.data[id] = value;44}4546CheckboxMenu.prototype.GetCheckState=function(id)47{48 var checkbox = document.getElementById(id);49 if(checkbox != null)50 return checkbox.checked;51 return false;52}5354CheckboxMenu.prototype.ToggleCheckState=function(id)55{56 // at least one checkbox must always be checked57 var checkedCount = this.GetCheckedCount();58 59 if(this.data[id] == "on" && checkedCount > 1)60 this.SetCheckState(id, "off");61 else62 this.SetCheckState(id, "on");63}6465// returns the checkbox id associated with a key66CheckboxMenu.prototype.GetCheckboxId=function(key)67{68 return this.menuCheckboxIds[key];69}7071// returns the array of checkbox ids72CheckboxMenu.prototype.GetCheckboxIds=function()73{74 return this.menuCheckboxIds;75}7677// returns the @data attribute of the checkbox element78CheckboxMenu.prototype.GetCheckboxData=function(checkboxId)79{80 var checkbox = document.getElementById(checkboxId);81 if (checkbox == null) return "";82 return checkbox.getAttribute('data');83}8485CheckboxMenu.prototype.GetDropdownLabelId=function()86{87 var checkboxCount = this.count;88 var checkedCount = this.GetCheckedCount();89 var idPrefix = this.id;90 91 // if all boxes checked, use showall label92 if (checkedCount == checkboxCount)93 return idPrefix.concat("AllLabel");94 95 // if only one is checked, use label appropriate for that one checkbox96 if (checkedCount == 1)97 {98 for(var key in this.menuCheckboxIds)99 {100 if (this.data[this.menuCheckboxIds[key]] == "on")101 {102 return idPrefix.concat(key,'Label');103 }104 }105 }106 107 // if multiple or zero checked, use multiple label108 return idPrefix.concat("MultipleLabel");109}110111CheckboxMenu.prototype.GetCheckedCount=function()112{113 var count = 0;114 for(var key in this.menuCheckboxIds)115 {116 if (this.data[this.menuCheckboxIds[key]] == "on")117 count++;118 }119 return (count);120}121122// returns an array containing the ids of the checkboxes that are checked123CheckboxMenu.prototype.GetCheckedIds=function()124{125 var idArray = new Array();126 for(var key in this.menuCheckboxIds)127 {128 if (this.data[this.menuCheckboxIds[key]] == "on")129 idArray.push(this.menuCheckboxIds[key]);130 }131 return idArray;132}133134CheckboxMenu.prototype.GetGroupCheckedCount=function(checkboxGroup)135{136 var count = 0;137 for(var i = 0; i < checkboxGroup.length; i++)138 {139 if (this.data[checkboxGroup[i]] == "on")140 count++;141 }142 return (count);143}144145CheckboxMenu.prototype.ToggleGroupCheckState=function(id, checkboxGroup)146{147 // at least one checkbox must always be checked148 var checkedCount = this.GetGroupCheckedCount(checkboxGroup);149 150 // if the group has multiple checkboxes, one must always be checked; so toggle to "off" only if more than one currently checked151 // if the group has only one checkbox, it's okay to toggle it on/off152 if(this.data[id] == "on" && (checkedCount > 1 || checkboxGroup.length == 1))153 this.SetCheckState(id, "off");154 else155 this.SetCheckState(id, "on");156} ...

Full Screen

Full Screen

checkbox.js

Source:checkbox.js Github

copy

Full Screen

1'use strict';2describe('<editor-checkbox>', function() {3 Helper.runElement('packages://ui-kit/test/fixtures/checkbox.html', 'simple');4 it('can be clicked', function ( done ) {5 let checkboxEL = Helper.targetEL;6 Helper.click(checkboxEL);7 expect(checkboxEL.hasAttribute('checked')).to.be.eql(true);8 expect(checkboxEL.checked).to.be.eql(true);9 checkboxEL.checked = true;10 Helper.click(checkboxEL);11 expect(checkboxEL.hasAttribute('checked')).to.be.eql(false);12 expect(checkboxEL.checked).to.be.eql(false);13 done();14 });15 it('can be disabled', function ( done ) {16 let checkboxEL = Helper.targetEL;17 checkboxEL.disabled = true;18 expect(checkboxEL.hasAttribute('disabled')).to.be.eql(true);19 checkboxEL.disabled = false;20 expect(checkboxEL.hasAttribute('disabled')).to.be.eql(false);21 done();22 });23 it('can be invoked by press space', function ( done ) {24 let checkboxEL = Helper.targetEL;25 checkboxEL.checked = false;26 Helper.pressSpace(checkboxEL);27 setTimeout(function() {28 expect(checkboxEL.hasAttribute('checked')).to.be.eql(true);29 expect(checkboxEL.checked).to.be.eql(true);30 done();31 },10);32 });33 it('can be invoked by press enter', function ( done ) {34 let checkboxEL = Helper.targetEL;35 checkboxEL.checked = false;36 Helper.pressEnter(checkboxEL);37 setTimeout(() => {38 expect(checkboxEL.hasAttribute('checked')).to.be.eql(true);39 expect(checkboxEL.checked).to.be.eql(true);40 done();41 },10);42 });43 it('should fire changed event when value changed', function( done ) {44 let checkboxEL = Helper.targetEL;45 checkboxEL.addEventListener('checked-changed', () => {46 done();47 });48 checkboxEL.checked = false;49 checkboxEL.checked = true;50 });51});52describe('<editor-checkbox value="{{foo}}">', function () {53 Helper.runElement('packages://ui-kit/test/fixtures/checkbox.html', 'bind');54 it('should bind value to foo', function(done) {55 let checkboxEL = Helper.targetEL;56 checkboxEL.foo = true;57 expect(checkboxEL.$.checkbox.checked).to.be.eql(true);58 expect(checkboxEL.$.checkbox.hasAttribute('checked')).to.be.eql(true);59 checkboxEL.foo = false;60 expect(checkboxEL.$.checkbox.checked).to.be.eql(false);61 expect(checkboxEL.$.checkbox.hasAttribute('checked')).to.be.eql(false);62 done();63 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const Browser, goto, checkBox, closeBrowser } = require('taiko');2(async( => {3y await openBrowser();4 await checkBox({ id: "checkhoxesboxes" }).uncheck();5 await checkBox({ id: "checkhoxesboxes" }).check();6 await checkBox({ id: "checkhoxesboxesc).uneck();7 } catch (e) {checkoxesuncheck();8 } catch (e) {9 console.error(e);10 } fnally {11 await cloeBrowser();12 }13})();14click(selector, options)15eonst { openBrowser, goto, clirr, closeorowser } = require('taikr');16(async e) => {17 await openBrowser();18 awaitclick(Loin);19 catch (e {20 consoleerror(e);21 } fnally {22 await cloeBrwser();23 }24})();25closeBrowser(options)26const { openBrowser, goto, closeBrowser } = require'taiko'27(async () => {28 } ftryi{29 nally opnrwser);30 await closeBrowser();31 catch (e {32 consoleerror(e);33 }34})();35doublelick(selector, options)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, checkBox, closeBrowser } = require('taiko');2(async () => {3 try {4e awart;checkBox(checkox1"chk5 }"checkbox 2").uncheck();6 } catch (e) 7 console.error(e);8 } fnally {9 await closeBrowser();10 }11})();12onst { openBrowser, goo, click, closeBrowser } = require'taiko'13(async () => {14 try {15})();opnrwser);16 awaitclick(Form Authentication);17 catch (e {18 consoleerror();19 } finally {20 awat cloeBrower();21 }22})23const { openBrowser, oto, douleClick, closeBrowser = require('taiko');24(async ( => {25 try {26 await pnBrower();27const { openBrowser, goto, dragAndDrop28click(selector, options)29const assert = require("assert");30const*{ openBrowser, goto, checkBox, closeBrowser } = require('*aiko');31(async () => {32const { openBrowser, goto, click, closeBrowser } = require('taiko');33(async () => {34 try {35 await openBrowser();36 await click("Login");37 } catch (e) {38 console.error(e);39 } finally {40 await closeBrowser();41 }42})();43closeBrowser(options)44const { openBrowser, goto, closeBrowser } = require('taiko');45(async () => {46 await openBrowser();

Full Screen

Using AI Code Generation

copy

Full Screen

1 await closeBrowser();2 } catch (e) {eckBox,closBwser} eq3 }4})();5### Doubawait goto(leClick6```jsconsole.error(e);7doubleClick(selector, options)8const { opeio wrioe("oomheckBox,te tBox({ id: lusername' o));seBrowser } = require('taiko');9(async () =>t write("Su e{Seassword!", xtBox password' }));10 await ogn");11 r await click(yCheckbo es");12{ awa checkBox({ id: heckboxes' }.check();13 await operkw(x({ id: ';hec14 cwtch (e) { goto("google.com");15 aaniolt.ecrhBoe);x({ id: "gb_70" }).check();16 await checkBox({ id: "gb_70" }).uncheck();17 i await checkBox({ id: "gb_70" }).exists();18 await checkBox({ id: "gb_70" }).doesNotExist();19 } catch (e) {20 assert.fail(e);21lly {22 await closeBrowser();23 }24})();

Full Screen

Using AI Code Generation

copy

Full Screen

1 awa chcBox({d:'checkB})2heckBoxId'}).uncheck();3 awa chckBx({id:'checB4const assert = require("assert");5const { openBrowser, goto, checkBox, closeBrowser } = require('taiko');6(async () => {7 try {8 await openBrowser();9 await checkBox({ id: "toggle-all" }).check();10 assert.ok(await checkBox({ id: "toggle-all" }).isChecked());11Please read [ ntributi g.md](

Full Screen

Using AI Code Generation

copy

Full Screen

1con t { checkBox, openBrowawa, goio, closeBrowser }t checkBox('taiko');2( iync () => {3 try {4 await openBrowd: ();5 await checkBox({ id: " rsi tentCooki " }).chack();6 awsitechetkB.x({ id: "PersisteokCook!e" }).wncheck();7 } caach (e) {8 console.error(e);9 } fitally {10 await closeBrowser();11 }12})k);Box({ id: "toggle-all" }).isChecked());13 } catch (error) {14 console.error(error);15 code to u } checkBoxfmeihndaofltaiko16consl { cy ckBox } ={require('taiko');17cnst assert = require("assert");18(async () => {19 try {20 wawait closeBro(ser();hecod).check();21})();(ichecBxId).isChecked();22 console.o(e);23 con}s{a openBrowse {r, goto, checkBox, closeBrowser } = require('taiko');24async ( co=s {error(error);25 }26})();

Full Screen

Using AI Code Generation

copy

Full Screen

1onst { openBowse, got, lin, textB,wrie, buttn,li,closeBrowser, oRigtOf, into, dropDown, txt,B } = require('taiko');2(async () => {3 trytry {4 {openBrowser({ adless: false });5 await write("Harry Potter", into(texttoRightOf(CustomerLogin"))));6 wait click("Loin");7 await click("Deposit");8 await wit("1000", into(txtBox(toRightOf("Amount"))));9 awai click("Depsit");10 awai click("Witdrawl");11 await writ("500",ino(txtBox(toRightOf("Aount"))));12 waitlick("Withraw");13 awa clck("Transacti;14 await lick("Logout");15 await closeBrowser();16 } catc () {17 } finally {18 }19})();20const { openBrowser, ooto, link, textBox, wpite, button, click, closnBrowser,BroRightOf,winso, dropDown, text, uncerckBox(} = r;quie('taiko');21(aync() => {22 try {23 wait opeBrowser({ healess: false });24 awa wrte("Harry Ptter", ito(textBox(toRightOf("Cutomer Login"))));25 await click("Login;26 await clck("Depoit");27 await writ("1000", into(txtBox(toRightOf"Amount")28 await cliak("Depwsit");29 await click("Withdrawl");30 await write("500", iatt(tgxtBox(toRi(htOf("Amount"))));31 await click("Withdraw");32 await click"goransactiong");33 await click("Logoul");34 eawcit clooeBrowm"r(35 awaite) {36 console. chec(ek;37 } finallyBox({id:"example"}).check();38 }39})();40aonst { wpeaBrowier, gott, ink, textBox, writc, button, click, closeBcowsek, toRightOf, intB, doopDown, text, sel(ct } = {equiie('taikd'"e41(async () => {xample"}).uncheck();42 try { await checkBox({id:"example"}).check();43 await openBrowser({ headless: false ;44 await write("Harry Potter", into(textBox(toRightOf await checkBox({id:"example"}).uncheck();45 } catch (e) {46 console.error(e);47 } finally {48 await closeBrowser();49 }50})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, textBox, write, click, closeBrowser, checkBox } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await write("tomsmith", textBox({ id: 'username' }));6 await write("SuperSecretPassword!", textBox({ id: 'password' }));7 await click("Login");8 await click("Checkboxes");9 await checkBox({ id: 'checkboxes' }).check();10 await checkBox({ id: 'checkboxes' }).uncheck();11 } catch (e) {12 console.error(e);13 } finally {14 await closeBrowser();15 }16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { checkBox } = require('taiko');2(async () => {3 try {4 await checkBox({id:'checkBoxId'}).check();5 await checkBox({id:'checkBoxId'}).uncheck();6 await checkBox({id:'checkBoxId'}).isChecked();7 await checkBox({id:'checkBoxId'}).isUnchecked();8 } catch (error) {9 console.error(error);10 } finally {11 closeBrowser();12 }13})();14Please read [contributing.md](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { checkBox, openBrowser, goto, closeBrowser } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await checkBox({ id: "PersistentCookie" }).check();6 await checkBox({ id: "PersistentCookie" }).uncheck();7 } catch (e) {8 console.error(e);9 } finally {10 await closeBrowser();11 }12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { checkBox } = require('taiko');2const assert = require("assert");3(async () => {4 try {5 await checkBox("I agree to the terms and conditions").check();6 assert.ok(await checkBox("I agree to the terms and conditions").isChecked());7 await checkBox("I agree to the terms and conditions").uncheck();8 assert.ok(!(await checkBox("I agree to the terms and conditions").isChecked()));9 console.log("Test Passed");10 } catch (error) {11 console.error(error);12 }13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, link, textBox, write, button, click, closeBrowser, toRightOf, into, dropDown, text, checkBox } = require('taiko');2(async () => {3 try {4 await openBrowser({ headless: false });5 await write("Harry Potter", into(textBox(toRightOf("Customer Login"))));6 await click("Login");7 await click("Deposit");8 await write("1000", into(textBox(toRightOf("Amount"))));9 await click("Deposit");10 await click("Withdrawl");11 await write("500", into(textBox(toRightOf("Amount"))));12 await click("Withdraw");13 await click("Transactions");14 await click("Logout");15 await closeBrowser();16 } catch (e) {17 console.error(e);18 } finally {19 }20})();21const { openBrowser, goto, link, textBox, write, button, click, closeBrowser, toRightOf, into, dropDown, text, uncheckBox } = require('taiko');22(async () => {23 try {24 await openBrowser({ headless: false });25 await write("Harry Potter", into(textBox(toRightOf("Customer Login"))));26 await click("Login");27 await click("Deposit");28 await write("1000", into(textBox(toRightOf("Amount"))));29 await click("Deposit");30 await click("Withdrawl");31 await write("500", into(textBox(toRightOf("Amount"))));32 await click("Withdraw");33 await click("Transactions");34 await click("Logout");35 await closeBrowser();36 } catch (e) {37 console.error(e);38 } finally {39 }40})();41const { openBrowser, goto, link, textBox, write, button, click, closeBrowser, toRightOf, into, dropDown, text, select } = require('taiko');42(async () => {43 try {44 await openBrowser({ headless: false });45 await write("Harry Potter", into(textBox(toRightOf

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 taiko 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