How to use ensure method in storybook-root

Best JavaScript code snippet using storybook-root

test_async_transactions.js

Source:test_async_transactions.js Github

copy

Full Screen

1/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */2/* vim:set ts=2 sw=2 sts=2 et: */3/* This Source Code Form is subject to the terms of the Mozilla Public4 * License, v. 2.0. If a copy of the MPL was not distributed with this5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */6const bmsvc = PlacesUtils.bookmarks;7const tagssvc = PlacesUtils.tagging;8const annosvc = PlacesUtils.annotations;9const PT = PlacesTransactions;10const rootGuid = PlacesUtils.bookmarks.rootGuid;11const menuGuid = PlacesUtils.bookmarks.menuGuid;12Components.utils.importGlobalProperties(["URL"]);13// Create and add bookmarks observer.14var observer = {15 __proto__: NavBookmarkObserver.prototype,16 tagRelatedGuids: new Set(),17 reset() {18 this.itemsAdded = new Map();19 this.itemsRemoved = new Map();20 this.itemsChanged = new Map();21 this.itemsMoved = new Map();22 this.beginUpdateBatch = false;23 this.endUpdateBatch = false;24 },25 onBeginUpdateBatch() {26 this.beginUpdateBatch = true;27 },28 onEndUpdateBatch() {29 this.endUpdateBatch = true;30 },31 onItemAdded(aItemId, aParentId, aIndex, aItemType, aURI, aTitle, aDateAdded,32 aGuid, aParentGuid) {33 // Ignore tag items.34 if (aParentId == PlacesUtils.tagsFolderId ||35 (aParentId != PlacesUtils.placesRootId &&36 bmsvc.getFolderIdForItem(aParentId) == PlacesUtils.tagsFolderId)) {37 this.tagRelatedGuids.add(aGuid);38 return;39 }40 this.itemsAdded.set(aGuid, { itemId: aItemId,41 parentGuid: aParentGuid,42 index: aIndex,43 itemType: aItemType,44 title: aTitle,45 url: aURI });46 },47 onItemRemoved(aItemId, aParentId, aIndex, aItemType, aURI, aGuid, aParentGuid) {48 if (this.tagRelatedGuids.has(aGuid))49 return;50 this.itemsRemoved.set(aGuid, { parentGuid: aParentGuid,51 index: aIndex,52 itemType: aItemType });53 },54 onItemChanged(aItemId, aProperty, aIsAnnoProperty, aNewValue, aLastModified,55 aItemType, aParentId, aGuid, aParentGuid) {56 if (this.tagRelatedGuids.has(aGuid))57 return;58 let changesForGuid = this.itemsChanged.get(aGuid);59 if (changesForGuid === undefined) {60 changesForGuid = new Map();61 this.itemsChanged.set(aGuid, changesForGuid);62 }63 let newValue = aNewValue;64 if (aIsAnnoProperty) {65 if (annosvc.itemHasAnnotation(aItemId, aProperty))66 newValue = annosvc.getItemAnnotation(aItemId, aProperty);67 else68 newValue = null;69 }70 let change = { isAnnoProperty: aIsAnnoProperty,71 newValue,72 lastModified: aLastModified,73 itemType: aItemType };74 changesForGuid.set(aProperty, change);75 },76 onItemVisited: () => {},77 onItemMoved(aItemId, aOldParent, aOldIndex, aNewParent, aNewIndex, aItemType,78 aGuid, aOldParentGuid, aNewParentGuid) {79 this.itemsMoved.set(aGuid, { oldParentGuid: aOldParentGuid,80 oldIndex: aOldIndex,81 newParentGuid: aNewParentGuid,82 newIndex: aNewIndex,83 itemType: aItemType });84 }85};86observer.reset();87// index at which items should begin88var bmStartIndex = 0;89function run_test() {90 bmsvc.addObserver(observer);91 do_register_cleanup(function() {92 bmsvc.removeObserver(observer);93 });94 run_next_test();95}96function sanityCheckTransactionHistory() {97 do_check_true(PT.undoPosition <= PT.length);98 let check_entry_throws = f => {99 try {100 f();101 do_throw("PT.entry should throw for invalid input");102 } catch (ex) {}103 };104 check_entry_throws( () => PT.entry(-1) );105 check_entry_throws( () => PT.entry({}) );106 check_entry_throws( () => PT.entry(PT.length) );107 if (PT.undoPosition < PT.length)108 do_check_eq(PT.topUndoEntry, PT.entry(PT.undoPosition));109 else110 do_check_null(PT.topUndoEntry);111 if (PT.undoPosition > 0)112 do_check_eq(PT.topRedoEntry, PT.entry(PT.undoPosition - 1));113 else114 do_check_null(PT.topRedoEntry);115}116function getTransactionsHistoryState() {117 let history = [];118 for (let i = 0; i < PT.length; i++) {119 history.push(PT.entry(i));120 }121 return [history, PT.undoPosition];122}123function ensureUndoState(aExpectedEntries = [], aExpectedUndoPosition = 0) {124 // ensureUndoState is called in various places during this test, so it's125 // a good places to sanity-check the transaction-history APIs in all126 // cases.127 sanityCheckTransactionHistory();128 let [actualEntries, actualUndoPosition] = getTransactionsHistoryState();129 do_check_eq(actualEntries.length, aExpectedEntries.length);130 do_check_eq(actualUndoPosition, aExpectedUndoPosition);131 function checkEqualEntries(aExpectedEntry, aActualEntry) {132 do_check_eq(aExpectedEntry.length, aActualEntry.length);133 aExpectedEntry.forEach( (t, i) => do_check_eq(t, aActualEntry[i]) );134 }135 aExpectedEntries.forEach( (e, i) => checkEqualEntries(e, actualEntries[i]) );136}137function ensureItemsAdded(...items) {138 let expectedResultsCount = items.length;139 for (let item of items) {140 if ("children" in item) {141 expectedResultsCount += item.children.length;142 }143 Assert.ok(observer.itemsAdded.has(item.guid),144 `Should have the expected guid ${item.guid}`);145 let info = observer.itemsAdded.get(item.guid);146 Assert.equal(info.parentGuid, item.parentGuid,147 "Should have notified the correct parentGuid");148 for (let propName of ["title", "index", "itemType"]) {149 if (propName in item)150 Assert.equal(info[propName], item[propName]);151 }152 if ("url" in item)153 Assert.ok(info.url.equals(item.url));154 }155 Assert.equal(observer.itemsAdded.size, expectedResultsCount,156 "Should have added the correct number of items");157}158function ensureItemsRemoved(...items) {159 let expectedResultsCount = items.length;160 for (let item of items) {161 // We accept both guids and full info object here.162 if (typeof(item) == "string") {163 Assert.ok(observer.itemsRemoved.has(item),164 `Should have removed the expected guid ${item}`);165 } else {166 if ("children" in item) {167 expectedResultsCount += item.children.length;168 }169 Assert.ok(observer.itemsRemoved.has(item.guid),170 `Should have removed expected guid ${item.guid}`);171 let info = observer.itemsRemoved.get(item.guid);172 Assert.equal(info.parentGuid, item.parentGuid,173 "Should have notified the correct parentGuid");174 if ("index" in item)175 Assert.equal(info.index, item.index);176 }177 }178 Assert.equal(observer.itemsRemoved.size, expectedResultsCount,179 "Should have removed the correct number of items");180}181function ensureItemsChanged(...items) {182 for (let item of items) {183 do_check_true(observer.itemsChanged.has(item.guid));184 let changes = observer.itemsChanged.get(item.guid);185 do_check_true(changes.has(item.property));186 let info = changes.get(item.property);187 if (!("isAnnoProperty" in item)) {188 do_check_false(info.isAnnoProperty);189 } else {190 do_check_eq(info.isAnnoProperty, Boolean(item.isAnnoProperty));191 }192 do_check_eq(info.newValue, item.newValue);193 if ("url" in item)194 do_check_true(item.url.equals(info.url));195 }196}197function ensureAnnotationsSet(aGuid, aAnnos) {198 do_check_true(observer.itemsChanged.has(aGuid));199 let changes = observer.itemsChanged.get(aGuid);200 for (let anno of aAnnos) {201 do_check_true(changes.has(anno.name));202 let changeInfo = changes.get(anno.name);203 do_check_true(changeInfo.isAnnoProperty);204 do_check_eq(changeInfo.newValue, anno.value);205 }206}207function ensureItemsMoved(...items) {208 do_check_true(observer.itemsMoved.size, items.length);209 for (let item of items) {210 do_check_true(observer.itemsMoved.has(item.guid));211 let info = observer.itemsMoved.get(item.guid);212 do_check_eq(info.oldParentGuid, item.oldParentGuid);213 do_check_eq(info.oldIndex, item.oldIndex);214 do_check_eq(info.newParentGuid, item.newParentGuid);215 do_check_eq(info.newIndex, item.newIndex);216 }217}218function ensureTimestampsUpdated(aGuid, aCheckDateAdded = false) {219 do_check_true(observer.itemsChanged.has(aGuid));220 let changes = observer.itemsChanged.get(aGuid);221 if (aCheckDateAdded)222 do_check_true(changes.has("dateAdded"))223 do_check_true(changes.has("lastModified"));224}225function ensureTagsForURI(aURI, aTags) {226 let tagsSet = tagssvc.getTagsForURI(aURI);227 do_check_eq(tagsSet.length, aTags.length);228 do_check_true(aTags.every( t => tagsSet.includes(t)));229}230function createTestFolderInfo(title = "Test Folder", parentGuid = menuGuid,231 children = undefined) {232 let info = { parentGuid, title };233 if (children) {234 info.children = children;235 }236 return info;237}238function isLivemarkTree(aTree) {239 return !!aTree.annos &&240 aTree.annos.some( a => a.name == PlacesUtils.LMANNO_FEEDURI );241}242async function ensureLivemarkCreatedByAddLivemark(aLivemarkGuid) {243 // This throws otherwise.244 await PlacesUtils.livemarks.getLivemark({ guid: aLivemarkGuid });245}246function removeAllDatesInTree(tree) {247 if ("lastModified" in tree) {248 delete tree.lastModified;249 }250 if ("dateAdded" in tree) {251 delete tree.dateAdded;252 }253 if (!tree.children) {254 return;255 }256 for (let child of tree.children) {257 removeAllDatesInTree(child);258 }259}260// Checks if two bookmark trees (as returned by promiseBookmarksTree) are the261// same.262// false value for aCheckParentAndPosition is ignored if aIsRestoredItem is set.263async function ensureEqualBookmarksTrees(aOriginal,264 aNew,265 aIsRestoredItem = true,266 aCheckParentAndPosition = false,267 aIgnoreAllDates = false) {268 // Note "id" is not-enumerable, and is therefore skipped by Object.keys (both269 // ours and the one at deepEqual). This is fine for us because ids are not270 // restored by Redo.271 if (aIsRestoredItem) {272 if (aIgnoreAllDates) {273 removeAllDatesInTree(aOriginal);274 removeAllDatesInTree(aNew);275 } else if (!aOriginal.lastModified) {276 // Ignore lastModified for newly created items, for performance reasons.277 aNew.lastModified = aOriginal.lastModified;278 }279 Assert.deepEqual(aOriginal, aNew);280 if (isLivemarkTree(aNew))281 await ensureLivemarkCreatedByAddLivemark(aNew.guid);282 return;283 }284 for (let property of Object.keys(aOriginal)) {285 if (property == "children") {286 Assert.equal(aOriginal.children.length, aNew.children.length);287 for (let i = 0; i < aOriginal.children.length; i++) {288 await ensureEqualBookmarksTrees(aOriginal.children[i],289 aNew.children[i],290 false,291 true);292 }293 } else if (property == "guid") {294 // guid shouldn't be copied if the item was not restored.295 Assert.notEqual(aOriginal.guid, aNew.guid);296 } else if (property == "dateAdded") {297 // dateAdded shouldn't be copied if the item was not restored.298 Assert.ok(is_time_ordered(aOriginal.dateAdded, aNew.dateAdded));299 } else if (property == "lastModified") {300 // same same, except for the never-changed case301 if (!aOriginal.lastModified)302 Assert.ok(!aNew.lastModified);303 else304 Assert.ok(is_time_ordered(aOriginal.lastModified, aNew.lastModified));305 } else if (aCheckParentAndPosition ||306 (property != "parentGuid" && property != "index")) {307 Assert.deepEqual(aOriginal[property], aNew[property]);308 }309 }310 if (isLivemarkTree(aNew))311 await ensureLivemarkCreatedByAddLivemark(aNew.guid);312}313async function ensureBookmarksTreeRestoredCorrectly(...aOriginalBookmarksTrees) {314 for (let originalTree of aOriginalBookmarksTrees) {315 let restoredTree =316 await PlacesUtils.promiseBookmarksTree(originalTree.guid);317 await ensureEqualBookmarksTrees(originalTree, restoredTree);318 }319}320async function ensureBookmarksTreeRestoredCorrectlyExceptDates(...aOriginalBookmarksTrees) {321 for (let originalTree of aOriginalBookmarksTrees) {322 let restoredTree =323 await PlacesUtils.promiseBookmarksTree(originalTree.guid);324 await ensureEqualBookmarksTrees(originalTree, restoredTree, true, false, true);325 }326}327async function ensureNonExistent(...aGuids) {328 for (let guid of aGuids) {329 Assert.strictEqual((await PlacesUtils.promiseBookmarksTree(guid)), null);330 }331}332add_task(async function test_recycled_transactions() {333 async function ensureTransactThrowsFor(aTransaction) {334 let [txns, undoPosition] = getTransactionsHistoryState();335 try {336 await aTransaction.transact();337 do_throw("Shouldn't be able to use the same transaction twice");338 } catch (ex) { }339 ensureUndoState(txns, undoPosition);340 }341 let txn_a = PT.NewFolder(createTestFolderInfo());342 await txn_a.transact();343 ensureUndoState([[txn_a]], 0);344 await ensureTransactThrowsFor(txn_a);345 await PT.undo();346 ensureUndoState([[txn_a]], 1);347 ensureTransactThrowsFor(txn_a);348 await PT.clearTransactionsHistory();349 ensureUndoState();350 ensureTransactThrowsFor(txn_a);351 let txn_b = PT.NewFolder(createTestFolderInfo());352 await PT.batch(async function() {353 try {354 await txn_a.transact();355 do_throw("Shouldn't be able to use the same transaction twice");356 } catch (ex) { }357 ensureUndoState();358 await txn_b.transact();359 });360 ensureUndoState([[txn_b]], 0);361 await PT.undo();362 ensureUndoState([[txn_b]], 1);363 ensureTransactThrowsFor(txn_a);364 ensureTransactThrowsFor(txn_b);365 await PT.clearTransactionsHistory();366 ensureUndoState();367 observer.reset();368});369add_task(async function test_new_folder_with_annotation() {370 const ANNO = { name: "TestAnno", value: "TestValue" };371 let folder_info = createTestFolderInfo();372 folder_info.index = bmStartIndex;373 folder_info.annotations = [ANNO];374 ensureUndoState();375 let txn = PT.NewFolder(folder_info);376 folder_info.guid = await txn.transact();377 let originalInfo = await PlacesUtils.promiseBookmarksTree(folder_info.guid);378 let ensureDo = async function(aRedo = false) {379 ensureUndoState([[txn]], 0);380 await ensureItemsAdded(folder_info);381 ensureAnnotationsSet(folder_info.guid, [ANNO]);382 if (aRedo) {383 // Ignore lastModified in the comparison, for performance reasons.384 originalInfo.lastModified = null;385 await ensureBookmarksTreeRestoredCorrectlyExceptDates(originalInfo);386 }387 observer.reset();388 };389 let ensureUndo = () => {390 ensureUndoState([[txn]], 1);391 ensureItemsRemoved({ guid: folder_info.guid,392 parentGuid: folder_info.parentGuid,393 index: bmStartIndex });394 observer.reset();395 };396 await ensureDo();397 await PT.undo();398 await ensureUndo();399 await PT.redo();400 await ensureDo(true);401 await PT.undo();402 ensureUndo();403 await PT.clearTransactionsHistory();404 ensureUndoState();405});406add_task(async function test_new_folder_with_children() {407 let folder_info = createTestFolderInfo("Test folder", PlacesUtils.bookmarks.menuGuid, [{408 url: "http://test_create_item.com",409 title: "Test creating an item"410 }]);411 ensureUndoState();412 let txn = PT.NewFolder(folder_info);413 folder_info.guid = await txn.transact();414 let originalInfo = await PlacesUtils.promiseBookmarksTree(folder_info.guid);415 let ensureDo = async function(aRedo = false) {416 ensureUndoState([[txn]], 0);417 ensureItemsAdded(folder_info);418 if (aRedo) {419 // Ignore lastModified in the comparison, for performance reasons.420 originalInfo.lastModified = null;421 await ensureBookmarksTreeRestoredCorrectlyExceptDates(originalInfo);422 }423 observer.reset();424 };425 let ensureUndo = () => {426 ensureUndoState([[txn]], 1);427 ensureItemsRemoved({428 guid: folder_info.guid,429 parentGuid: folder_info.parentGuid,430 index: bmStartIndex,431 children: [{432 title: "Test creating an item",433 url: "http://test_create_item.com",434 }]435 });436 observer.reset();437 };438 await ensureDo();439 await PT.undo();440 await ensureUndo();441 await PT.redo();442 await ensureDo(true);443 await PT.undo();444 ensureUndo();445 await PT.clearTransactionsHistory();446 ensureUndoState();447});448add_task(async function test_new_bookmark() {449 let bm_info = { parentGuid: rootGuid,450 url: NetUtil.newURI("http://test_create_item.com"),451 index: bmStartIndex,452 title: "Test creating an item" };453 ensureUndoState();454 let txn = PT.NewBookmark(bm_info);455 bm_info.guid = await txn.transact();456 let originalInfo = await PlacesUtils.promiseBookmarksTree(bm_info.guid);457 let ensureDo = async function(aRedo = false) {458 ensureUndoState([[txn]], 0);459 await ensureItemsAdded(bm_info);460 if (aRedo)461 await ensureBookmarksTreeRestoredCorrectly(originalInfo);462 observer.reset();463 };464 let ensureUndo = () => {465 ensureUndoState([[txn]], 1);466 ensureItemsRemoved({ guid: bm_info.guid,467 parentGuid: bm_info.parentGuid,468 index: bmStartIndex });469 observer.reset();470 };471 await ensureDo();472 await PT.undo();473 ensureUndo();474 await PT.redo(true);475 await ensureDo();476 await PT.undo();477 ensureUndo();478 await PT.clearTransactionsHistory();479 ensureUndoState();480});481add_task(async function test_merge_create_folder_and_item() {482 let folder_info = createTestFolderInfo();483 let bm_info = { url: NetUtil.newURI("http://test_create_item_to_folder.com"),484 title: "Test Bookmark",485 index: bmStartIndex };486 let [folderTxnResult, bkmTxnResult] = await PT.batch(async function() {487 let folderTxn = PT.NewFolder(folder_info);488 folder_info.guid = bm_info.parentGuid = await folderTxn.transact();489 let bkmTxn = PT.NewBookmark(bm_info);490 bm_info.guid = await bkmTxn.transact();491 return [folderTxn, bkmTxn];492 });493 let ensureDo = async function() {494 ensureUndoState([[bkmTxnResult, folderTxnResult]], 0);495 await ensureItemsAdded(folder_info, bm_info);496 observer.reset();497 };498 let ensureUndo = () => {499 ensureUndoState([[bkmTxnResult, folderTxnResult]], 1);500 ensureItemsRemoved(folder_info, bm_info);501 observer.reset();502 };503 await ensureDo();504 await PT.undo();505 ensureUndo();506 await PT.redo();507 await ensureDo();508 await PT.undo();509 ensureUndo();510 await PT.clearTransactionsHistory();511 ensureUndoState();512});513add_task(async function test_move_items_to_folder() {514 let folder_a_info = createTestFolderInfo("Folder A");515 let bkm_a_info = { url: new URL("http://test_move_items.com"),516 title: "Bookmark A" };517 let bkm_b_info = { url: NetUtil.newURI("http://test_move_items.com"),518 title: "Bookmark B" };519 // Test moving items within the same folder.520 let [folder_a_txn_result, bkm_a_txn_result, bkm_b_txn_result] = await PT.batch(async function() {521 let folder_a_txn = PT.NewFolder(folder_a_info);522 folder_a_info.guid = bkm_a_info.parentGuid = bkm_b_info.parentGuid =523 await folder_a_txn.transact();524 let bkm_a_txn = PT.NewBookmark(bkm_a_info);525 bkm_a_info.guid = await bkm_a_txn.transact();526 let bkm_b_txn = PT.NewBookmark(bkm_b_info);527 bkm_b_info.guid = await bkm_b_txn.transact();528 return [folder_a_txn, bkm_a_txn, bkm_b_txn];529 });530 ensureUndoState([[bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result]], 0);531 let moveTxn = PT.Move({ guid: bkm_a_info.guid,532 newParentGuid: folder_a_info.guid });533 await moveTxn.transact();534 let ensureDo = () => {535 ensureUndoState([[moveTxn], [bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result]], 0);536 ensureItemsMoved({ guid: bkm_a_info.guid,537 oldParentGuid: folder_a_info.guid,538 newParentGuid: folder_a_info.guid,539 oldIndex: 0,540 newIndex: 1 });541 observer.reset();542 };543 let ensureUndo = () => {544 ensureUndoState([[moveTxn], [bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result]], 1);545 ensureItemsMoved({ guid: bkm_a_info.guid,546 oldParentGuid: folder_a_info.guid,547 newParentGuid: folder_a_info.guid,548 oldIndex: 1,549 newIndex: 0 });550 observer.reset();551 };552 ensureDo();553 await PT.undo();554 ensureUndo();555 await PT.redo();556 ensureDo();557 await PT.undo();558 ensureUndo();559 await PT.clearTransactionsHistory(false, true);560 ensureUndoState([[bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result]], 0);561 // Test moving items between folders.562 let folder_b_info = createTestFolderInfo("Folder B");563 let folder_b_txn = PT.NewFolder(folder_b_info);564 folder_b_info.guid = await folder_b_txn.transact();565 ensureUndoState([ [folder_b_txn],566 [bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result] ], 0);567 moveTxn = PT.Move({ guid: bkm_a_info.guid,568 newParentGuid: folder_b_info.guid,569 newIndex: bmsvc.DEFAULT_INDEX });570 await moveTxn.transact();571 ensureDo = () => {572 ensureUndoState([ [moveTxn],573 [folder_b_txn],574 [bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result] ], 0);575 ensureItemsMoved({ guid: bkm_a_info.guid,576 oldParentGuid: folder_a_info.guid,577 newParentGuid: folder_b_info.guid,578 oldIndex: 0,579 newIndex: 0 });580 observer.reset();581 };582 ensureUndo = () => {583 ensureUndoState([ [moveTxn],584 [folder_b_txn],585 [bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result] ], 1);586 ensureItemsMoved({ guid: bkm_a_info.guid,587 oldParentGuid: folder_b_info.guid,588 newParentGuid: folder_a_info.guid,589 oldIndex: 0,590 newIndex: 0 });591 observer.reset();592 };593 ensureDo();594 await PT.undo();595 ensureUndo();596 await PT.redo();597 ensureDo();598 await PT.undo();599 ensureUndo();600 // Clean up601 await PT.undo(); // folder_b_txn602 await PT.undo(); // folder_a_txn + the bookmarks;603 do_check_eq(observer.itemsRemoved.size, 4);604 ensureUndoState([ [moveTxn],605 [folder_b_txn],606 [bkm_b_txn_result, bkm_a_txn_result, folder_a_txn_result] ], 3);607 await PT.clearTransactionsHistory();608 ensureUndoState();609});610add_task(async function test_remove_folder() {611 let folder_level_1_info = createTestFolderInfo("Folder Level 1");612 let folder_level_2_info = { title: "Folder Level 2" };613 let [folder_level_1_txn_result,614 folder_level_2_txn_result] = await PT.batch(async function() {615 let folder_level_1_txn = PT.NewFolder(folder_level_1_info);616 folder_level_1_info.guid = await folder_level_1_txn.transact();617 folder_level_2_info.parentGuid = folder_level_1_info.guid;618 let folder_level_2_txn = PT.NewFolder(folder_level_2_info);619 folder_level_2_info.guid = await folder_level_2_txn.transact();620 return [folder_level_1_txn, folder_level_2_txn];621 });622 let original_folder_level_1_tree =623 await PlacesUtils.promiseBookmarksTree(folder_level_1_info.guid);624 let original_folder_level_2_tree =625 Object.assign({ parentGuid: original_folder_level_1_tree.guid },626 original_folder_level_1_tree.children[0]);627 ensureUndoState([[folder_level_2_txn_result, folder_level_1_txn_result]]);628 await ensureItemsAdded(folder_level_1_info, folder_level_2_info);629 observer.reset();630 let remove_folder_2_txn = PT.Remove(folder_level_2_info);631 await remove_folder_2_txn.transact();632 ensureUndoState([ [remove_folder_2_txn],633 [folder_level_2_txn_result, folder_level_1_txn_result] ]);634 await ensureItemsRemoved(folder_level_2_info);635 // Undo Remove "Folder Level 2"636 await PT.undo();637 ensureUndoState([ [remove_folder_2_txn],638 [folder_level_2_txn_result, folder_level_1_txn_result] ], 1);639 await ensureItemsAdded(folder_level_2_info);640 await ensureBookmarksTreeRestoredCorrectly(original_folder_level_2_tree);641 observer.reset();642 // Redo Remove "Folder Level 2"643 await PT.redo();644 ensureUndoState([ [remove_folder_2_txn],645 [folder_level_2_txn_result, folder_level_1_txn_result] ]);646 await ensureItemsRemoved(folder_level_2_info);647 observer.reset();648 // Undo it again649 await PT.undo();650 ensureUndoState([ [remove_folder_2_txn],651 [folder_level_2_txn_result, folder_level_1_txn_result] ], 1);652 await ensureItemsAdded(folder_level_2_info);653 await ensureBookmarksTreeRestoredCorrectly(original_folder_level_2_tree);654 observer.reset();655 // Undo the creation of both folders656 await PT.undo();657 ensureUndoState([ [remove_folder_2_txn],658 [folder_level_2_txn_result, folder_level_1_txn_result] ], 2);659 await ensureItemsRemoved(folder_level_2_info, folder_level_1_info);660 observer.reset();661 // Redo the creation of both folders662 await PT.redo();663 ensureUndoState([ [remove_folder_2_txn],664 [folder_level_2_txn_result, folder_level_1_txn_result] ], 1);665 await ensureItemsAdded(folder_level_1_info, folder_level_2_info);666 await ensureBookmarksTreeRestoredCorrectlyExceptDates(original_folder_level_1_tree);667 observer.reset();668 // Redo Remove "Folder Level 2"669 await PT.redo();670 ensureUndoState([ [remove_folder_2_txn],671 [folder_level_2_txn_result, folder_level_1_txn_result] ]);672 await ensureItemsRemoved(folder_level_2_info);673 observer.reset();674 // Undo everything one last time675 await PT.undo();676 ensureUndoState([ [remove_folder_2_txn],677 [folder_level_2_txn_result, folder_level_1_txn_result] ], 1);678 await ensureItemsAdded(folder_level_2_info);679 observer.reset();680 await PT.undo();681 ensureUndoState([ [remove_folder_2_txn],682 [folder_level_2_txn_result, folder_level_1_txn_result] ], 2);683 await ensureItemsRemoved(folder_level_2_info, folder_level_2_info);684 observer.reset();685 await PT.clearTransactionsHistory();686 ensureUndoState();687});688add_task(async function test_add_and_remove_bookmarks_with_additional_info() {689 const testURI = NetUtil.newURI("http://add.remove.tag");690 const TAG_1 = "TestTag1";691 const TAG_2 = "TestTag2";692 const ANNO = { name: "TestAnno", value: "TestAnnoValue" };693 let folder_info = createTestFolderInfo();694 folder_info.guid = await PT.NewFolder(folder_info).transact();695 let ensureTags = ensureTagsForURI.bind(null, testURI);696 // Check that the NewBookmark transaction preserves tags.697 observer.reset();698 let b1_info = { parentGuid: folder_info.guid, url: testURI, tags: [TAG_1] };699 b1_info.guid = await PT.NewBookmark(b1_info).transact();700 let b1_originalInfo = await PlacesUtils.promiseBookmarksTree(b1_info.guid);701 ensureTags([TAG_1]);702 await PT.undo();703 ensureTags([]);704 observer.reset();705 await PT.redo();706 await ensureBookmarksTreeRestoredCorrectly(b1_originalInfo);707 ensureTags([TAG_1]);708 // Check if the Remove transaction removes and restores tags of children709 // correctly.710 await PT.Remove(folder_info.guid).transact();711 ensureTags([]);712 observer.reset();713 await PT.undo();714 await ensureBookmarksTreeRestoredCorrectly(b1_originalInfo);715 ensureTags([TAG_1]);716 await PT.redo();717 ensureTags([]);718 observer.reset();719 await PT.undo();720 await ensureBookmarksTreeRestoredCorrectly(b1_originalInfo);721 ensureTags([TAG_1]);722 // * Check that no-op tagging (the uri is already tagged with TAG_1) is723 // also a no-op on undo.724 observer.reset();725 let b2_info = { parentGuid: folder_info.guid,726 url: testURI,727 tags: [TAG_1, TAG_2],728 annotations: [ANNO] };729 b2_info.guid = await PT.NewBookmark(b2_info).transact();730 let b2_post_creation_changes = [731 { guid: b2_info.guid,732 isAnnoProperty: true,733 property: ANNO.name,734 newValue: ANNO.value } ];735 ensureItemsChanged(...b2_post_creation_changes);736 ensureTags([TAG_1, TAG_2]);737 observer.reset();738 await PT.undo();739 await ensureItemsRemoved(b2_info);740 ensureTags([TAG_1]);741 // Check if Remove correctly restores tags and annotations.742 observer.reset();743 await PT.redo();744 ensureItemsChanged({ guid: b2_info.guid,745 isAnnoProperty: true,746 property: ANNO.name,747 newValue: ANNO.value });748 ensureTags([TAG_1, TAG_2]);749 // Test Remove for multiple items.750 observer.reset();751 await PT.Remove(b1_info.guid).transact();752 await PT.Remove(b2_info.guid).transact();753 await PT.Remove(folder_info.guid).transact();754 await ensureItemsRemoved(b1_info, b2_info, folder_info);755 ensureTags([]);756 observer.reset();757 await PT.undo();758 await ensureItemsAdded(folder_info);759 ensureTags([]);760 observer.reset();761 await PT.undo();762 ensureItemsChanged(...b2_post_creation_changes);763 ensureTags([TAG_1, TAG_2]);764 observer.reset();765 await PT.undo();766 await ensureItemsAdded(b1_info);767 ensureTags([TAG_1, TAG_2]);768 // The redo calls below cleanup everything we did.769 observer.reset();770 await PT.redo();771 await ensureItemsRemoved(b1_info);772 ensureTags([TAG_1, TAG_2]);773 observer.reset();774 await PT.redo();775 await ensureItemsRemoved(b2_info);776 ensureTags([]);777 observer.reset();778 await PT.redo();779 await ensureItemsRemoved(folder_info);780 ensureTags([]);781 await PT.clearTransactionsHistory();782 ensureUndoState();783});784add_task(async function test_creating_and_removing_a_separator() {785 let folder_info = createTestFolderInfo();786 let separator_info = {};787 let undoEntries = [];788 observer.reset();789 let create_txns = await PT.batch(async function() {790 let folder_txn = PT.NewFolder(folder_info);791 folder_info.guid = separator_info.parentGuid = await folder_txn.transact();792 let separator_txn = PT.NewSeparator(separator_info);793 separator_info.guid = await separator_txn.transact();794 return [separator_txn, folder_txn];795 });796 undoEntries.unshift(create_txns);797 ensureUndoState(undoEntries, 0);798 ensureItemsAdded(folder_info, separator_info);799 observer.reset();800 await PT.undo();801 ensureUndoState(undoEntries, 1);802 ensureItemsRemoved(folder_info, separator_info);803 observer.reset();804 await PT.redo();805 ensureUndoState(undoEntries, 0);806 ensureItemsAdded(folder_info, separator_info);807 observer.reset();808 let remove_sep_txn = PT.Remove(separator_info);809 await remove_sep_txn.transact();810 undoEntries.unshift([remove_sep_txn]);811 ensureUndoState(undoEntries, 0);812 ensureItemsRemoved(separator_info);813 observer.reset();814 await PT.undo();815 ensureUndoState(undoEntries, 1);816 ensureItemsAdded(separator_info);817 observer.reset();818 await PT.undo();819 ensureUndoState(undoEntries, 2);820 ensureItemsRemoved(folder_info, separator_info);821 observer.reset();822 await PT.redo();823 ensureUndoState(undoEntries, 1);824 ensureItemsAdded(folder_info, separator_info);825 // Clear redo entries and check that |redo| does nothing826 observer.reset();827 await PT.clearTransactionsHistory(false, true);828 undoEntries.shift();829 ensureUndoState(undoEntries, 0);830 await PT.redo();831 ensureItemsAdded();832 ensureItemsRemoved();833 // Cleanup834 observer.reset();835 await PT.undo();836 ensureUndoState(undoEntries, 1);837 ensureItemsRemoved(folder_info, separator_info);838 await PT.clearTransactionsHistory();839 ensureUndoState();840});841add_task(async function test_add_and_remove_livemark() {842 let createLivemarkTxn = PT.NewLivemark(843 { feedUrl: NetUtil.newURI("http://test.remove.livemark"),844 parentGuid: rootGuid,845 title: "Test Remove Livemark" });846 let guid = await createLivemarkTxn.transact();847 let originalInfo = await PlacesUtils.promiseBookmarksTree(guid);848 Assert.ok(originalInfo);849 await ensureLivemarkCreatedByAddLivemark(guid);850 let removeTxn = PT.Remove(guid);851 await removeTxn.transact();852 await ensureNonExistent(guid);853 async function undo() {854 ensureUndoState([[removeTxn], [createLivemarkTxn]], 0);855 await PT.undo();856 ensureUndoState([[removeTxn], [createLivemarkTxn]], 1);857 await ensureBookmarksTreeRestoredCorrectly(originalInfo);858 await PT.undo();859 ensureUndoState([[removeTxn], [createLivemarkTxn]], 2);860 await ensureNonExistent(guid);861 }862 async function redo() {863 ensureUndoState([[removeTxn], [createLivemarkTxn]], 2);864 await PT.redo();865 ensureUndoState([[removeTxn], [createLivemarkTxn]], 1);866 await ensureBookmarksTreeRestoredCorrectly(originalInfo);867 await PT.redo();868 ensureUndoState([[removeTxn], [createLivemarkTxn]], 0);869 await ensureNonExistent(guid);870 }871 await undo();872 await redo();873 await undo();874 await redo();875 // Cleanup876 await undo();877 observer.reset();878 await PT.clearTransactionsHistory();879});880add_task(async function test_edit_title() {881 let bm_info = { parentGuid: rootGuid,882 url: NetUtil.newURI("http://test_create_item.com"),883 title: "Original Title" };884 function ensureTitleChange(aCurrentTitle) {885 ensureItemsChanged({ guid: bm_info.guid,886 property: "title",887 newValue: aCurrentTitle});888 }889 bm_info.guid = await PT.NewBookmark(bm_info).transact();890 observer.reset();891 await PT.EditTitle({ guid: bm_info.guid, title: "New Title" }).transact();892 ensureTitleChange("New Title");893 observer.reset();894 await PT.undo();895 ensureTitleChange("Original Title");896 observer.reset();897 await PT.redo();898 ensureTitleChange("New Title");899 // Cleanup900 observer.reset();901 await PT.undo();902 ensureTitleChange("Original Title");903 await PT.undo();904 ensureItemsRemoved(bm_info);905 await PT.clearTransactionsHistory();906 ensureUndoState();907});908add_task(async function test_edit_url() {909 let oldURI = NetUtil.newURI("http://old.test_editing_item_uri.com/");910 let newURI = NetUtil.newURI("http://new.test_editing_item_uri.com/");911 let bm_info = { parentGuid: rootGuid, url: oldURI, tags: ["TestTag"] };912 function ensureURIAndTags(aPreChangeURI, aPostChangeURI, aOLdURITagsPreserved) {913 ensureItemsChanged({ guid: bm_info.guid,914 property: "uri",915 newValue: aPostChangeURI.spec });916 ensureTagsForURI(aPostChangeURI, bm_info.tags);917 ensureTagsForURI(aPreChangeURI, aOLdURITagsPreserved ? bm_info.tags : []);918 }919 bm_info.guid = await PT.NewBookmark(bm_info).transact();920 ensureTagsForURI(oldURI, bm_info.tags);921 // When there's a single bookmark for the same url, tags should be moved.922 observer.reset();923 await PT.EditUrl({ guid: bm_info.guid, url: newURI }).transact();924 ensureURIAndTags(oldURI, newURI, false);925 observer.reset();926 await PT.undo();927 ensureURIAndTags(newURI, oldURI, false);928 observer.reset();929 await PT.redo();930 ensureURIAndTags(oldURI, newURI, false);931 observer.reset();932 await PT.undo();933 ensureURIAndTags(newURI, oldURI, false);934 // When there're multiple bookmarks for the same url, tags should be copied.935 let bm2_info = Object.create(bm_info);936 bm2_info.guid = await PT.NewBookmark(bm2_info).transact();937 let bm3_info = Object.create(bm_info);938 bm3_info.url = newURI;939 bm3_info.guid = await PT.NewBookmark(bm3_info).transact();940 observer.reset();941 await PT.EditUrl({ guid: bm_info.guid, url: newURI }).transact();942 ensureURIAndTags(oldURI, newURI, true);943 observer.reset();944 await PT.undo();945 ensureURIAndTags(newURI, oldURI, true);946 observer.reset();947 await PT.redo();948 ensureURIAndTags(oldURI, newURI, true);949 // Cleanup950 observer.reset();951 await PT.undo();952 ensureURIAndTags(newURI, oldURI, true);953 await PT.undo();954 await PT.undo();955 await PT.undo();956 ensureItemsRemoved(bm3_info, bm2_info, bm_info);957 await PT.clearTransactionsHistory();958 ensureUndoState();959});960add_task(async function test_edit_keyword() {961 let bm_info = { parentGuid: rootGuid,962 url: NetUtil.newURI("http://test.edit.keyword") };963 const KEYWORD = "test_keyword";964 bm_info.guid = await PT.NewBookmark(bm_info).transact();965 function ensureKeywordChange(aCurrentKeyword = "") {966 ensureItemsChanged({ guid: bm_info.guid,967 property: "keyword",968 newValue: aCurrentKeyword });969 }970 bm_info.guid = await PT.NewBookmark(bm_info).transact();971 observer.reset();972 await PT.EditKeyword({ guid: bm_info.guid, keyword: KEYWORD, postData: "postData" }).transact();973 ensureKeywordChange(KEYWORD);974 let entry = await PlacesUtils.keywords.fetch(KEYWORD);975 Assert.equal(entry.url.href, bm_info.url.spec);976 Assert.equal(entry.postData, "postData");977 observer.reset();978 await PT.undo();979 ensureKeywordChange();980 entry = await PlacesUtils.keywords.fetch(KEYWORD);981 Assert.equal(entry, null);982 observer.reset();983 await PT.redo();984 ensureKeywordChange(KEYWORD);985 entry = await PlacesUtils.keywords.fetch(KEYWORD);986 Assert.equal(entry.url.href, bm_info.url.spec);987 Assert.equal(entry.postData, "postData");988 // Cleanup989 observer.reset();990 await PT.undo();991 ensureKeywordChange();992 await PT.undo();993 ensureItemsRemoved(bm_info);994 await PT.clearTransactionsHistory();995 ensureUndoState();996});997add_task(async function test_edit_specific_keyword() {998 let bm_info = { parentGuid: rootGuid,999 url: NetUtil.newURI("http://test.edit.keyword") };1000 bm_info.guid = await PT.NewBookmark(bm_info).transact();1001 function ensureKeywordChange(aCurrentKeyword = "", aPreviousKeyword = "") {1002 ensureItemsChanged({ guid: bm_info.guid,1003 property: "keyword",1004 newValue: aCurrentKeyword1005 });1006 }1007 await PlacesUtils.keywords.insert({ keyword: "kw1", url: bm_info.url.spec, postData: "postData1" });1008 await PlacesUtils.keywords.insert({ keyword: "kw2", url: bm_info.url.spec, postData: "postData2" });1009 bm_info.guid = await PT.NewBookmark(bm_info).transact();1010 observer.reset();1011 await PT.EditKeyword({ guid: bm_info.guid, keyword: "keyword", oldKeyword: "kw2" }).transact();1012 ensureKeywordChange("keyword", "kw2");1013 let entry = await PlacesUtils.keywords.fetch("kw1");1014 Assert.equal(entry.url.href, bm_info.url.spec);1015 Assert.equal(entry.postData, "postData1");1016 entry = await PlacesUtils.keywords.fetch("keyword");1017 Assert.equal(entry.url.href, bm_info.url.spec);1018 Assert.equal(entry.postData, "postData2");1019 entry = await PlacesUtils.keywords.fetch("kw2");1020 Assert.equal(entry, null);1021 observer.reset();1022 await PT.undo();1023 ensureKeywordChange("kw2", "keyword");1024 entry = await PlacesUtils.keywords.fetch("kw1");1025 Assert.equal(entry.url.href, bm_info.url.spec);1026 Assert.equal(entry.postData, "postData1");1027 entry = await PlacesUtils.keywords.fetch("kw2");1028 Assert.equal(entry.url.href, bm_info.url.spec);1029 Assert.equal(entry.postData, "postData2");1030 entry = await PlacesUtils.keywords.fetch("keyword");1031 Assert.equal(entry, null);1032 observer.reset();1033 await PT.redo();1034 ensureKeywordChange("keyword", "kw2");1035 entry = await PlacesUtils.keywords.fetch("kw1");1036 Assert.equal(entry.url.href, bm_info.url.spec);1037 Assert.equal(entry.postData, "postData1");1038 entry = await PlacesUtils.keywords.fetch("keyword");1039 Assert.equal(entry.url.href, bm_info.url.spec);1040 Assert.equal(entry.postData, "postData2");1041 entry = await PlacesUtils.keywords.fetch("kw2");1042 Assert.equal(entry, null);1043 // Cleanup1044 observer.reset();1045 await PT.undo();1046 ensureKeywordChange("kw2");1047 await PT.undo();1048 ensureItemsRemoved(bm_info);1049 await PT.clearTransactionsHistory();1050 ensureUndoState();1051});1052add_task(async function test_tag_uri() {1053 // This also tests passing uri specs.1054 let bm_info_a = { url: "http://bookmarked.uri",1055 parentGuid: rootGuid };1056 let bm_info_b = { url: NetUtil.newURI("http://bookmarked2.uri"),1057 parentGuid: rootGuid };1058 let unbookmarked_uri = NetUtil.newURI("http://un.bookmarked.uri");1059 await PT.batch(async function() {1060 bm_info_a.guid = await PT.NewBookmark(bm_info_a).transact();1061 bm_info_b.guid = await PT.NewBookmark(bm_info_b).transact();1062 });1063 async function doTest(aInfo) {1064 let urls = "url" in aInfo ? [aInfo.url] : aInfo.urls;1065 let tags = "tag" in aInfo ? [aInfo.tag] : aInfo.tags;1066 let ensureURI = url => typeof(url) == "string" ? NetUtil.newURI(url) : url;1067 urls = urls.map(ensureURI);1068 let tagWillAlsoBookmark = new Set();1069 for (let url of urls) {1070 if (!(await bmsvc.fetch({ url }))) {1071 tagWillAlsoBookmark.add(url);1072 }1073 }1074 async function ensureTagsSet() {1075 for (let url of urls) {1076 ensureTagsForURI(url, tags);1077 Assert.ok(await bmsvc.fetch({ url }));1078 }1079 }1080 async function ensureTagsUnset() {1081 for (let url of urls) {1082 ensureTagsForURI(url, []);1083 if (tagWillAlsoBookmark.has(url))1084 Assert.ok(!(await bmsvc.fetch({ url })));1085 else1086 Assert.ok(await bmsvc.fetch({ url }));1087 }1088 }1089 await PT.Tag(aInfo).transact();1090 await ensureTagsSet();1091 await PT.undo();1092 await ensureTagsUnset();1093 await PT.redo();1094 await ensureTagsSet();1095 await PT.undo();1096 await ensureTagsUnset();1097 }1098 await doTest({ url: bm_info_a.url, tags: ["MyTag"] });1099 await doTest({ urls: [bm_info_a.url], tag: "MyTag" });1100 await doTest({ urls: [bm_info_a.url, bm_info_b.url], tags: ["A, B"] });1101 await doTest({ urls: [bm_info_a.url, unbookmarked_uri], tag: "C" });1102 // Cleanup1103 observer.reset();1104 await PT.undo();1105 ensureItemsRemoved(bm_info_a, bm_info_b);1106 await PT.clearTransactionsHistory();1107 ensureUndoState();1108});1109add_task(async function test_untag_uri() {1110 let bm_info_a = { url: NetUtil.newURI("http://bookmarked.uri"),1111 parentGuid: rootGuid,1112 tags: ["A", "B"] };1113 let bm_info_b = { url: NetUtil.newURI("http://bookmarked2.uri"),1114 parentGuid: rootGuid,1115 tag: "B" };1116 await PT.batch(async function() {1117 bm_info_a.guid = await PT.NewBookmark(bm_info_a).transact();1118 ensureTagsForURI(bm_info_a.url, bm_info_a.tags);1119 bm_info_b.guid = await PT.NewBookmark(bm_info_b).transact();1120 ensureTagsForURI(bm_info_b.url, [bm_info_b.tag]);1121 });1122 async function doTest(aInfo) {1123 let urls, tagsRemoved;1124 if (aInfo instanceof Ci.nsIURI) {1125 urls = [aInfo];1126 tagsRemoved = [];1127 } else if (Array.isArray(aInfo)) {1128 urls = aInfo;1129 tagsRemoved = [];1130 } else {1131 urls = "url" in aInfo ? [aInfo.url] : aInfo.urls;1132 tagsRemoved = "tag" in aInfo ? [aInfo.tag] : aInfo.tags;1133 }1134 let preRemovalTags = new Map();1135 for (let url of urls) {1136 preRemovalTags.set(url, tagssvc.getTagsForURI(url));1137 }1138 function ensureTagsSet() {1139 for (let url of urls) {1140 ensureTagsForURI(url, preRemovalTags.get(url));1141 }1142 }1143 function ensureTagsUnset() {1144 for (let url of urls) {1145 let expectedTags = tagsRemoved.length == 0 ?1146 [] : preRemovalTags.get(url).filter(tag => !tagsRemoved.includes(tag));1147 ensureTagsForURI(url, expectedTags);1148 }1149 }1150 await PT.Untag(aInfo).transact();1151 await ensureTagsUnset();1152 await PT.undo();1153 await ensureTagsSet();1154 await PT.redo();1155 await ensureTagsUnset();1156 await PT.undo();1157 await ensureTagsSet();1158 }1159 await doTest(bm_info_a);1160 await doTest(bm_info_b);1161 await doTest(bm_info_a.url);1162 await doTest(bm_info_b.url);1163 await doTest([bm_info_a.url, bm_info_b.url]);1164 await doTest({ urls: [bm_info_a.url, bm_info_b.url], tags: ["A", "B"] });1165 await doTest({ urls: [bm_info_a.url, bm_info_b.url], tag: "B" });1166 await doTest({ urls: [bm_info_a.url, bm_info_b.url], tag: "C" });1167 await doTest({ urls: [bm_info_a.url, bm_info_b.url], tags: ["C"] });1168 // Cleanup1169 observer.reset();1170 await PT.undo();1171 ensureItemsRemoved(bm_info_a, bm_info_b);1172 await PT.clearTransactionsHistory();1173 ensureUndoState();1174});1175add_task(async function test_annotate() {1176 let bm_info = { url: NetUtil.newURI("http://test.item.annotation"),1177 parentGuid: rootGuid };1178 let anno_info = { name: "TestAnno", value: "TestValue" };1179 function ensureAnnoState(aSet) {1180 ensureAnnotationsSet(bm_info.guid,1181 [{ name: anno_info.name,1182 value: aSet ? anno_info.value : null }]);1183 }1184 bm_info.guid = await PT.NewBookmark(bm_info).transact();1185 observer.reset();1186 await PT.Annotate({ guid: bm_info.guid, annotation: anno_info }).transact();1187 ensureAnnoState(true);1188 observer.reset();1189 await PT.undo();1190 ensureAnnoState(false);1191 observer.reset();1192 await PT.redo();1193 ensureAnnoState(true);1194 // Test removing the annotation by not passing the |value| property.1195 observer.reset();1196 await PT.Annotate({ guid: bm_info.guid,1197 annotation: { name: anno_info.name }}).transact();1198 ensureAnnoState(false);1199 observer.reset();1200 await PT.undo();1201 ensureAnnoState(true);1202 observer.reset();1203 await PT.redo();1204 ensureAnnoState(false);1205 // Cleanup1206 await PT.undo();1207 observer.reset();1208});1209add_task(async function test_annotate_multiple() {1210 let guid = await PT.NewFolder(createTestFolderInfo()).transact();1211 let itemId = await PlacesUtils.promiseItemId(guid);1212 function AnnoObj(aName, aValue) {1213 this.name = aName;1214 this.value = aValue;1215 this.flags = 0;1216 this.expires = Ci.nsIAnnotationService.EXPIRE_NEVER;1217 }1218 function annos(a = null, b = null) {1219 return [new AnnoObj("A", a), new AnnoObj("B", b)];1220 }1221 function verifyAnnoValues(a = null, b = null) {1222 let currentAnnos = PlacesUtils.getAnnotationsForItem(itemId);1223 let expectedAnnos = [];1224 if (a !== null)1225 expectedAnnos.push(new AnnoObj("A", a));1226 if (b !== null)1227 expectedAnnos.push(new AnnoObj("B", b));1228 Assert.deepEqual(currentAnnos, expectedAnnos);1229 }1230 await PT.Annotate({ guid, annotations: annos(1, 2) }).transact();1231 verifyAnnoValues(1, 2);1232 await PT.undo();1233 verifyAnnoValues();1234 await PT.redo();1235 verifyAnnoValues(1, 2);1236 await PT.Annotate({ guid,1237 annotation: { name: "A" } }).transact();1238 verifyAnnoValues(null, 2);1239 await PT.Annotate({ guid,1240 annotation: { name: "B", value: 0 } }).transact();1241 verifyAnnoValues(null, 0);1242 await PT.undo();1243 verifyAnnoValues(null, 2);1244 await PT.redo();1245 verifyAnnoValues(null, 0);1246 await PT.undo();1247 verifyAnnoValues(null, 2);1248 await PT.undo();1249 verifyAnnoValues(1, 2);1250 await PT.undo();1251 verifyAnnoValues();1252 // Cleanup1253 await PT.undo();1254 observer.reset();1255});1256add_task(async function test_sort_folder_by_name() {1257 let folder_info = createTestFolderInfo();1258 let url = NetUtil.newURI("http://sort.by.name/");1259 let preSep = ["3", "2", "1"].map(i => ({ title: i, url }));1260 let sep = {};1261 let postSep = ["c", "b", "a"].map(l => ({ title: l, url }));1262 let originalOrder = [...preSep, sep, ...postSep];1263 let sortedOrder = [...preSep.slice(0).reverse(),1264 sep,1265 ...postSep.slice(0).reverse()];1266 await PT.batch(async function() {1267 folder_info.guid = await PT.NewFolder(folder_info).transact();1268 for (let info of originalOrder) {1269 info.parentGuid = folder_info.guid;1270 info.guid = await (info == sep ?1271 PT.NewSeparator(info).transact() :1272 PT.NewBookmark(info).transact());1273 }1274 });1275 let folderId = await PlacesUtils.promiseItemId(folder_info.guid);1276 let folderContainer = PlacesUtils.getFolderContents(folderId).root;1277 function ensureOrder(aOrder) {1278 for (let i = 0; i < folderContainer.childCount; i++) {1279 do_check_eq(folderContainer.getChild(i).bookmarkGuid, aOrder[i].guid);1280 }1281 }1282 ensureOrder(originalOrder);1283 await PT.SortByName(folder_info.guid).transact();1284 ensureOrder(sortedOrder);1285 await PT.undo();1286 ensureOrder(originalOrder);1287 await PT.redo();1288 ensureOrder(sortedOrder);1289 // Cleanup1290 observer.reset();1291 await PT.undo();1292 ensureOrder(originalOrder);1293 await PT.undo();1294 ensureItemsRemoved(...originalOrder, folder_info);1295});1296add_task(async function test_livemark_txns() {1297 let livemark_info =1298 { feedUrl: NetUtil.newURI("http://test.feed.uri"),1299 parentGuid: rootGuid,1300 title: "Test Livemark" };1301 function ensureLivemarkAdded() {1302 ensureItemsAdded({ guid: livemark_info.guid,1303 title: livemark_info.title,1304 parentGuid: livemark_info.parentGuid,1305 itemType: bmsvc.TYPE_FOLDER });1306 let annos = [{ name: PlacesUtils.LMANNO_FEEDURI,1307 value: livemark_info.feedUrl.spec }];1308 if ("siteUrl" in livemark_info) {1309 annos.push({ name: PlacesUtils.LMANNO_SITEURI,1310 value: livemark_info.siteUrl.spec });1311 }1312 ensureAnnotationsSet(livemark_info.guid, annos);1313 }1314 function ensureLivemarkRemoved() {1315 ensureItemsRemoved({ guid: livemark_info.guid,1316 parentGuid: livemark_info.parentGuid });1317 }1318 async function _testDoUndoRedoUndo() {1319 observer.reset();1320 livemark_info.guid = await PT.NewLivemark(livemark_info).transact();1321 ensureLivemarkAdded();1322 observer.reset();1323 await PT.undo();1324 ensureLivemarkRemoved();1325 observer.reset();1326 await PT.redo();1327 ensureLivemarkAdded();1328 await PT.undo();1329 ensureLivemarkRemoved();1330 }1331 await _testDoUndoRedoUndo()1332 livemark_info.siteUrl = NetUtil.newURI("http://feed.site.uri");1333 await _testDoUndoRedoUndo();1334 // Cleanup1335 observer.reset();1336 await PT.clearTransactionsHistory();1337});1338add_task(async function test_copy() {1339 async function duplicate_and_test(aOriginalGuid) {1340 let txn = PT.Copy({ guid: aOriginalGuid, newParentGuid: rootGuid });1341 let duplicateGuid = await txn.transact();1342 let originalInfo = await PlacesUtils.promiseBookmarksTree(aOriginalGuid);1343 let duplicateInfo = await PlacesUtils.promiseBookmarksTree(duplicateGuid);1344 await ensureEqualBookmarksTrees(originalInfo, duplicateInfo, false);1345 async function redo() {1346 await PT.redo();1347 await ensureBookmarksTreeRestoredCorrectlyExceptDates(originalInfo);1348 await PT.redo();1349 await ensureBookmarksTreeRestoredCorrectlyExceptDates(duplicateInfo);1350 }1351 async function undo() {1352 await PT.undo();1353 // also undo the original item addition.1354 await PT.undo();1355 await ensureNonExistent(aOriginalGuid, duplicateGuid);1356 }1357 await undo();1358 await redo();1359 await undo();1360 await redo();1361 // Cleanup. This also remove the original item.1362 await PT.undo();1363 observer.reset();1364 await PT.clearTransactionsHistory();1365 }1366 // Test duplicating leafs (bookmark, separator, empty folder)1367 PT.NewBookmark({ url: new URL("http://test.item.duplicate"),1368 parentGuid: rootGuid,1369 annos: [{ name: "Anno", value: "AnnoValue"}] });1370 let sepTxn = PT.NewSeparator({ parentGuid: rootGuid, index: 1 });1371 let livemarkTxn = PT.NewLivemark(1372 { feedUrl: new URL("http://test.feed.uri"),1373 parentGuid: rootGuid,1374 title: "Test Livemark", index: 1 });1375 let emptyFolderTxn = PT.NewFolder(createTestFolderInfo());1376 for (let txn of [livemarkTxn, sepTxn, emptyFolderTxn]) {1377 let guid = await txn.transact();1378 await duplicate_and_test(guid);1379 }1380 // Test duplicating a folder having some contents.1381 let filledFolderGuid = await PT.batch(async function() {1382 let folderGuid = await PT.NewFolder(createTestFolderInfo()).transact();1383 let nestedFolderGuid =1384 await PT.NewFolder({ parentGuid: folderGuid,1385 title: "Nested Folder" }).transact();1386 // Insert a bookmark under the nested folder.1387 await PT.NewBookmark({ url: new URL("http://nested.nested.bookmark"),1388 parentGuid: nestedFolderGuid }).transact();1389 // Insert a separator below the nested folder1390 await PT.NewSeparator({ parentGuid: folderGuid }).transact();1391 // And another bookmark.1392 await PT.NewBookmark({ url: new URL("http://nested.bookmark"),1393 parentGuid: folderGuid }).transact();1394 return folderGuid;1395 });1396 await duplicate_and_test(filledFolderGuid);1397 // Cleanup1398 await PT.clearTransactionsHistory();1399});1400add_task(async function test_array_input_for_batch() {1401 let folderTxn = PT.NewFolder(createTestFolderInfo());1402 let folderGuid = await folderTxn.transact();1403 let sep1_txn = PT.NewSeparator({ parentGuid: folderGuid });1404 let sep2_txn = PT.NewSeparator({ parentGuid: folderGuid });1405 await PT.batch([sep1_txn, sep2_txn]);1406 ensureUndoState([[sep2_txn, sep1_txn], [folderTxn]], 0);1407 let ensureChildCount = async function(count) {1408 let tree = await PlacesUtils.promiseBookmarksTree(folderGuid);1409 if (count == 0)1410 Assert.ok(!("children" in tree));1411 else1412 Assert.equal(tree.children.length, count);1413 };1414 await ensureChildCount(2);1415 await PT.undo();1416 await ensureChildCount(0);1417 await PT.redo()1418 await ensureChildCount(2);1419 await PT.undo();1420 await ensureChildCount(0);1421 await PT.undo();1422 Assert.equal((await PlacesUtils.promiseBookmarksTree(folderGuid)), null);1423 // Cleanup1424 await PT.clearTransactionsHistory();1425});1426add_task(async function test_copy_excluding_annotations() {1427 let folderInfo = createTestFolderInfo();1428 let anno = n => { return { name: n, value: 1 } };1429 folderInfo.annotations = [anno("a"), anno("b"), anno("c")];1430 let folderGuid = await PT.NewFolder(folderInfo).transact();1431 let ensureAnnosSet = async function(guid, ...expectedAnnoNames) {1432 let tree = await PlacesUtils.promiseBookmarksTree(guid);1433 let annoNames = "annos" in tree ?1434 tree.annos.map(a => a.name).sort() : [];1435 Assert.deepEqual(annoNames, expectedAnnoNames);1436 };1437 await ensureAnnosSet(folderGuid, "a", "b", "c");1438 let excluding_a_dupeGuid =1439 await PT.Copy({ guid: folderGuid,1440 newParentGuid: rootGuid,1441 excludingAnnotation: "a" }).transact();1442 await ensureAnnosSet(excluding_a_dupeGuid, "b", "c");1443 let excluding_ac_dupeGuid =1444 await PT.Copy({ guid: folderGuid,1445 newParentGuid: rootGuid,1446 excludingAnnotations: ["a", "c"] }).transact();1447 await ensureAnnosSet(excluding_ac_dupeGuid, "b");1448 // Cleanup1449 await PT.undo();1450 await PT.undo();1451 await PT.undo();1452 await PT.clearTransactionsHistory();1453});1454add_task(async function test_invalid_uri_spec_throws() {1455 Assert.throws(() =>1456 PT.NewBookmark({ parentGuid: rootGuid,1457 url: "invalid uri spec",1458 title: "test bookmark" }));1459 Assert.throws(() =>1460 PT.Tag({ tag: "TheTag",1461 urls: ["invalid uri spec"] }));1462 Assert.throws(() =>1463 PT.Tag({ tag: "TheTag",1464 urls: ["about:blank", "invalid uri spec"] }));1465});1466add_task(async function test_annotate_multiple_items() {1467 let parentGuid = menuGuid;1468 let guids = [1469 await PT.NewBookmark({ url: "about:blank", parentGuid }).transact(),1470 await PT.NewFolder({ title: "Test Folder", parentGuid }).transact()];1471 let annotation = { name: "TestAnno", value: "TestValue" };1472 await PT.Annotate({ guids, annotation }).transact();1473 async function ensureAnnoSet() {1474 for (let guid of guids) {1475 let itemId = await PlacesUtils.promiseItemId(guid);1476 Assert.equal(annosvc.getItemAnnotation(itemId, annotation.name),1477 annotation.value);1478 }1479 }1480 async function ensureAnnoUnset() {1481 for (let guid of guids) {1482 let itemId = await PlacesUtils.promiseItemId(guid);1483 Assert.ok(!annosvc.itemHasAnnotation(itemId, annotation.name));1484 }1485 }1486 await ensureAnnoSet();1487 await PT.undo();1488 await ensureAnnoUnset();1489 await PT.redo();1490 await ensureAnnoSet();1491 await PT.undo();1492 await ensureAnnoUnset();1493 // Cleanup1494 await PT.undo();1495 await PT.undo();1496 await ensureNonExistent(...guids);1497 await PT.clearTransactionsHistory();1498 observer.reset();1499});1500add_task(async function test_remove_multiple() {1501 let guids = [];1502 await PT.batch(async function() {1503 let folderGuid = await PT.NewFolder({ title: "Test Folder",1504 parentGuid: menuGuid }).transact();1505 let nestedFolderGuid =1506 await PT.NewFolder({ title: "Nested Test Folder",1507 parentGuid: folderGuid }).transact();1508 await PT.NewSeparator(nestedFolderGuid).transact();1509 guids.push(folderGuid);1510 let bmGuid =1511 await PT.NewBookmark({ url: new URL("http://test.bookmark.removed"),1512 parentGuid: menuGuid }).transact();1513 guids.push(bmGuid);1514 });1515 let originalInfos = [];1516 for (let guid of guids) {1517 originalInfos.push(await PlacesUtils.promiseBookmarksTree(guid));1518 }1519 await PT.Remove(guids).transact();1520 await ensureNonExistent(...guids);1521 await PT.undo();1522 await ensureBookmarksTreeRestoredCorrectly(...originalInfos);1523 await PT.redo();1524 await ensureNonExistent(...guids);1525 await PT.undo();1526 await ensureBookmarksTreeRestoredCorrectly(...originalInfos);1527 // Undo the New* transactions batch.1528 await PT.undo();1529 await ensureNonExistent(...guids);1530 // Redo it.1531 await PT.redo();1532 await ensureBookmarksTreeRestoredCorrectlyExceptDates(...originalInfos);1533 // Redo remove.1534 await PT.redo();1535 await ensureNonExistent(...guids);1536 // Cleanup1537 await PT.clearTransactionsHistory();1538 observer.reset();...

Full Screen

Full Screen

indexdb.ts

Source:indexdb.ts Github

copy

Full Screen

1import { Restaurants } from '../../../both/collections/restaurant/restaurant.collection';2import { UserDetails } from '../../../both/collections/auth/user-detail.collection';3import { Sections } from '../../../both/collections/menu/section.collection';4import { Categories } from '../../../both/collections/menu/category.collection';5import { Subcategories } from '../../../both/collections/menu/subcategory.collection';6import { Additions } from '../../../both/collections/menu/addition.collection';7import { Items } from '../../../both/collections/menu/item.collection';8import { GarnishFoodCol } from '../../../both/collections/menu/garnish-food.collection';9import { PaymentMethods } from '../../../both/collections/general/paymentMethod.collection';10import { PaymentsHistory } from '../../../both/collections/payment/payment-history.collection';11import { Accounts } from '../../../both/collections/restaurant/account.collection';12import { Orders } from '../../../both/collections/restaurant/order.collection';13import { Tables } from '../../../both/collections/restaurant/table.collection';14import { Payments } from '../../../both/collections/restaurant/payment.collection';15import { WaiterCallDetails } from '../../../both/collections/restaurant/waiter-call-detail.collection';16import { CcPaymentMethods } from '../../../both/collections/payment/cc-payment-methods.collection';17import { PaymentTransactions } from '../../../both/collections/payment/payment-transaction.collection';18import { Invoices } from '../../../both/collections/restaurant/invoice.collection';19import { Cities } from '../../../both/collections/general/city.collection';20import { Countries } from '../../../both/collections/general/country.collection';21import { Languages } from '../../../both/collections/general/language.collection';22export function createdbindexes(){23 // Restaurant Collection Indexes24 Restaurants.collection._ensureIndex( { creation_user: 1 } );25 Restaurants.collection._ensureIndex( { name: 1 } ); 26 Restaurants.collection._ensureIndex( { isActive: 1 } ); 27 // User Collections Indexes28 UserDetails.collection._ensureIndex( { user_id: 1 } );29 UserDetails.collection._ensureIndex( { restaurant_work: 1 } );30 UserDetails.collection._ensureIndex( { current_restaurant: 1, current_table: 1 } ); 31 // Section Collection Indexes32 Sections.collection._ensureIndex( { creation_user: 1 } );33 Sections.collection._ensureIndex( { restaurants: 1 } ); 34 // Category Collection Indexes35 Categories.collection._ensureIndex( { creation_user: 1 } );36 Categories.collection._ensureIndex( { section: 1 } ); 37 // Subcategory Collection Indexes38 Subcategories.collection._ensureIndex( { creation_user: 1 } );39 Subcategories.collection._ensureIndex( { category: 1 } );40 // Addition Collection Indexes41 Additions.collection._ensureIndex( { creation_user: 1 } );42 Additions.collection._ensureIndex( { restaurants: 1 } ); 43 // Item Collection Indexes44 Items.collection._ensureIndex( { additionsIsAccepted: 1 } );45 Items.collection._ensureIndex( { garnishFoodIsAcceped: 1 } );46 Items.collection._ensureIndex( { creation_user: 1 } );47 Items.collection._ensureIndex( { sectionId: 1 } );48 Items.collection._ensureIndex( { restaurants: 1 } );49 // GarnishFood Collection Indexes50 GarnishFoodCol.collection._ensureIndex( { creation_user: 1 } );51 GarnishFoodCol.collection._ensureIndex( { restaurants: 1 } );52 // PaymentMethod Collection Indexes53 PaymentMethods.collection._ensureIndex( { isActive: 1 } ); 54 55 // PaymentsHistory Collection Indexes56 PaymentsHistory.collection._ensureIndex( { restaurantIds: 1 } );57 PaymentsHistory.collection._ensureIndex( { creation_user: 1 } );58 PaymentsHistory.collection._ensureIndex( { creation_date: 1 } );59 // Accounts Collection Indexes60 Accounts.collection._ensureIndex( { restaurantId: 1 } );61 Accounts.collection._ensureIndex( { status: 1 } );62 Accounts.collection._ensureIndex( { tableId: 1 } );63 // Tables Collection Indexes64 Tables.collection._ensureIndex( { QR_code: 1 } );65 Tables.collection._ensureIndex( { restaurantId: 1 } ); 66 // Orders Collection Indexes67 Orders.collection._ensureIndex( { restaurantId: 1 } );68 Orders.collection._ensureIndex( { tableId: 1 } );69 Orders.collection._ensureIndex( { status: 1 } );70 Orders.collection._ensureIndex( { accountId: 1 } );71 // Payments Collection Indexes72 Payments.collection._ensureIndex( { creation_user: 1 } );73 Payments.collection._ensureIndex( { restaurantId: 1, tableId: 1, status: 1 } );74 75 // WaiterCallDetails Collection Indexes76 WaiterCallDetails.collection._ensureIndex( { status: 1 } );77 WaiterCallDetails.collection._ensureIndex( { user_id: 1 } );78 WaiterCallDetails.collection._ensureIndex( { restaurant_id: 1, table_id: 1, type: 1 } ); 79 // CcPaymentMethods Collection Indexes80 CcPaymentMethods.collection._ensureIndex( { is_active: 1 } );81 // PaymentTransactions Collection Indexes82 PaymentTransactions.collection._ensureIndex( { creation_user: 1 } );83 // Invoices Collection Indexes84 Invoices.collection._ensureIndex( { customer_id: 1 } );85 // Cities Collection Indexes86 Cities.collection._ensureIndex( { country: 1 } );87 Cities.collection._ensureIndex( { is_active: 1 } );88 // Countries Collection Indexes89 Countries.collection._ensureIndex( { is_active: 1 } );90 // Languages Collection Indexes91 Languages.collection._ensureIndex( { is_active: 1 } );...

Full Screen

Full Screen

RequireEnsurePlugin.js

Source:RequireEnsurePlugin.js Github

copy

Full Screen

1/*2 MIT License http://www.opensource.org/licenses/mit-license.php3 Author Tobias Koppers @sokra4*/5"use strict";6const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");7const RequireEnsureDependency = require("./RequireEnsureDependency");8const NullFactory = require("../NullFactory");9const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");10const ParserHelpers = require("../ParserHelpers");11class RequireEnsurePlugin {12 apply(compiler) {13 compiler.hooks.compilation.tap(14 "RequireEnsurePlugin",15 (compilation, { normalModuleFactory }) => {16 compilation.dependencyFactories.set(17 RequireEnsureItemDependency,18 normalModuleFactory19 );20 compilation.dependencyTemplates.set(21 RequireEnsureItemDependency,22 new RequireEnsureItemDependency.Template()23 );24 compilation.dependencyFactories.set(25 RequireEnsureDependency,26 new NullFactory()27 );28 compilation.dependencyTemplates.set(29 RequireEnsureDependency,30 new RequireEnsureDependency.Template()31 );32 const handler = (parser, parserOptions) => {33 if (34 typeof parserOptions.requireEnsure !== "undefined" &&35 !parserOptions.requireEnsure36 )37 return;38 new RequireEnsureDependenciesBlockParserPlugin().apply(parser);39 parser.hooks.evaluateTypeof40 .for("require.ensure")41 .tap(42 "RequireEnsurePlugin",43 ParserHelpers.evaluateToString("function")44 );45 parser.hooks.typeof46 .for("require.ensure")47 .tap(48 "RequireEnsurePlugin",49 ParserHelpers.toConstantDependency(50 parser,51 JSON.stringify("function")52 )53 );54 };55 normalModuleFactory.hooks.parser56 .for("javascript/auto")57 .tap("RequireEnsurePlugin", handler);58 normalModuleFactory.hooks.parser59 .for("javascript/dynamic")60 .tap("RequireEnsurePlugin", handler);61 }62 );63 }64}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensure } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import React from 'react';5import Button from './Button';6storiesOf('Button', module)7 .add('with text', () => (8 <Button onClick={action('clicked')}>Hello Button</Button>9 .add('with some emoji', () => (10 <Button onClick={action('clicked')}>11 ));12import { ensure } from 'storybook-root';13import { storiesOf } from '@storybook/react';14import { action } from '@storybook/addon-actions';15import React from 'react';16import Button from './Button';17storiesOf('Button', module)18 .add('with text', () => (19 <Button onClick={action('clicked')}>Hello Button</Button>20 .add('with some emoji', () => (21 <Button onClick={action('clicked')}>22 ));23import { ensure } from 'storybook-root';24import { storiesOf } from '@storybook/react';25import { action } from '@storybook/addon-actions';26import React from 'react';27import Button from './Button';28storiesOf('Button', module)29 .add('with text', () => (30 <Button onClick={action('clicked')}>Hello Button</Button>31 .add('with some emoji', () => (32 <Button onClick={action('clicked')}>33 ));34import { ensure } from 'storybook-root';35import { storiesOf } from '@storybook/react';36import { action } from '@storybook/addon-actions';37import React from 'react';38import Button from './Button';39storiesOf('Button', module)40 .add('with text', () => (41 <Button onClick={

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensure } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4const stories = storiesOf('Button', module);5stories.addDecorator(withInfo);6ensure(stories, 'with text', () => <Button>Hello Button</Button>);7import { ensure } from 'storybook-root';8import { storiesOf } from '@storybook/react';9import { withInfo } from '@storybook/addon-info';10const stories = storiesOf('Button', module);11stories.addDecorator(withInfo);12ensure(stories, 'with text', () => <Button>Hello Button</Button>);13import { ensure } from 'storybook-root';14import { storiesOf } from '@storybook/react';15import { withInfo } from '@storybook/addon-info';16const stories = storiesOf('Button', module);17stories.addDecorator(withInfo);18ensure(stories, 'with text', () => <Button>Hello Button</Button>);19import { ensure } from 'storybook-root';20import { storiesOf } from '@storybook/react';21import { withInfo } from '@storybook/addon-info';22const stories = storiesOf('Button', module);23stories.addDecorator(withInfo);24ensure(stories, 'with text', () => <Button>Hello Button</Button>);25import { ensure } from 'storybook-root';26import { storiesOf } from '@storybook/react';27import { withInfo } from '@storybook/addon-info';28const stories = storiesOf('Button', module);29stories.addDecorator(withInfo);30ensure(stories, 'with text', () => <Button>Hello Button</Button>);31import { ensure } from 'storybook-root';32import { storiesOf } from '@storybook/react';33import { withInfo } from '@storybook/addon-info';34const stories = storiesOf('Button', module);35stories.addDecorator(withInfo);36ensure(stories, 'with text', () => <Button>Hello Button</Button>);37import { ensure } from 'storybook-root';38import { storiesOf } from '@storybook/react';39import { withInfo } from '@storybook/addon-info';40const stories = storiesOf('Button', module);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensure } from "storybook-root-saga";2import { takeEvery } from "redux-saga/effects";3function* testSaga() {4}5export default function* rootSaga() {6 yield ensure("TEST_SAGA", takeEvery, "TEST_SAGA", testSaga);7}8import { configure } from "@storybook/react";9import { setAddon, addDecorator } from "@storybook/react";10import { withInfo } from "@storybook/addon-info";11import JSXAddon from "storybook-addon-jsx";12import { withKnobs } from "@storybook/addon-knobs";13import { Provider } from "react-redux";14import { createStore, applyMiddleware } from "redux";15import createSagaMiddleware from "redux-saga";16import rootReducer from "../src/reducers";17import rootSaga from "../src/sagas";18const sagaMiddleware = createSagaMiddleware();19const store = createStore(rootReducer, applyMiddleware(sagaMiddleware));20sagaMiddleware.run(rootSaga);21addDecorator(22 withInfo({23 })24);25addDecorator(withKnobs);26setAddon(JSXAddon);27addDecorator(story => <Provider store={store}>{story()}</Provider>);28configure(() => require("../src/stories"), module);29const path = require("path");30module.exports = ({ config }) => {31 config.module.rules.push({32 include: path.resolve(__dirname, "../src"),33 {34 loader: require.resolve("babel-loader"),35 options: {36 presets: [["es2015", { modules: false }], "react"]37 }38 }39 });40 return config;41};42import { combineReducers } from "redux";43import { reducer as formReducer } from "redux-form";44const rootReducer = combineReducers({45});46export default rootReducer;47import { all } from "redux-saga/effects";48import testSaga from "./test";49export default function* rootSaga() {50 yield all([testSaga()]);51}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensure } from 'storybook-root';2import { storiesOf } from '@storybook/react';3import React from 'react';4storiesOf('Test', module)5 .add('Test', () => {6 ensure('Test', 'Test');7 return <div>Test</div>;8 });9import { ensure } from 'storybook-root';10import { storiesOf } from '@storybook/react';11import React from 'react';12storiesOf('Test', module)13 .add('Test', () => {14 ensure('Test', 'Test');15 return <div>Test</div>;16 });17import { ensure } from 'storybook-root';18import { storiesOf } from '@storybook/react';19import React from 'react';20storiesOf('Test', module)21 .add('Test', () => {22 ensure('Test', 'Test');23 return <div>Test</div>;24 });25import { ensure } from 'storybook-root';26import { storiesOf } from '@storybook/react';27import React from 'react';28storiesOf('Test', module)29 .add('Test', () => {30 ensure('Test', 'Test');31 return <div>Test</div>;32 });33import { ensure } from 'storybook-root';34import { storiesOf } from '@storybook/react';35import React from 'react';36storiesOf('Test', module)37 .add('Test', () => {38 ensure('Test', 'Test');39 return <div>Test</div>;40 });41import { ensure } from 'storybook-root';42import { storiesOf } from '@storybook/react';43import React from 'react';44storiesOf('Test', module)45 .add('Test', () => {46 ensure('Test', 'Test');47 return <div>Test</div>;48 });49import { ensure } from 'storybook-root';50import { storiesOf } from '@storybook/react';51import React from 'react';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensure } from 'storybook-root';2const test = () => {3 ensure('storybook-root');4 return 'storybook-root';5};6export default test;7import test from './test';8describe('test', () => {9 it('should return storybook-root', () => {10 expect(test()).toBe('storybook-root');11 });12});13import { configure } from '@storybook/react';14import { ensure } from 'storybook-root';15ensure('storybook-root');16import { addDecorator } from '@storybook/react';17import { ensure } from 'storybook-root';18ensure('storybook-root');19import { addons } from '@storybook/addons';20import { ensure } from 'storybook-root';21ensure('storybook-root');22import '@storybook/addon-actions/register';23import '@storybook/addon-links/register';24import { ensure } from 'storybook-root';25ensure('storybook-root');26const path = require('path');27const { ensure } = require('storybook-root');28ensure('storybook-root');29module.exports = ({ config }) => {30 config.module.rules.push({31 test: /\.(ts|tsx)$/,32 include: path.resolve(__dirname, '../'),33 {34 loader: require.resolve('awesome-typescript-loader'),35 options: {36 },37 },38 {39 loader: require.resolve('react-docgen-typescript-loader'),40 },41 });42 config.resolve.extensions.push('.ts', '.tsx');43 return config;44};45{46 "compilerOptions": {

Full Screen

Using AI Code Generation

copy

Full Screen

1export default function* rootSaga() {2 yield ensure([3 authSaga(),4 ]);5}6export default function* authSaga() {7 yield takeLatest(AUTH_REQUEST, authRequest);8}9export const AUTH_REQUEST = 'AUTH_REQUEST';10export const AUTH_SUCCESS = 'AUTH_SUCCESS';11export const AUTH_FAILURE = 'AUTH_FAILURE';12export const authRequest = createAction(AUTH_REQUEST);13export const authSuccess = createAction(AUTH_SUCCESS);14export const authFailure = createAction(AUTH_FAILURE);15import { createReducer } from 'reduxsauce';16import { AUTH_REQUEST, AUTH_SUCCESS, AUTH_FAILURE } from './actions';17export const INITIAL_STATE = {18};19const authRequest = state => ({20});21const authSuccess = (state, { user }) => ({22});23const authFailure = (state, { error }) => ({24});25export default createReducer(INITIAL_STATE, {26});27import React, { Component } from 'react';28import { connect } from 'react-redux';29import { authRequest } from '../actions';30import { Button } from 'react-native';31class AuthContainer extends Component {32 render() {33 const { authRequest } = this.props;34 return (35 onPress={() => authRequest({ email: '

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensure } from 'storybook-root';2ensure('test', {3});4import { assert } from 'storybook-root';5describe('test', () => {6 it('test', () => {7 assert('test', {8 });9 });10});11import { assert } from 'storybook-root';12describe('test', () => {13 it('test', () => {14 assert('test', {15 });16 });17});18import { assert } from 'storybook-root';19describe('test', () => {20 it('test', () => {21 assert('test', {22 });23 });24});25import { assert } from 'storybook-root';26describe('test', () => {27 it('test', () => {28 assert('test', {29 });30 });31});32import { assert } from 'storybook-root';33describe('test', () => {34 it('test', () => {35 assert('test', {36 });37 });38});39import { assert } from 'storybook-root';40describe('test', () => {41 it('test', () => {42 assert('test', {43 });44 });45});46import { assert } from 'storybook-root';47describe('test', () => {48 it('test', () => {49 assert('test', {50 });51 });52});53import { assert } from 'storybook-root';54describe('test', () => {55 it('test', () => {56 assert('test', {57 });58 });59});

Full Screen

Using AI Code Generation

copy

Full Screen

1import {ensure} from '@storybook-root';2const {expect} = chai;3describe('test', () => {4 it('should work', () => {5 expect(ensure).to.be.a('function');6 });7});8import {ensure} from '@storybook-root';9const {expect} = chai;10describe('test', () => {11 it('should work', () => {12 expect(ensure).to.be.a('function');13 });14});15import {ensure} from '@storybook-root';16const {expect} = chai;17describe('test', () => {18 it('should work', () => {19 expect(ensure).to.be.a('function');20 });21});22import {ensure} from '@storybook-root';23const {expect} = chai;24describe('test', () => {25 it('should work', () => {26 expect(ensure).to.be.a('function');27 });28});29import {ensure} from '@storybook-root';30const {expect} = chai;31describe('test', () => {32 it('should work', () => {33 expect(ensure).to.be.a('function');34 });35});36import {ensure} from '@storybook-root';37const {expect} = chai;38describe('test', () => {39 it('should work', () => {40 expect(ensure).to.be.a('function');41 });42});43import {ensure} from '@storybook-root';44const {expect} = chai;45describe('test', () => {46 it('should work', () => {47 expect(ensure).to.be.a('function');48 });49});50import {ensure} from '@storybook-root';51const {expect} = chai;52describe('test', () => {53 it('should work', () => {54 expect(ensure).to.be.a('function');55 });56});

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 storybook-root 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