How to use isWindows method in ng-mocks

Best JavaScript code snippet using ng-mocks

db-tx-error-mapping-test.js

Source:db-tx-error-mapping-test.js Github

copy

Full Screen

1/* 'use strict'; */2var MYTIMEOUT = 12000;3// NOTE: DEFAULT_SIZE wanted depends on type of browser4var isWindows = /MSAppHost/.test(navigator.userAgent);5var isAndroid = !isWindows && /Android/.test(navigator.userAgent);6var isFirefox = /Firefox/.test(navigator.userAgent);7var isWebKitBrowser = !isWindows && !isAndroid && /Safari/.test(navigator.userAgent);8var isBrowser = isWebKitBrowser || isFirefox;9var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));10var isChromeBrowser = isBrowser && !isEdgeBrowser && (/Chrome/.test(navigator.userAgent));11var isSafariBrowser = isWebKitBrowser && !isEdgeBrowser && !isChromeBrowser;12// detect iOS platform:13var isAppleMobileOS =14 (/iPhone/.test(navigator.userAgent)15 || /iPad/.test(navigator.userAgent)16 || /iPod/.test(navigator.userAgent));17// should avoid popups (Safari seems to count 2x)18var DEFAULT_SIZE = isSafariBrowser ? 2000000 : 5000000;19// FUTURE TBD: 50MB should be OK on Chrome and some other test browsers.20// NOTE: While in certain version branches there is no difference between21// the default Android implementation and implementation #2,22// this test script will also apply the androidLockWorkaround: 1 option23// in case of implementation #2.24var scenarioList = [25 isAndroid ? 'Plugin-implementation-default' : 'Plugin',26 'HTML5',27 'Plugin-implementation-2'28];29var scenarioCount = (!!window.hasWebKitWebSQL) ? (isAndroid ? 3 : 2) : 1;30var mytests = function() {31 for (var i=0; i<scenarioCount; ++i) {32 // TBD skip plugin test on browser platform (not yet supported):33 if (isBrowser && (i === 0)) continue;34 describe(scenarioList[i] + ': db tx error mapping test(s) [TBD INCORRECT & INCONSISTENT error message on Windows - missing actual error info ref: litehelpers/Cordova-sqlite-storage#539]', function() {35 var scenarioName = scenarioList[i];36 var suiteName = scenarioName + ': ';37 var isWebSql = (i === 1);38 var isImpl2 = (i === 2);39 // XXX TBD WORKAROUND SOLUTION for (WebKit) Web SQL on Safari browser (TEST DB NAME IGNORED):40 var recycleWebDatabase = null;41 // NOTE: MUST be defined in function scope, NOT outer scope:42 var openDatabase = function(name, ignored1, ignored2, ignored3) {43 if (isWebSql && isSafariBrowser && !!recycleWebDatabase)44 return recycleWebDatabase;45 if (isImpl2) {46 return window.sqlitePlugin.openDatabase({47 // prevent reuse of database from default db implementation:48 name: 'i2-'+name,49 androidDatabaseImplementation: 2,50 androidLockWorkaround: 1,51 location: 152 });53 }54 if (isWebSql) {55 return recycleWebDatabase =56 window.openDatabase(name, '1.0', 'Test', DEFAULT_SIZE);57 } else {58 return window.sqlitePlugin.openDatabase({name: name, location: 0});59 }60 }61 // ERROR MAPPING ISSUES/DEVIATIONS:62 //63 // - In case an executeSql error handler returns true (WebKit) Web SQL indicates64 // error code 0 (SQLError.UNKNOWN_ERR) in the transaction error callback65 // - In certain database error cases (WebKit) Web SQL and plugin on Android66 // (no androidDatabaseImplementation: 2 setting) & iOS report SQLError code 567 // (SQLError.SYNTAX_ERR) wile it should be 1 (SQLError.DATABASE_ERR)68 // ("not covered by any other error code") ref:69 // https://www.w3.org/TR/webdatabase/#dom-sqlerror-code-170 // - Android plugin with androidDatabaseImplementation: 2 setting indicates SQLError code 071 // (SQLError.UNKNOWN_ERR) in cases other than a syntax error or constraint violation72 // - Windows plugin always reports error code 0 (SQLError.UNKNOWN_ERR) and73 // INCONSISTENT messages (missing actual error info)74 // OTHER ERROR MAPPING NOTES:75 //76 // - (WebKit) Web SQL apparently includes 'prepare statement error' vs77 // 'execute statement error' info along with the sqlite error code78 // - Default Android implementation (Android-sqlite-connector) includes79 // sqlite3_prepare_v2 vs sqlite3_step function call info indicating80 // 'prepare statement error' vs 'execute statement error'81 // - Android plugin with androidDatabaseImplementation: 2 setting includes the sqlite error code82 // - Windows plugin also includes info indicating 'prepare statement error' vs83 // 'execute statement error', along with sqlite error code in case of84 // 'execute statement error'85 // GENERAL NOTE: ERROR MESSAGES are subject to improvements and other possible changes.86 it(suiteName + 'syntax error: command with misspelling', function(done) {87 var db = openDatabase("Syntax-error-test.db", "1.0", "Demo", DEFAULT_SIZE);88 expect(db).toBeDefined();89 // VERIFY that an error object was received in the end90 var sqlerror = null;91 db.transaction(function(tx) {92 // syntax error due to misspelling:93 tx.executeSql('SLCT 1 ', [], function(tx) {94 // NOT EXPECTED:95 expect(false).toBe(true);96 throw new Error('abort tx');97 }, function(tx, error) {98 sqlerror = error;99 expect(error).toBeDefined();100 expect(error.code).toBeDefined();101 expect(error.message).toBeDefined();102 // error.hasOwnProperty('message') apparently NOT WORKING on103 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:104 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))105 expect(error.hasOwnProperty('message')).toBe(true);106 if (isWindows || (isAndroid && isImpl2))107 expect(error.code).toBe(0);108 else109 expect(error.code).toBe(5);110 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))111 expect(error.message).toMatch(/could not prepare statement.*1 near \"SLCT\": syntax error/);112 else if (isWindows)113 expect(error.message).toMatch(/Error preparing an SQLite statement/);114 else if (!isWebSql && !isWindows && isAndroid && !isImpl2)115 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*near \"SLCT\": syntax error/);116 else if (!isWebSql && !isWindows && isAndroid && isImpl2)117 expect(error.message).toMatch(/near \"SLCT\": syntax error.*code 1.*while compiling: SLCT 1/);118 else119 expect(error.message).toMatch(/near \"SLCT\": syntax error/);120 // FAIL transaction & check reported transaction error:121 return true;122 });123 }, function (error) {124 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered125 expect(error).toBeDefined();126 expect(error.code).toBeDefined();127 expect(error.message).toBeDefined();128 // error.hasOwnProperty('message') apparently NOT WORKING on129 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:130 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))131 expect(error.hasOwnProperty('message')).toBe(true);132 if (isWindows || isWebSql || (isAndroid && isImpl2))133 expect(error.code).toBe(0);134 else135 expect(error.code).toBe(5);136 if (isWebSql)137 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);138 else if (isWindows)139 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);140 else141 expect(error.message).toMatch(/error callback did not return false.*syntax error/);142 isWebSql ? done() : db.close(done, done);143 }, function() {144 // NOT EXPECTED:145 expect(false).toBe(true);146 isWebSql ? done() : db.close(done, done);147 });148 }, MYTIMEOUT);149 it(suiteName + 'syntax error: comma after a field name', function(done) {150 var db = openDatabase('comma-after-field-name-error-test.db');151 expect(db).toBeDefined();152 // VERIFY that an error object was received in the end153 var sqlerror = null;154 db.transaction(function(tx) {155 // This insertion has a SQL syntax error156 tx.executeSql('SELECT name, from Users', [], function(tx) {157 // NOT EXPECTED:158 expect(false).toBe(true);159 throw new Error('abort tx');160 }, function(tx, error) {161 sqlerror = error;162 expect(error).toBeDefined();163 expect(error.code).toBeDefined();164 expect(error.message).toBeDefined();165 // error.hasOwnProperty('message') apparently NOT WORKING on166 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:167 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))168 expect(error.hasOwnProperty('message')).toBe(true);169 if (isWindows || (isAndroid && isImpl2))170 expect(error.code).toBe(0);171 else172 expect(error.code).toBe(5);173 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))174 expect(error.message).toMatch(/could not prepare statement.*1 near \"from\": syntax error/);175 else if (isWindows)176 expect(error.message).toMatch(/Error preparing an SQLite statement/);177 else178 expect(error.message).toMatch(/near \"from\": syntax error/);179 // FAIL transaction & check reported transaction error:180 return true;181 });182 }, function (error) {183 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered184 expect(error).toBeDefined();185 expect(error.code).toBeDefined();186 expect(error.message).toBeDefined();187 // error.hasOwnProperty('message') apparently NOT WORKING on188 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:189 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))190 expect(error.hasOwnProperty('message')).toBe(true);191 if (isWindows || isWebSql || (isAndroid && isImpl2))192 expect(error.code).toBe(0);193 else194 expect(error.code).toBe(5);195 if (isWebSql)196 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);197 else if (isWindows)198 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);199 else200 expect(error.message).toMatch(/error callback did not return false.*syntax error/);201 isWebSql ? done() : db.close(done, done);202 }, function() {203 // NOT EXPECTED:204 expect(false).toBe(true);205 isWebSql ? done() : db.close(done, done);206 });207 }, MYTIMEOUT);208 it(suiteName + 'INSERT with VALUES in the wrong place (and with a trailing space) [TBD "incomplete input" vs "syntax error" message IGNORED on (WebKit) Web SQL on Android 7.0(+) & iOS 12.0(+)]', function(done) {209 var db = openDatabase("INSERT-Syntax-error-test.db", "1.0", "Demo", DEFAULT_SIZE);210 expect(db).toBeDefined();211 // VERIFY that an error object was received in the end212 var sqlerror = null;213 db.transaction(function(tx) {214 tx.executeSql('DROP TABLE IF EXISTS test_table');215 tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (data unique)');216 // This insertion has a SQL syntax error217 tx.executeSql('INSERT INTO test_table (data) VALUES ', [123], function(tx) {218 // NOT EXPECTED:219 expect(false).toBe(true);220 throw new Error('abort tx');221 }, function(tx, error) {222 sqlerror = error;223 expect(error).toBeDefined();224 expect(error.code).toBeDefined();225 expect(error.message).toBeDefined();226 // error.hasOwnProperty('message') apparently NOT WORKING on227 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:228 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))229 expect(error.hasOwnProperty('message')).toBe(true);230 if (isWindows || (isAndroid && isImpl2))231 expect(error.code).toBe(0);232 else233 expect(error.code).toBe(5);234 if (isWebSql && (isAppleMobileOS || (/Android [7-9]/.test(navigator.userAgent))))235 // TBD incomplete input vs syntax error message IGNORED on Android 7.0(+) & iOS 12.0(+)236 expect(error.message).toMatch(/could not prepare statement.*/);237 else if (isWebSql && !isBrowser && !(/Android 4.[1-3]/.test(navigator.userAgent)))238 expect(error.message).toMatch(/could not prepare statement.*1 near \"VALUES\": syntax error/);239 else if (isWebSql && isBrowser)240 expect(error.message).toMatch(/could not prepare statement.*1 incomplete input/);241 else if (isWebSql)242 expect(error.message).toMatch(/near \"VALUES\": syntax error/);243 else if (isWindows)244 expect(error.message).toMatch(/Error preparing an SQLite statement/);245 else if (isAndroid && !isImpl2)246 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*incomplete input/);247 else if (isAndroid && isImpl2)248 // TBD more general pattern for Android 9 vs ...249 expect(error.message).toMatch(/code 1.*while compiling: INSERT INTO test_table/);250 else251 expect(error.message).toMatch(/incomplete input/);252 // FAIL transaction & check reported transaction error:253 return true;254 });255 }, function (error) {256 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered257 expect(error).toBeDefined();258 expect(error.code).toBeDefined();259 expect(error.message).toBeDefined();260 // error.hasOwnProperty('message') apparently NOT WORKING on261 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:262 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))263 expect(error.hasOwnProperty('message')).toBe(true);264 if (isWindows || isWebSql || (isAndroid && isImpl2))265 expect(error.code).toBe(0);266 else267 expect(error.code).toBe(5);268 if (isWebSql)269 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);270 else if (isWindows)271 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);272 else if (isAndroid && isImpl2)273 // TBD more general pattern for Android 9 vs ...274 expect(error.message).toMatch(/error callback did not return false.*code 1/);275 else276 expect(error.message).toMatch(/error callback did not return false.*incomplete input/);277 isWebSql ? done() : db.close(done, done);278 }, function() {279 // NOT EXPECTED:280 expect(false).toBe(true);281 isWebSql ? done() : db.close(done, done);282 });283 }, MYTIMEOUT);284 it(suiteName + 'constraint violation', function(done) {285 var db = openDatabase("Constraint-violation-test.db", "1.0", "Demo", DEFAULT_SIZE);286 expect(db).toBeDefined();287 // VERIFY that an error object was received in the end288 var sqlerror = null;289 db.transaction(function(tx) {290 tx.executeSql('DROP TABLE IF EXISTS test_table');291 tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (data unique)');292 // First INSERT OK:293 tx.executeSql("INSERT INTO test_table (data) VALUES (?)", [123], null, function(tx, error) {294 // NOT EXPECTED:295 expect(false).toBe(true);296 expect(error.message).toBe('--');297 });298 // Second INSERT will violate the unique constraint:299 tx.executeSql('INSERT INTO test_table (data) VALUES (?)', [123], function(tx) {300 // NOT EXPECTED:301 expect(false).toBe(true);302 throw new Error('abort tx');303 }, function(tx, error) {304 sqlerror = error;305 expect(error).toBeDefined();306 expect(error.code).toBeDefined();307 expect(error.message).toBeDefined();308 // error.hasOwnProperty('message') apparently NOT WORKING on309 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:310 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))311 expect(error.hasOwnProperty('message')).toBe(true);312 if (isWebSql && (!isAndroid || /Android 4.[1-3]/.test(navigator.userAgent)))313 expect(true).toBe(true); // SKIP for iOS (WebKit) & Android 4.1-4.3 (WebKit) Web SQL314 else if (isWindows)315 expect(error.code).toBe(0);316 else317 expect(error.code).toBe(6);318 // (WebKit) Web SQL (Android/iOS) possibly with a missing 'r'319 if (isWebSql && /Android 4.[1-3]/.test(navigator.userAgent))320 expect(error.message).toMatch(/column data is not unique/);321 else if (isWebSql && isAndroid)322 expect(error.message).toMatch(/could not execute statement due to a constr?aint failure.*19.*constraint failed/);323 else if (isWebSql)324 expect(error.message).toMatch(/constr?aint fail/); // [possibly missing letter on iOS (WebKit) Web SQL]325 else if (isWindows)326 expect(error.message).toMatch(/SQLite3 step error result code: 1/);327 else if (isAndroid && !isImpl2)328 expect(error.message).toMatch(/sqlite3_step failure: UNIQUE constraint failed: test_table\.data/);329 else if (isAndroid && isImpl2)330 expect(error.message).toMatch(/constraint failure/);331 else332 expect(error.message).toMatch(/UNIQUE constraint failed: test_table\.data/);333 // FAIL transaction & check reported transaction error:334 return true;335 });336 }, function (error) {337 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered338 expect(error).toBeDefined();339 expect(error.code).toBeDefined();340 expect(error.message).toBeDefined();341 // error.hasOwnProperty('message') apparently NOT WORKING on342 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:343 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))344 expect(error.hasOwnProperty('message')).toBe(true);345 if (isWindows || isWebSql)346 expect(error.code).toBe(0);347 else348 expect(error.code).toBe(6);349 if (isWebSql)350 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);351 else if (isWindows)352 expect(error.message).toMatch(/error callback did not return false.*SQLite3 step error result code: 1/);353 else354 expect(error.message).toMatch(/error callback did not return false.*constraint fail/);355 isWebSql ? done() : db.close(done, done);356 }, function() {357 // NOT EXPECTED:358 expect(false).toBe(true);359 isWebSql ? done() : db.close(done, done);360 });361 }, MYTIMEOUT);362 it(suiteName + 'SELECT uper("Test") (misspelled function name) [INCORRECT error code WebKit Web SQL & plugin]', function(done) {363 var db = openDatabase("Misspelled-function-name-error-test.db", "1.0", "Demo", DEFAULT_SIZE);364 expect(db).toBeDefined();365 // VERIFY that an error object was received in the end366 var sqlerror = null;367 db.transaction(function(tx) {368 // This insertion has a SQL syntax error369 tx.executeSql('SELECT uper("Test")', [], function(tx) {370 // NOT EXPECTED:371 expect(false).toBe(true);372 throw new Error('abort tx');373 }, function(tx, error) {374 sqlerror = error;375 expect(error).toBeDefined();376 expect(error.code).toBeDefined();377 expect(error.message).toBeDefined();378 // error.hasOwnProperty('message') apparently NOT WORKING on379 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:380 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))381 expect(error.hasOwnProperty('message')).toBe(true);382 if (isWindows || (isAndroid && isImpl2))383 expect(error.code).toBe(0);384 else385 expect(error.code).toBe(5);386 // ACTUAL WebKit Web SQL vs plugin error.message387 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))388 expect(error.message).toMatch(/could not prepare statement.*1 no such function: uper/);389 else if (isWindows)390 expect(error.message).toMatch(/Error preparing an SQLite statement/);391 else if (!isWebSql && !isWindows && isAndroid && !isImpl2)392 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*no such function: uper/);393 else if (!isWebSql && !isWindows && isAndroid && isImpl2)394 expect(error.message).toMatch(/no such function: uper.*code 1/);395 else396 expect(error.message).toMatch(/no such function: uper/);397 // FAIL transaction & check reported transaction error:398 return true;399 });400 }, function (error) {401 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered402 expect(error).toBeDefined();403 expect(error.code).toBeDefined();404 expect(error.message).toBeDefined();405 // error.hasOwnProperty('message') apparently NOT WORKING on406 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:407 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))408 expect(error.hasOwnProperty('message')).toBe(true);409 if (isWebSql || isWindows || (isAndroid && isImpl2))410 expect(error.code).toBe(0);411 else412 expect(error.code).toBe(5);413 if (isWebSql)414 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);415 else if (isWindows)416 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);417 else418 expect(error.message).toMatch(/error callback did not return false.*no such function: uper/);419 isWebSql ? done() : db.close(done, done);420 }, function() {421 // NOT EXPECTED:422 expect(false).toBe(true);423 isWebSql ? done() : db.close(done, done);424 });425 }, MYTIMEOUT);426 it(suiteName + 'SELECT FROM bogus table (other database error) [INCORRECT error code WebKit Web SQL & plugin]', function(done) {427 var db = openDatabase("SELECT-FROM-bogus-table-error-test.db", "1.0", "Demo", DEFAULT_SIZE);428 expect(db).toBeDefined();429 // VERIFY that an error object was received in the end430 var sqlerror = null;431 db.transaction(function(tx) {432 tx.executeSql('DROP TABLE IF EXISTS BogusTable');433 // Attempt to SELECT FROM a bogus table:434 tx.executeSql('SELECT * FROM BogusTable', [], function(ignored1, ignored2) {435 // NOT EXPECTED:436 expect(false).toBe(true);437 throw new Error('abort tx');438 }, function(tx, error) {439 sqlerror = error;440 expect(error).toBeDefined();441 expect(error.code).toBeDefined();442 expect(error.message).toBeDefined();443 // error.hasOwnProperty('message') apparently NOT WORKING on444 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:445 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))446 expect(error.hasOwnProperty('message')).toBe(true);447 if (isWindows || (isAndroid && isImpl2))448 expect(error.code).toBe(0);449 else450 expect(error.code).toBe(5);451 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))452 expect(error.message).toMatch(/could not prepare statement.*1 no such table: BogusTable/);453 else if (isWindows)454 expect(error.message).toMatch(/Error preparing an SQLite statement/);455 else if (!isWebSql && !isWindows && isAndroid && !isImpl2)456 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*no such table: BogusTable/);457 else if (!isWebSql && !isWindows && isAndroid && isImpl2)458 expect(error.message).toMatch(/no such table: BogusTable.*code 1/);459 else460 expect(error.message).toMatch(/no such table: BogusTable/);461 // FAIL transaction & check reported transaction error:462 return true;463 });464 }, function (error) {465 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered466 expect(error).toBeDefined();467 expect(error.code).toBeDefined();468 expect(error.message).toBeDefined();469 // error.hasOwnProperty('message') apparently NOT WORKING on470 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:471 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))472 expect(error.hasOwnProperty('message')).toBe(true);473 if (isWebSql || isWindows || (isAndroid && isImpl2))474 expect(error.code).toBe(0);475 else476 expect(error.code).toBe(5);477 if (isWebSql)478 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);479 else if (isWindows)480 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);481 else482 expect(error.message).toMatch(/error callback did not return false.*no such table: BogusTable/);483 isWebSql ? done() : db.close(done, done);484 }, function() {485 // NOT EXPECTED:486 expect(false).toBe(true);487 isWebSql ? done() : db.close(done, done);488 });489 }, MYTIMEOUT);490 it(suiteName + 'INSERT missing column [INCORRECT error code WebKit Web SQL & plugin]', function(done) {491 var db = openDatabase("INSERT-missing-column-test.db", "1.0", "Demo", DEFAULT_SIZE);492 expect(db).toBeDefined();493 // VERIFY that an error object was received in the end494 var sqlerror = null;495 db.transaction(function(tx) {496 tx.executeSql('DROP TABLE IF EXISTS test_table');497 tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (data1, data2)');498 tx.executeSql('INSERT INTO test_table VALUES (?)', ['abcdef'], function(tx) {499 // NOT EXPECTED:500 expect(false).toBe(true);501 throw new Error('abort tx');502 }, function(tx, error) {503 sqlerror = error;504 expect(error).toBeDefined();505 expect(error.code).toBeDefined();506 expect(error.message).toBeDefined();507 // error.hasOwnProperty('message') apparently NOT WORKING on508 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:509 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))510 expect(error.hasOwnProperty('message')).toBe(true);511 if (isWindows || (isAndroid && isImpl2))512 expect(error.code).toBe(0);513 else514 expect(error.code).toBe(5);515 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))516 expect(error.message).toMatch(/could not prepare statement.*1 table test_table has 2 columns but 1 values were supplied/);517 else if (isWindows)518 expect(error.message).toMatch(/Error preparing an SQLite statement/);519 else if (!isWebSql && !isWindows && isAndroid && !isImpl2)520 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*table test_table has 2 columns but 1 values were supplied/);521 else if (!isWebSql && !isWindows && isAndroid && isImpl2)522 expect(error.message).toMatch(/table test_table has 2 columns but 1 values were supplied.*code 1.*while compiling: INSERT INTO test_table/);523 else524 expect(error.message).toMatch(/table test_table has 2 columns but 1 values were supplied/);525 // FAIL transaction & check reported transaction error:526 return true;527 });528 }, function (error) {529 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered530 expect(error).toBeDefined();531 expect(error.code).toBeDefined();532 expect(error.message).toBeDefined();533 // error.hasOwnProperty('message') apparently NOT WORKING on534 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:535 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))536 expect(error.hasOwnProperty('message')).toBe(true);537 if (isWebSql || isWindows || (isAndroid && isImpl2))538 expect(error.code).toBe(0);539 else540 expect(error.code).toBe(5);541 if (isWebSql)542 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);543 else if (isWindows)544 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);545 else546 expect(error.message).toMatch(/error callback did not return false.*table test_table has 2 columns but 1 values were supplied/);547 isWebSql ? done() : db.close(done, done);548 }, function() {549 // NOT EXPECTED:550 expect(false).toBe(true);551 isWebSql ? done() : db.close(done, done);552 });553 }, MYTIMEOUT);554 it(suiteName + 'INSERT wrong column name [INCORRECT error code WebKit Web SQL & plugin]', function(done) {555 var db = openDatabase("INSERT-wrong-column-name-test.db", "1.0", "Demo", DEFAULT_SIZE);556 expect(db).toBeDefined();557 // VERIFY that an error object was received in the end558 var sqlerror = null;559 db.transaction(function(tx) {560 tx.executeSql('DROP TABLE IF EXISTS test_table');561 tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (data1)');562 tx.executeSql('INSERT INTO test_table (wrong_column) VALUES (?)', ['abcdef'], function(tx) {563 // NOT EXPECTED:564 expect(false).toBe(true);565 throw new Error('abort tx');566 }, function(tx, error) {567 sqlerror = error;568 expect(error).toBeDefined();569 expect(error.code).toBeDefined();570 expect(error.message).toBeDefined();571 // error.hasOwnProperty('message') apparently NOT WORKING on572 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:573 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))574 expect(error.hasOwnProperty('message')).toBe(true);575 if (isWindows || (isAndroid && isImpl2))576 expect(error.code).toBe(0);577 else578 expect(error.code).toBe(5);579 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))580 expect(error.message).toMatch(/could not prepare statement.*1 table test_table has no column named wrong_column/);581 else if (isWindows)582 expect(error.message).toMatch(/Error preparing an SQLite statement/);583 else if (!isWebSql && !isWindows && isAndroid && !isImpl2)584 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*table test_table has no column named wrong_column/);585 else if (!isWebSql && !isWindows && isAndroid && isImpl2)586 expect(error.message).toMatch(/table test_table has no column named wrong_column.*code 1.*while compiling: INSERT INTO test_table/);587 else588 expect(error.message).toMatch(/table test_table has no column named wrong_column/);589 // FAIL transaction & check reported transaction error:590 return true;591 });592 }, function (error) {593 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered594 expect(error).toBeDefined();595 expect(error.code).toBeDefined();596 expect(error.message).toBeDefined();597 // error.hasOwnProperty('message') apparently NOT WORKING on598 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:599 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))600 expect(error.hasOwnProperty('message')).toBe(true);601 if (isWebSql || isWindows || (isAndroid && isImpl2))602 expect(error.code).toBe(0);603 else604 expect(error.code).toBe(5);605 if (isWebSql)606 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);607 else if (isWindows)608 expect(error.message).toMatch(/error callback did not return false.*Error preparing an SQLite statement/);609 else610 expect(error.message).toMatch(/error callback did not return false.*table test_table has no column named wrong_column/);611 isWebSql ? done() : db.close(done, done);612 }, function() {613 // NOT EXPECTED:614 expect(false).toBe(true);615 isWebSql ? done() : db.close(done, done);616 });617 }, MYTIMEOUT);618 // NOTE: For some reason the Android/iOS (WebKit) Web SQL implementation619 // claims to detect the error at the "prepare statement" stage while the620 // plugin detects the error at the "execute statement" stage.621 it(suiteName + 'CREATE VIRTUAL TABLE USING bogus module (other database error) [INCORRECT error code WebKit Web SQL & plugin]', function(done) {622 var db = openDatabase("create-virtual-table-using-bogus-module-error-test.db", "1.0", "Demo", DEFAULT_SIZE);623 expect(db).toBeDefined();624 // VERIFY that an error object was received in the end625 var sqlerror = null;626 db.transaction(function(tx) {627 tx.executeSql('DROP TABLE IF EXISTS test_table');628 // Attempt to use a bogus module:629 tx.executeSql('CREATE VIRTUAL TABLE test_table USING bogus_module (data)', [], function(ignored1, ignored2) {630 // NOT EXPECTED:631 expect(false).toBe(true);632 throw new Error('abort tx');633 }, function(tx, error) {634 sqlerror = error;635 expect(error).toBeDefined();636 expect(error.code).toBeDefined();637 expect(error.message).toBeDefined();638 // error.hasOwnProperty('message') apparently NOT WORKING on639 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:640 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))641 expect(error.hasOwnProperty('message')).toBe(true);642 if (isWindows || (!isWebSql && isAndroid && isImpl2))643 expect(error.code).toBe(0);644 else645 expect(error.code).toBe(5);646 if (isWebSql && isAndroid && !(/Android 4.[1-3]/.test(navigator.userAgent)))647 expect(error.message).toMatch(/could not prepare statement.*not authorized/);648 else if (isWebSql && isAndroid)649 expect(error.message).toMatch(/not authorized/);650 else if (isWebSql && (isBrowser && (/Chrome/.test(navigator.userAgent))))651 expect(error.message).toMatch(/could not prepare statement.*23 not authorized/);652 else if (isWebSql) // [iOS (WebKit) Web SQL]653 expect(error.message).toMatch(/could not prepare statement.*1 not authorized/);654 else if (isWindows)655 expect(error.message).toMatch(/SQLite3 step error result code: 1/);656 else if (isAndroid && !isImpl2)657 expect(error.message).toMatch(/sqlite3_step failure: no such module: bogus/);658 else if (isAndroid && isImpl2)659 expect(error.message).toMatch(/no such module: bogus.*code 1/);660 else661 expect(error.message).toMatch(/no such module: bogus/);662 // FAIL transaction & check reported transaction error:663 return true;664 });665 }, function (error) {666 expect(!!sqlerror).toBe(true); // VERIFY the SQL error callback was triggered667 expect(error).toBeDefined();668 expect(error.code).toBeDefined();669 expect(error.message).toBeDefined();670 // error.hasOwnProperty('message') apparently NOT WORKING on671 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:672 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))673 expect(error.hasOwnProperty('message')).toBe(true);674 if (isWebSql || isWindows || (isAndroid && isImpl2))675 expect(error.code).toBe(0);676 else677 expect(error.code).toBe(5);678 if (isWebSql)679 expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);680 else if (isWindows)681 expect(error.message).toMatch(/error callback did not return false.*SQLite3 step error result code: 1/);682 else683 expect(error.message).toMatch(/error callback did not return false.*no such module: bogus/);684 isWebSql ? done() : db.close(done, done);685 }, function() {686 // NOT EXPECTED:687 expect(false).toBe(true);688 isWebSql ? done() : db.close(done, done);689 });690 }, MYTIMEOUT);691 // TESTS with no SQL error handler:692 it(suiteName + 'transaction.executeSql syntax error (command with misspelling) with no SQL error handler', function(done) {693 db = openDatabase('tx-sql-syntax-error-with-no-sql-error-handler-test.db');694 db.transaction(function(transaction) {695 transaction.executeSql('SLCT 1');696 }, function(error) {697 // EXPECTED RESULT:698 expect(error).toBeDefined();699 expect(error.code).toBeDefined();700 expect(error.message).toBeDefined();701 // error.hasOwnProperty('message') apparently NOT WORKING on702 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:703 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))704 expect(error.hasOwnProperty('message')).toBe(true);705 if (isWindows || (isAndroid && isImpl2))706 expect(error.code).toBe(0);707 else708 expect(error.code).toBe(5);709 if (isWebSql && !(/Android 4.[1-3]/.test(navigator.userAgent)))710 expect(error.message).toMatch(/could not prepare statement.*1 near \"SLCT\": syntax error/);711 else if (isWindows)712 expect(error.message).toMatch(/a statement with no error handler failed: Error preparing an SQLite statement/);713 else if (!isWebSql && !isWindows && isAndroid && !isImpl2)714 expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*near \"SLCT\": syntax error/);715 else if (!isWebSql && !isWindows && isAndroid && isImpl2)716 expect(error.message).toMatch(/a statement with no error handler failed: near \"SLCT\": syntax error.*code 1.*while compiling: SLCT 1/);717 else if (!isWebSql) // [iOS/macOS plugin]718 expect(error.message).toMatch(/a statement with no error handler failed.*near \"SLCT\": syntax error/);719 else720 expect(error.message).toMatch(/near \"SLCT\": syntax error/);721 isWebSql ? done() : db.close(done, done);722 }, function() {723 // NOT EXPECTED:724 expect(false).toBe(true);725 isWebSql ? done() : db.close(done, done);726 })727 }, MYTIMEOUT);728 it(suiteName + 'transaction.executeSql constraint violation with no SQL error handler', function(done) {729 var db = openDatabase("Constraint-violation-with-no-sql-error-handler.db", "1.0", "Demo", DEFAULT_SIZE);730 db.transaction(function(tx) {731 tx.executeSql('DROP TABLE IF EXISTS test_table');732 tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (data unique)');733 // First INSERT OK:734 tx.executeSql('INSERT INTO test_table (data) VALUES (?)', [123]);735 // Second INSERT will violate the unique constraint:736 tx.executeSql('INSERT INTO test_table (data) VALUES (?)', [123]);737 }, function (error) {738 expect(error).toBeDefined();739 expect(error.code).toBeDefined();740 expect(error.message).toBeDefined();741 // error.hasOwnProperty('message') apparently NOT WORKING on742 // WebKit Web SQL on Android 5.x/... or iOS 10.x/...:743 if (!isWebSql || isWindows || (isAndroid && (/Android 4/.test(navigator.userAgent))))744 expect(error.hasOwnProperty('message')).toBe(true);745 if (isWebSql && (!isAndroid || /Android 4.[1-3]/.test(navigator.userAgent)))746 expect(true).toBe(true); // SKIP for iOS (WebKit) & Android 4.1-4.3 (WebKit) Web SQL747 else if (isWindows)748 expect(error.code).toBe(0);749 else750 expect(error.code).toBe(6);751 // (WebKit) Web SQL (Android/iOS) possibly with a missing 'r'752 if (isWebSql && /Android 4.[1-3]/.test(navigator.userAgent))753 expect(error.message).toMatch(/column data is not unique/);754 else if (isWebSql && isAndroid)755 expect(error.message).toMatch(/could not execute statement due to a constr?aint failure.*19.*constraint failed/);756 else if (isWebSql)757 expect(error.message).toMatch(/constr?aint fail/);758 else if (isWindows)759 expect(error.message).toMatch(/a statement with no error handler failed: SQLite3 step error result code: 1/);760 else if (isAndroid && !isImpl2)761 expect(error.message).toMatch(/a statement with no error handler failed: sqlite3_step failure: UNIQUE constraint failed: test_table\.data/);762 else if (isAndroid && isImpl2)763 expect(error.message).toMatch(/a statement with no error handler failed:.*constraint failure/);764 else765 expect(error.message).toMatch(/a statement with no error handler failed: UNIQUE constraint failed: test_table\.data/);766 isWebSql ? done() : db.close(done, done);767 }, function() {768 // NOT EXPECTED:769 expect(false).toBe(true);770 isWebSql ? done() : db.close(done, done);771 });772 }, MYTIMEOUT);773 });774 }775}776if (window.hasBrowser) mytests();777else exports.defineAutoTests = mytests;...

Full Screen

Full Screen

default_keybindings_loader.test.js

Source:default_keybindings_loader.test.js Github

copy

Full Screen

1'use strict';2const assert = require('assert');3const defaultKeybindingsLoader = require('../../generator/default_keybindings_loader.js');4describe('default_keybindings_loader', () => {5 describe('combineBaseKeybingings', () => {6 const combineBaseKeybingings = defaultKeybindingsLoader.combineBaseKeybingings;7 it('should create a combined keybindings which consists of given set of keybindings with added context', () => {8 const input = [9 {10 keybindings: [11 { key: 'ctrl+a', command: 'command1' },12 { key: 'ctrl+b', command: 'command2', when: 'context1' }13 ],14 context: 'isWindows'15 },16 {17 keybindings: [18 { key: 'ctrl+c', command: 'command3' },19 { key: 'ctrl+d', command: 'command4', when: 'context2 || context3' }20 ],21 context: 'isLinux'22 }23 ];24 const expected = [25 { key: 'ctrl+a', command: 'command1', when: 'isWindows' },26 { key: 'ctrl+b', command: 'command2', when: 'isWindows && context1' },27 { key: 'ctrl+c', command: 'command3', when: 'isLinux' },28 { key: 'ctrl+d', command: 'command4', when: 'isLinux && context2 || isLinux && context3' }29 ];30 assert.deepStrictEqual(combineBaseKeybingings(input), expected);31 });32 it('should retain keybindings that share a common key but have different commands or when-clause', () => {33 const input = [34 {35 keybindings: [36 { key: 'ctrl+a', command: 'command1' },37 { key: 'ctrl+a', command: 'command2' },38 ],39 context: 'isWindows'40 },41 {42 keybindings: [43 { key: 'ctrl+a', command: 'command3' },44 { key: 'ctrl+a', command: 'command3', when: 'context1' }45 ],46 context: 'isLinux'47 }48 ];49 const expected = [50 { key: 'ctrl+a', command: 'command1', when: 'isWindows' },51 { key: 'ctrl+a', command: 'command2', when: 'isWindows' },52 { key: 'ctrl+a', command: 'command3', when: 'isLinux' },53 { key: 'ctrl+a', command: 'command3', when: 'isLinux && context1' }54 ];55 assert.deepStrictEqual(combineBaseKeybingings(input), expected);56 });57 it('should unify keybindings that share a common definition among all sources [compaction]', () => {58 const input = [59 {60 keybindings: [61 { key: 'ctrl+a', command: 'command1' }, // <= common62 { key: 'ctrl+a', command: 'command2' }63 ],64 context: 'isWindows'65 },66 {67 keybindings: [68 { key: 'ctrl+a', command: 'command1' }, // <= common69 { key: 'ctrl+a', command: 'command1', when: 'context1' }70 ],71 context: 'isLinux'72 }73 ];74 const expected = [75 { key: 'ctrl+a', command: 'command1' }, // <= common76 { key: 'ctrl+a', command: 'command2', when: 'isWindows' },77 { key: 'ctrl+a', command: 'command1', when: 'isLinux && context1' }78 ];79 assert.deepStrictEqual(combineBaseKeybingings(input), expected);80 });81 it('should retain the original order of keybindings in each source', () => {82 const input = [83 {84 keybindings: [85 { key: 'ctrl+a', command: 'command1', when: 'cond1' }, // <= common86 { key: 'ctrl+a', command: 'command2', when: 'cond2' } // should come after common one87 ],88 context: 'isWindows'89 },90 {91 keybindings: [92 { key: 'ctrl+a', command: 'command3', when: 'cond3' }, // should come before common one93 { key: 'ctrl+a', command: 'command1', when: 'cond1' } // <= common94 ],95 context: 'isLinux'96 }97 ];98 const expected = [99 { key: 'ctrl+a', command: 'command3', when: 'isLinux && cond3' },100 { key: 'ctrl+a', command: 'command1', when: 'cond1' }, // <= common101 { key: 'ctrl+a', command: 'command2', when: 'isWindows && cond2' }102 ];103 assert.deepStrictEqual(combineBaseKeybingings(input), expected);104 });105 it('should not unify keybindings that cause conflicts that prevent retaining the proper order', () => {106 const input = [107 {108 keybindings: [109 { key: 'ctrl+a', command: 'command1', when: 'cond1' }, // <= common I110 { key: 'ctrl+a', command: 'command2', when: 'cond2' },111 { key: 'ctrl+a', command: 'command3', when: 'cond3' } // <= common II112 ],113 context: 'isWindows'114 },115 {116 keybindings: [117 { key: 'ctrl+a', command: 'command3', when: 'cond3' }, // <= common II118 { key: 'ctrl+a', command: 'command1', when: 'cond1' } // <= common I119 ],120 context: 'isLinux'121 }122 ];123 const expected = [124 { key: 'ctrl+a', command: 'command3', when: 'isLinux && cond3' },125 { key: 'ctrl+a', command: 'command1', when: 'cond1' }, // <= common I126 { key: 'ctrl+a', command: 'command2', when: 'isWindows && cond2' },127 { key: 'ctrl+a', command: 'command3', when: 'isWindows && cond3' }128 ];129 assert.deepStrictEqual(combineBaseKeybingings(input), expected);130 });131 it('should unify keybindings that share a common definition among a subset of sources [compaction]', () => {132 const input = [133 {134 keybindings: [135 { key: 'ctrl+a', command: 'command1' }, // <= partially common136 { key: 'ctrl+a', command: 'command2' }137 ],138 context: 'isWindows'139 },140 {141 keybindings: [142 { key: 'ctrl+a', command: 'command1' }, // <= partially common143 { key: 'ctrl+a', command: 'command1', when: 'context1' }144 ],145 context: 'isLinux'146 },147 {148 keybindings: [149 { key: 'ctrl+b', command: 'command1', when: 'context1' }150 ],151 context: 'isMac'152 }153 ];154 // We use negative form of '!isMac' rather than OR form 'isWindows || isLinux'155 // for compaction of package.json.156 const expected = [157 { key: 'ctrl+a', command: 'command1', when: '!isMac' }, // <= partially common158 { key: 'ctrl+a', command: 'command2', when: 'isWindows' },159 { key: 'ctrl+a', command: 'command1', when: 'isLinux && context1' },160 { key: 'ctrl+b', command: 'command1', when: 'isMac && context1' }161 ];162 assert.deepStrictEqual(combineBaseKeybingings(input), expected);163 });164 it('should unify keybindings that share a common definition among 2nd and 3rd source [compaction]', () => {165 const input = [166 {167 keybindings: [168 { key: 'ctrl+a', command: 'command1' }169 ],170 context: 'isWindows'171 },172 {173 keybindings: [174 { key: 'ctrl+a', command: 'command2' } // <= partially common175 ],176 context: 'isLinux'177 },178 {179 keybindings: [180 { key: 'ctrl+a', command: 'command3' },181 { key: 'ctrl+a', command: 'command2' } // <= partially common182 ],183 context: 'isMac'184 }185 ];186 const expected = [187 { key: 'ctrl+a', command: 'command3', when: 'isMac' },188 { key: 'ctrl+a', command: 'command2', when: '!isWindows' }, // <= partially common189 { key: 'ctrl+a', command: 'command1', when: 'isWindows' }190 ];191 assert.deepStrictEqual(combineBaseKeybingings(input), expected);192 });193 it('should drop reduntant "isWindows" if the keystroke contains Win key [compaction]', () => {194 const input = [195 {196 keybindings: [197 { key: 'ctrl+win+a', command: 'command1', when: 'context1' }198 ],199 context: 'isWindows'200 },201 {202 keybindings: [203 { key: 'ctrl+alt+a', command: 'command2', when: 'context2' }204 ],205 context: 'isLinux'206 }207 ];208 const expected = [209 { key: 'ctrl+win+a', command: 'command1', when: 'context1' },210 { key: 'ctrl+alt+a', command: 'command2', when: 'isLinux && context2' }211 ];212 assert.deepStrictEqual(combineBaseKeybingings(input), expected);213 });214 it('should drop reduntant "isLinux" if the keystroke contains Meta key [compaction]', () => {215 const input = [216 {217 keybindings: [218 { key: 'ctrl+a', command: 'command1', when: 'context1' }219 ],220 context: 'isWindows'221 },222 {223 keybindings: [224 { key: 'meta+a', command: 'command2', when: 'context2' }225 ],226 context: 'isLinux'227 }228 ];229 const expected = [230 { key: 'ctrl+a', command: 'command1', when: 'isWindows && context1' },231 { key: 'meta+a', command: 'command2', when: 'context2' }232 ];233 assert.deepStrictEqual(combineBaseKeybingings(input), expected);234 });235 it('should drop reduntant "isMac" if the keystroke contains Command key [compaction]', () => {236 const input = [237 {238 keybindings: [239 { key: 'ctrl+a', command: 'command1', when: 'context1' }240 ],241 context: 'isWindows'242 },243 {244 keybindings: [245 { key: 'cmd+a', command: 'command2', when: 'context2' }246 ],247 context: 'isMac'248 }249 ];250 const expected = [251 { key: 'ctrl+a', command: 'command1', when: 'isWindows && context1' },252 { key: 'cmd+a', command: 'command2', when: 'context2' }253 ];254 assert.deepStrictEqual(combineBaseKeybingings(input), expected);255 });256 it('should unify keybindings that are common for Windows and Linux and also Mac except assigned "key" (using "mac" key) (1) [compaction]', () => {257 const input = [258 {259 keybindings: [260 { key: 'ctrl+a', command: 'command1', when: 'context1' }, // <= common261 { key: 'ctrl+a', command: 'command2', when: 'context2' }262 ],263 context: 'isWindows'264 },265 {266 keybindings: [267 { key: 'ctrl+a', command: 'command1', when: 'context1' }, // <= common268 { key: 'ctrl+a', command: 'command1', when: 'context3' }269 ],270 context: 'isLinux'271 },272 {273 keybindings: [274 { key: 'ctrl+b', command: 'command2' },275 { key: 'ctrl+b', command: 'command1', when: 'context1' } // <= common except 'key'276 ],277 context: 'isMac'278 }279 ];280 const expected = [281 { key: 'ctrl+b', command: 'command2', when: 'isMac' },282 { key: 'ctrl+a', command: 'command1', when: 'context1', mac: 'ctrl+b' }, // <= unified with 'mac' key283 { key: 'ctrl+a', command: 'command2', when: 'isWindows && context2' },284 { key: 'ctrl+a', command: 'command1', when: 'isLinux && context3' }285 ];286 assert.deepStrictEqual(combineBaseKeybingings(input), expected);287 });288 it('should unify keybindings using "mac" key (2) [compaction]', () => {289 const input = [290 {291 keybindings: [292 { key: 'ctrl+a', command: 'command1', when: 'context1' }, // <= common A293 { key: 'ctrl+a', command: 'command2', when: 'context2' },294 { key: 'ctrl+c', command: 'command3', when: 'context4' } // <= common B295 ],296 context: 'isWindows'297 },298 {299 keybindings: [300 { key: 'ctrl+a', command: 'command1', when: 'context1' }, // <= common A301 { key: 'ctrl+a', command: 'command1', when: 'context3' },302 { key: 'ctrl+c', command: 'command3', when: 'context4' } // <= common B303 ],304 context: 'isLinux'305 },306 {307 keybindings: [308 { key: 'ctrl+b', command: 'command2' },309 { key: 'ctrl+b', command: 'command1', when: 'context1' }, // <= common A except 'key'310 { key: 'ctrl+b', command: 'command3', when: 'context4' } // <= common B except 'key'311 ],312 context: 'isMac'313 }314 ];315 const expected = [316 { key: 'ctrl+b', command: 'command2', when: 'isMac' },317 { key: 'ctrl+a', command: 'command1', when: 'context1', mac: 'ctrl+b' }, // <= A318 { key: 'ctrl+c', command: 'command3', when: 'context4', mac: 'ctrl+b' }, // <= B319 { key: 'ctrl+a', command: 'command2', when: 'isWindows && context2' },320 { key: 'ctrl+a', command: 'command1', when: 'isLinux && context3' }321 ];322 assert.deepStrictEqual(combineBaseKeybingings(input), expected);323 });324 it('should unify keybindings using "mac" key (3) (special case that a same command applies to multiple keys) [compaction]', () => {325 const input = [326 {327 keybindings: [328 { key: 'ctrl+a', command: 'command1' }, // <= common A329 { key: 'ctrl+a', command: 'command2', when: 'context2' },330 { key: 'ctrl+c', command: 'command1' } // <= common B331 ],332 context: 'isWindows'333 },334 {335 keybindings: [336 { key: 'ctrl+a', command: 'command1' }, // <= common A337 { key: 'ctrl+a', command: 'command1', when: 'context3' },338 { key: 'ctrl+c', command: 'command1' } // <= common B339 ],340 context: 'isLinux'341 },342 {343 keybindings: [344 { key: 'ctrl+b', command: 'command2' },345 { key: 'ctrl+b', command: 'command1' }, // <= common A except 'key'346 { key: 'ctrl+d', command: 'command1' } // <= common B except 'key'347 ],348 context: 'isMac'349 }350 ];351 const expected = [352 { key: 'ctrl+b', command: 'command2', when: 'isMac' },353 { key: 'ctrl+a', command: 'command1', mac: 'ctrl+b' }, // <= A354 { key: 'ctrl+c', command: 'command1', mac: 'ctrl+d' }, // <= B355 { key: 'ctrl+a', command: 'command2', when: 'isWindows && context2' },356 { key: 'ctrl+a', command: 'command1', when: 'isLinux && context3' }357 ];358 assert.deepStrictEqual(combineBaseKeybingings(input), expected);359 });360 it('should unify keybindings using "mac" key (4) [compaction]', () => {361 const input = [362 {363 keybindings: [364 { key: 'ctrl+delete', command: 'command1', when: 'context1' },365 { key: 'alt+delete', command: 'command3', when: 'context3' }366 ],367 context: 'isWindows'368 },369 {370 keybindings: [371 { key: 'ctrl+delete', command: 'command1', when: 'context1' },372 { key: 'alt+delete', command: 'command3', when: 'context3' }373 ],374 context: 'isLinux'375 },376 {377 keybindings: [378 { key: 'alt+delete', command: 'command2', when: 'context2' },379 { key: 'alt+delete', command: 'command3', when: 'context3' },380 { key: 'alt+delete', command: 'command1', when: 'context1' }381 ],382 context: 'isMac'383 }384 ];385 const expected = [386 { key: 'ctrl+delete', command: 'command1', when: '!isMac && context1' },387 { key: 'alt+delete', command: 'command2', when: 'isMac && context2' },388 { key: 'alt+delete', command: 'command3', when: 'context3' },389 { key: 'alt+delete', command: 'command1', when: 'isMac && context1' }390 ];391 assert.deepStrictEqual(combineBaseKeybingings(input), expected);392 });393 });...

Full Screen

Full Screen

color.service.ts

Source:color.service.ts Github

copy

Full Screen

1export default class ColorService {2 isWindows = process.platform === 'win32'3 get green(): string {4 return '\x1B[32m'5 }6 get red(): string {7 return '\x1B[31m'8 }9 get yellow(): string {10 return '\x1b[33m'11 }12 get purple(): string {13 return '\x1b[95m'14 }15 get reset(): string {16 return '\x1B[0m'17 }18 get bold(): string {19 return '\x1b[1m'20 }21 get dim(): string {22 return '\x1b[2m'23 }24 get tick(): string {25 return this.isWindows ? '\u221A' : '✓'26 }27 get cross(): string {28 return this.isWindows ? '\u00D7' : '✘'29 }30 get whiteSmallSquare(): string {31 return this.isWindows ? '\u0387' : '▫'32 }33 get heavyHorizontal(): string {34 return this.isWindows ? '\u2500' : '━'35 }36 get heavyVertical(): string {37 return this.isWindows ? '\u2502' : '┃'38 }39 get heavyUpAndRight(): string {40 return this.isWindows ? '\u2514' : '└'41 }42 get heavyUpAndLeft(): string {43 return this.isWindows ? '\u2518' : '┘'44 }45 get heavyDownAndRight(): string {46 return this.isWindows ? '\u250c' : '┌'47 }48 get heavyDownAndLeft(): string {49 return this.isWindows ? '\u2510' : '┐'50 }51 get heavyVerticalAndRight(): string {52 return this.isWindows ? '\u251C' : '┣'53 }54 get heavyDownAndHorizontal(): string {55 return this.isWindows ? '\u252C' : '┳'56 }57 get doubleLightHorizontal(): string {58 return '──'59 }60 get space(): string {61 return '\u0020'62 }63 get break(): string {64 return this.isWindows ? '\r\n' : '\n'65 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { isWindows } from 'ng-mocks';2import { isPlatformBrowser } from 'ng-mocks';3import { isPlatformServer } from 'ng-mocks';4import { isPlatformWorkerApp } from 'ng-mocks';5import { isPlatformWorkerUi } from 'ng-mocks';6import { isPlatformIos } from 'ng-mocks';7import { isPlatformAndroid } from 'ng-mocks';8import { isPlatformBrowser } from 'ng-mocks';9import { isPlatformServer } from 'ng-mocks';10import { isPlatformWorkerApp } from 'ng-mocks';11import { isPlatformWorkerUi } from 'ng-mocks';12import { isPlatformIos } from 'ng-mocks';13import { isPlatformAndroid } from 'ng-mocks';14import { isPlatformBrowser } from 'ng-mocks';15import { isPlatformServer } from 'ng-mocks';16import { isPlatformWorkerApp } from 'ng-mocks';17import { isPlatformWorkerUi } from 'ng-mocks';18import { isPlatformIos } from 'ng-mocks';19import { isPlatformAndroid } from 'ng-mocks';20import { isPlatformBrowser } from

Full Screen

Using AI Code Generation

copy

Full Screen

1var isWindows = ngMocks.isWindows();2var isString = ngMocks.isString();3var isNumber = ngMocks.isNumber();4var isObject = ngMocks.isObject();5var isFunction = ngMocks.isFunction();6var isDate = ngMocks.isDate();7var isRegExp = ngMocks.isRegExp();8var isArray = ngMocks.isArray();9var isDefined = ngMocks.isDefined();10var isUndefined = ngMocks.isUndefined();11var isElement = ngMocks.isElement();12var isString = ngMocks.isString();13var isNumber = ngMocks.isNumber();14var isObject = ngMocks.isObject();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { isWindows } from 'ng-mocks';2describe('isWindows', () => {3 it('should work', () => {4 expect(isWindows()).toBe(false);5 });6});7import { isWindowsPhone } from 'ng-mocks';8describe('isWindowsPhone', () => {9 it('should work', () => {10 expect(isWindowsPhone()).toBe(false);11 });12});13import { isWindowsTablet } from 'ng-mocks';14describe('isWindowsTablet', () => {15 it('should work', () => {16 expect(isWindowsTablet()).toBe(false);17 });18});19import { isWindowsVersion } from 'ng-mocks';20describe('isWindowsVersion', () => {21 it('should work', () => {22 expect(isWindowsVersion()).toBe(false);23 });24});25import { isXbox } from 'ng-mocks';26describe('isXbox', () => {27 it('should work', () => {28 expect(isXbox()).toBe(false);29 });30});31import { isXboxOne } from 'ng-mocks';32describe('isXboxOne', () => {33 it('should work', () => {34 expect(isXboxOne()).toBe(false);35 });36});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { isWindows } from 'ng-mocks';2describe('isWindows', () => {3 it('should return true if the platform is Windows', () => {4 expect(isWindows()).toBe(true);5 });6});7import { ngMocks } from 'ng-mocks';8describe('ngMocks', () => {9 it('should return the mock of a component', () => {10 expect(ngMocks.formatText('foo')).toEqual('foo');11 });12});13import { ngMocksUniverse } from 'ng-mocks';14describe('ngMocksUniverse', () => {15 it('should return the mock of a component', () => {16 expect(ngMocksUniverse.isMockOf('foo', 'foo')).toBe(true);17 });18});19import { ngMocksFormatText } from 'ng-mocks';20describe('ngMocksFormatText', () => {21 it('should return the mock of a component', () => {22 expect(ngMocksFormatText('foo')).toEqual('foo');23 });24});25import { ngMocksGuts } from 'ng-mocks';26describe('ngMocksGuts', () => {27 it('should return the mock of a component', () => {28 expect(ngMocksGuts.getInternalComponent('foo')).toEqual('foo');29 });30});31import { ngMocksDefaultMock } from 'ng-mocks';32describe('ngMocksDefaultMock', () => {33 it('should return the mock of a component', () => {34 expect(ngMocksDefaultMock('foo', 'foo')).toEqual('foo');35 });36});37import { ngMocksFind } from 'ng-mocks';38describe('ngMocksFind', () => {39 it('should return

Full Screen

Using AI Code Generation

copy

Full Screen

1import { isWindows } from 'ng-mocks';2describe('isWindows', () => {3 it('returns true if the navigator is windows', () => {4 expect(isWindows()).toBe(true);5 });6});7import { isMacOS } from 'ng-mocks';8describe('isMacOS', () => {9 it('returns true if the navigator is macos', () => {10 expect(isMacOS()).toBe(true);11 });12});13import { isLinux } from 'ng-mocks';14describe('isLinux', () => {15 it('returns true if the navigator is linux', () => {16 expect(isLinux()).toBe(true);17 });18});19import { isAndroid } from 'ng-mocks';20describe('isAndroid', () => {21 it('returns true if the navigator is android', () => {22 expect(isAndroid()).toBe(true);23 });24});25import { isIOS } from 'ng-mocks';26describe('isIOS', () => {27 it('returns true if the navigator is ios', () => {28 expect(isIOS()).toBe(true);29 });30});31import { isMobile } from 'ng-mocks';32describe('isMobile', () => {33 it('returns true if the navigator is mobile', () => {34 expect(isMobile()).toBe(true);35 });36});37import { isDesktop } from 'ng-mocks';38describe('isDesktop', () => {39 it('returns true if the navigator is desktop', () => {40 expect(isDesktop()).toBe(true);41 });42});43import { isTablet } from 'ng-mocks';44describe('isTablet', () => {45 it('returns true if the navigator is tablet', () => {46 expect(isTablet()).toBe(true);47 });48});49import { isTouch } from 'ng-mocks';50describe('isTouch', () => {51 it('returns true if the navigator is touch', () => {52 expect(isTouch()).toBe(true);

Full Screen

Using AI Code Generation

copy

Full Screen

1const isWindows = require('ng-mocks').isWindows;2if (isWindows()) {3 console.log('This is Windows');4} else {5 console.log('This is not Windows');6}7const isMacOS = require('ng-mocks').isMacOS;8if (isMacOS()) {9 console.log('This is MacOS');10} else {11 console.log('This is not MacOS');12}13const isLinux = require('ng-mocks').isLinux;14if (isLinux()) {15 console.log('This is Linux');16} else {17 console.log('This is not Linux');18}19const isBrowser = require('ng-mocks').isBrowser;20if (isBrowser()) {21 console.log('This is a browser');22} else {23 console.log('This is not a browser');24}25const isNode = require('ng-mocks').isNode;26if (isNode()) {27 console.log('This is Node');28} else {29 console.log('This is not Node');30}31const isJsDom = require('ng-mocks').isJsDom;32if (isJsDom()) {33 console.log('This is JSDOM');34} else {35 console.log('This is not JSDOM');36}37const isTestBedRendered = require('ng-mocks').isTestBedRendered;38if (isTestBedRendered()) {39 console.log('TestBed has been rendered');40} else {41 console.log('TestBed has not been rendered');42}

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('isWindows', () => {2 it('should return true if window is defined', () => {3 const isWindows = require('ng-mocks').isWindows;4 expect(isWindows()).toBeTruthy();5 });6});

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