Best JavaScript code snippet using wpt
test-box-properties.js
Source:test-box-properties.js
1import {2 testElement,3 writingModes,4 testCSSValues,5 testComputedValues,6 makeDeclaration7} from "./test-shared.js";8// Values to use while testing9const testValues = {10 "length": ["1px", "2px", "3px", "4px", "5px"],11 "color": ["rgb(1, 1, 1)", "rgb(2, 2, 2)", "rgb(3, 3, 3)", "rgb(4, 4, 4)", "rgb(5, 5, 5)"],12 "border-style": ["solid", "dashed", "dotted", "double", "groove"],13};14/**15 * Creates a group of physical and logical box properties, such as16 *17 * { physical: {18 * left: "margin-left", right: "margin-right",19 * top: "margin-top", bottom: "margin-bottom",20 * }, logical: {21 * inlineStart: "margin-inline-start", inlineEnd: "margin-inline-end",22 * blockStart: "margin-block-start", blockEnd: "margin-block-end",23 * }, shorthands: {24 * "margin": ["margin-top", "margin-right", "margin-bottom", "margin-left"],25 * "margin-inline": ["margin-inline-start", "margin-inline-end"],26 * "margin-block": ["margin-block-start", "margin-block-end"],27 * }, type: ["length"], prerequisites: "...", property: "margin-*" }28 *29 * @param {string} property30 * A string representing the property names, like "margin-*".31 * @param {Object} descriptor32 * @param {string|string[]} descriptor.type33 * Describes the kind of values accepted by the property, like "length".34 * Must be a key or a collection of keys from the `testValues` object.35 * @param {Object={}} descriptor.prerequisites36 * Represents property declarations that are needed by `property` to work.37 * For example, border-width properties require a border style.38 */39export function createBoxPropertyGroup(property, descriptor) {40 const logical = {};41 const physical = {};42 const shorthands = {};43 for (const axis of ["inline", "block"]) {44 const shorthand = property.replace("*", axis);45 const longhands = [];46 shorthands[shorthand] = longhands;47 for (const side of ["start", "end"]) {48 const logicalSide = axis + "-" + side;49 const camelCase = logicalSide.replace(/-(.)/g, (match, $1) => $1.toUpperCase());50 const longhand = property.replace("*", logicalSide);51 logical[camelCase] = longhand;52 longhands.push(longhand);53 }54 }55 const isInset = property === "inset-*";56 let prerequisites = "";57 for (const physicalSide of ["left", "right", "top", "bottom"]) {58 physical[physicalSide] = isInset ? physicalSide : property.replace("*", physicalSide);59 prerequisites += makeDeclaration(descriptor.prerequisites, physicalSide);60 }61 shorthands[property.replace("-*", "")] =62 ["top", "right", "bottom", "left"].map(physicalSide => physical[physicalSide]);63 const type = [].concat(descriptor.type);64 return {logical, physical, shorthands, type, prerequisites, property};65}66/**67 * Creates a group of physical and logical sizing properties.68 *69 * @param {string} prefix70 * One of "", "max-" or "min-".71 */72export function createSizingPropertyGroup(prefix) {73 return {74 logical: {75 inline: `${prefix}inline-size`,76 block: `${prefix}block-size`,77 },78 physical: {79 horizontal: `${prefix}width`,80 vertical: `${prefix}height`,81 },82 type: ["length"],83 prerequisites: makeDeclaration({display: "block"}),84 property: (prefix ? prefix.slice(0, -1) + " " : "") + "sizing",85 };86}87/**88 * Tests a grup of logical and physical properties in different writing modes.89 *90 * @param {Object} group91 * An object returned by createBoxPropertyGroup or createSizingPropertyGroup.92 */93export function runTests(group) {94 const values = testValues[group.type[0]].map(function(_, i) {95 return group.type.map(type => testValues[type][i]).join(" ");96 });97 const logicals = Object.values(group.logical);98 const physicals = Object.values(group.physical);99 const shorthands = group.shorthands ? Object.entries(group.shorthands) : null;100 test(function() {101 const expected = [];102 for (const [i, logicalProp] of logicals.entries()) {103 testElement.style.setProperty(logicalProp, values[i]);104 expected.push([logicalProp, values[i]]);105 }106 testCSSValues("logical properties in inline style", testElement.style, expected);107 }, `Test that logical ${group.property} properties are supported.`);108 testElement.style.cssText = "";109 const shorthandValues = {};110 for (const [shorthand, longhands] of shorthands || []) {111 let valueArray;112 if (group.type.length > 1) {113 valueArray = [values[0]];114 } else {115 valueArray = testValues[group.type].slice(0, longhands.length);116 }117 shorthandValues[shorthand] = valueArray;118 const value = valueArray.join(" ");119 const expected = [[shorthand, value]];120 for (let [i, longhand] of longhands.entries()) {121 expected.push([longhand, valueArray[group.type.length > 1 ? 0 : i]]);122 }123 test(function() {124 testElement.style.setProperty(shorthand, value);125 testCSSValues("shorthand in inline style", testElement.style, expected);126 const stylesheet = `.test { ${group.prerequisites} }`;127 testComputedValues("shorthand in computed style", stylesheet, expected);128 }, `Test that ${shorthand} shorthand sets longhands and serializes correctly.`);129 testElement.style.cssText = "";130 }131 for (const writingMode of writingModes) {132 for (const style of writingMode.styles) {133 const writingModeDecl = makeDeclaration(style);134 const associated = {};135 for (const [logicalSide, logicalProp] of Object.entries(group.logical)) {136 const physicalProp = group.physical[writingMode[logicalSide]];137 associated[logicalProp] = physicalProp;138 associated[physicalProp] = logicalProp;139 }140 // Test that logical properties are converted to their physical141 // equivalent correctly when all in the group are present on a single142 // declaration, with no overwriting of previous properties and143 // no physical properties present. We put the writing mode properties144 // on a separate declaration to test that the computed values of these145 // properties are used, rather than those on the same declaration.146 test(function() {147 let decl = group.prerequisites;148 const expected = [];149 for (const [i, logicalProp] of logicals.entries()) {150 decl += `${logicalProp}: ${values[i]}; `;151 expected.push([logicalProp, values[i]]);152 expected.push([associated[logicalProp], values[i]]);153 }154 testComputedValues("logical properties on one declaration, writing " +155 `mode properties on another, '${writingModeDecl}'`,156 `.test { ${writingModeDecl} } .test { ${decl} }`,157 expected);158 }, `Test that logical ${group.property} properties share computed values `159 + `with their physical associates, with '${writingModeDecl}'.`);160 // Test logical shorthand properties.161 if (shorthands) {162 test(function() {163 for (const [shorthand, longhands] of shorthands) {164 let valueArray = shorthandValues[shorthand];165 const decl = group.prerequisites + `${shorthand}: ${valueArray.join(" ")}; `;166 const expected = [];167 for (let [i, longhand] of longhands.entries()) {168 const longhandValue = valueArray[group.type.length > 1 ? 0 : i];169 expected.push([longhand, longhandValue]);170 expected.push([associated[longhand], longhandValue]);171 }172 testComputedValues("shorthand properties on one declaration, writing " +173 `mode properties on another, '${writingModeDecl}'`,174 `.test { ${writingModeDecl} } .test { ${decl} }`,175 expected);176 }177 }, `Test that ${group.property} shorthands set the computed value of both `178 + `logical and physical longhands, with '${writingModeDecl}'.`);179 }180 // Test that logical and physical properties are cascaded together,181 // honoring their relative order on a single declaration182 // (a) with a single logical property after the physical ones183 // (b) with a single physical property after the logical ones184 test(function() {185 for (const lastIsLogical of [true, false]) {186 const lasts = lastIsLogical ? logicals : physicals;187 const others = lastIsLogical ? physicals : logicals;188 for (const lastProp of lasts) {189 let decl = writingModeDecl + group.prerequisites;190 const expected = [];191 for (const [i, prop] of others.entries()) {192 decl += `${prop}: ${values[i]}; `;193 const valueIdx = associated[prop] === lastProp ? others.length : i;194 expected.push([prop, values[valueIdx]]);195 expected.push([associated[prop], values[valueIdx]]);196 }197 decl += `${lastProp}: ${values[others.length]}; `;198 testComputedValues(`'${lastProp}' last on single declaration, '${writingModeDecl}'`,199 `.test { ${decl} }`,200 expected);201 }202 }203 }, `Test that ${group.property} properties honor order of appearance when both `204 + `logical and physical associates are declared, with '${writingModeDecl}'.`);205 // Test that logical and physical properties are cascaded properly when206 // on different declarations207 // (a) with a logical property in the high specificity rule208 // (b) with a physical property in the high specificity rule209 test(function() {210 for (const highIsLogical of [true, false]) {211 let lowDecl = writingModeDecl + group.prerequisites;212 const high = highIsLogical ? logicals : physicals;213 const others = highIsLogical ? physicals : logicals;214 for (const [i, prop] of others.entries()) {215 lowDecl += `${prop}: ${values[i]}; `;216 }217 for (const highProp of high) {218 const highDecl = `${highProp}: ${values[others.length]}; `;219 const expected = [];220 for (const [i, prop] of others.entries()) {221 const valueIdx = associated[prop] === highProp ? others.length : i;222 expected.push([prop, values[valueIdx]]);223 expected.push([associated[prop], values[valueIdx]]);224 }225 testComputedValues(`'${highProp}', two declarations, '${writingModeDecl}'`,226 `#test { ${highDecl} } .test { ${lowDecl} }`,227 expected);228 }229 }230 }, `Test that ${group.property} properties honor selector specificty when both `231 + `logical and physical associates are declared, with '${writingModeDecl}'.`);232 }233 }...
Using AI Code Generation
1var wptools = require('wptools');2wptools.page('Albert Einstein').then(function(page) {3 return page.writingModeDecl();4}).then(function(writingModeDecl) {5 console.log(writingModeDecl);6}).catch(function(err) {7 console.log('Error:', err);8});9{ '0': 'ltr', '1': 'ltr', '2': 'ltr' }10var wptools = require('wptools');11wptools.page('Albert Einstein').then(function(page) {12 return page.writingModeDecl();13}).then(function(writingModeDecl) {14 console.log(writingModeDecl);15}).catch(function(err) {16 console.log('Error:', err);17});18{ '0': 'ltr', '1': 'ltr', '2': 'ltr' }19var wptools = require('wptools');20wptools.page('Albert Einstein').then(function(page) {21 return page.writingMode();22}).then(function(writingMode) {23 console.log(writingMode);24}).catch(function(err) {25 console.log('Error:', err);26});27{ '0': 'horizontal-tb', '1': 'horizontal-tb', '2': 'horizontal-tb' }28var wptools = require('wptools');29wptools.page('Albert Einstein').then(function(page) {30 return page.writingMode();31}).then(function(writingMode) {32 console.log(writingMode);33}).catch(function(err) {34 console.log('Error:', err);35});36{ '0': 'horizontal-tb', '1': 'horizontal-tb', '2': 'horizontal-tb' }37var wptools = require('wptools');38wptools.page('Albert Einstein').then(function(page) {39 return page.writingMode();40}).then(function(writingMode) {41 console.log(writingMode);42}).catch(function(err) {43 console.log('Error:', err);44});45{ '0': 'horizontal
Using AI Code Generation
1var cssom = new CSSOM();2cssom.writingModeDecl("horizontal-tb", "test");3cssom.writingModeDecl("vertical-rl", "test");4cssom.writingModeDecl("vertical-lr", "test");5cssom.writingModeDecl("horizontal-bt", "test");6cssom.writingModeDecl("vertical-lr", "test");7cssom.writingModeDecl("vertical-rl", "test");8cssom.writingModeDecl("horizontal-tb", "test");9var CSSOM = function() {10 this.writingModeDecl = function(writingMode, id) {11 var div = document.getElementById(id);12 div.style.writingMode = writingMode;13 var computedStyle = window.getComputedStyle(div);14 var computedWritingMode = computedStyle.getPropertyValue("writing-mode");15 var result = computedWritingMode == writingMode;16 return result;17 }18}
Using AI Code Generation
1var editor = wp.editor;2var writingMode = editor.writingModeDecl( 'vertical-rl' );3editor.on( 'init', function() {4 editor.getBody().style.writingMode = writingMode;5} );6I have added the code in test.js file and included it in the plugin. The problem is the editor.on( 'init' ) is not working. How can I get the editor to work?
Using AI Code Generation
1var wptUtils = require('wptutils');2module.exports = {3 'Test writingModeDecl' : function (browser) {4 .url(url)5 .waitForElementVisible('body', 1000)6 .assert.writingModeDecl('html', 'horizontal-tb')7 .end();8 }9};10 body {11 writing-mode: vertical-rl;12 }
Using AI Code Generation
1var textlayout = require('wptextlayout');2var text = "Hello World";3var textLayout = new textlayout.TextLayout(text);4textLayout.writingModeDecl("vertical-lr");5textLayout.writingModeDecl("horizontal-tb");6textLayout.writingModeDecl("vertical-rl");7textLayout.writingModeDecl("horizontal-bt");8textLayout.writingModeDecl("sideways-lr");9textLayout.writingModeDecl("sideways-rl");10textLayout.writingModeDecl("lr-tb");11textLayout.writingModeDecl("rl-tb");12textLayout.writingModeDecl("tb-rl");13textLayout.writingModeDecl("tb-lr");14textLayout.writingModeDecl("lr");15textLayout.writingModeDecl("rl");16textLayout.writingModeDecl("tb");17textLayout.writingModeDecl("lr-tb");18textLayout.writingModeDecl("rl-tb");19textLayout.writingModeDecl("tb-rl");20textLayout.writingModeDecl("tb-lr");21textLayout.writingModeDecl("horizontal-tb");22textLayout.writingModeDecl("vertical-rl");23textLayout.writingModeDecl("vertical-lr");24textLayout.writingModeDecl("sideways-rl");25textLayout.writingModeDecl("sideways-lr");26textLayout.writingModeDecl("horizontal-bt");27 at Object.TextLayout.writingModeDecl (C:\Users\user\Desktop\wptextlayout\build\Release\wptextlayout.node:1:177)28 at Object.<anonymous> (C:\Users\user\Desktop\wptextlayout\test.js:6:20)29 at Module._compile (module.js:456:26)30 at Object.Module._extensions..js (module.js:474:10)31 at Module.load (module.js:356:32)32 at Function.Module._load (module.js:312:12)33 at Function.Module.runMain (module.js:497:10)34 at startup (node.js:119:16)
Using AI Code Generation
1var wpt = require('./wpt.js');2var wpt = new wpt();3wpt.writingModeDecl("vertical-lr");4wpt.writingModeDecl("horizontal-tb");5var writingModeDecl = function(writingMode){6 var css = "";7 css += "writing-mode: " + writingMode + ";";8 css += "-webkit-writing-mode: " + writingMode + ";";9 css += "-ms-writing-mode: " + writingMode + ";";10 css += "-o-writing-mode: " + writingMode + ";";11 css += "-moz-writing-mode: " + writingMode + ";";12 return css;13};14module.exports = writingModeDecl;
Using AI Code Generation
1var test = new writingModeDecl();2test.testWritingModeDecl();3var test = new writingModeDecl();4test.testWritingModeDecl();5var test = new writingModeDecl();6test.testWritingModeDecl();7var test = new writingModeDecl();8test.testWritingModeDecl();9var test = new writingModeDecl();10test.testWritingModeDecl();11var test = new writingModeDecl();12test.testWritingModeDecl();13var test = new writingModeDecl();14test.testWritingModeDecl();15var test = new writingModeDecl();16test.testWritingModeDecl();17var test = new writingModeDecl();18test.testWritingModeDecl();19var test = new writingModeDecl();20test.testWritingModeDecl();
Using AI Code Generation
1var textString = "This is a test of the writingModeDecl method of the wptext object.";2var fontName = "Arial";3var fontSize = 12;4var fontStyle = "normal";5var fontVariant = "normal";6var fontWeight = "normal";7var direction = "ltr";8var orientation = "sideways-right";9var alignment = "start";10var anchor = "start";11var baseline = "alphabetic";12var x = 50;13var y = 50;14var text = app.wpText;15text.writingModeDecl(textString, fontName, fontSize, fontStyle, fontVariant, fontWeight, direction, orientation, alignment, anchor, baseline, x, y);16var bbox = text.getBBox();17text.drawRect(bbox[0], bbox[1], bbox[2], bbox[3]);18var nLines = text.getNumLines();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!