How to use memo method in Playwright Internal

Best JavaScript code snippet using playwright-internal

memo.actions.test.js

Source:memo.actions.test.js Github

copy

Full Screen

1import * as memoActions from './memo.actions'2import * as userActions from './user.actions'3import { MemoActionTypes } from './memo.actions'4import { verifyAction, mockStoreAndDispatch, getAction } from '../../test-utils/actions.test-helper'5import { testUsers, testMemos } from '../../test-utils/test-data'6import { combineMemoId } from '../reducers/memo.reducer'7import * as userSelectors from '../selectors/user.selector'8jest.mock('./user.actions', () => {9 const lib = require.requireActual('./user.actions')10 return { ...lib, getUsers: jest.fn().mockReturnValue({ type: 'USERS_RECEIVED' }) }11})12describe('memo actions', () => {13 describe('should create an action', () => {14 it('to indicate memos were received', () => {15 verifyAction(MemoActionTypes.MEMOS_RECEIVED, 'memos', () => memoActions.memosReceived('memos'))16 })17 it('to indicate the memo was updated', () => {18 verifyAction(MemoActionTypes.MEMO_UPDATED, 'memo', () => memoActions.memoUpdated('memo'))19 })20 it('to indicate a like was removed', () => {21 verifyAction(MemoActionTypes.LIKE_REMOVED, 'likeId', () => memoActions.likeRemoved('likeId'))22 })23 it('to indicate a memo was deleted', () => {24 verifyAction(MemoActionTypes.MEMO_DELETED, 'memoId', () => memoActions.memoDeleted('memoId'))25 })26 it('to indicate memo replies were received', () => {27 const payload = {28 memoId: 'memoId',29 replies: [],30 username: 'username'31 }32 expect(memoActions.memoRepliesReceived(payload.username, payload.memoId, payload.replies)).toEqual({33 type: MemoActionTypes.MEMO_REPLIES_RECEIVED,34 payload35 })36 })37 })38 describe('when dispatching action', () => {39 let spies40 let state41 const username = 'alice'42 beforeEach(async () => {43 spies = {44 getMemosForUser: jest.fn(),45 getMemos: jest.fn(),46 likeMemo: jest.fn(),47 removeLike: jest.fn(),48 getUserLikes: jest.fn(),49 getMemo: jest.fn(),50 replyToMemo: jest.fn(),51 getMemoReplies: jest.fn(),52 postMemo: jest.fn(),53 getUsers: jest.fn(),54 deleteMemo: jest.fn(),55 editMemo: jest.fn()56 }57 state = {58 root: {59 memoDashLib: {60 ...spies61 }62 },63 user: { currentUser: username, users: testUsers },64 memo: {65 memos: testMemos66 }67 }68 })69 describe('Memos', () => {70 const alice = testUsers['alice']71 let memos = []72 alice.memoIds.forEach(memoId => memos.push(testMemos[memoId]))73 describe('getMemosForUser(username)', () => {74 it('should call memoDashLib.getMemosForUser', async () => {75 await mockStoreAndDispatch(state, memoActions.getMemosForUser())76 expect(spies.getMemosForUser).toHaveBeenCalled()77 })78 it('should dispatch userUpdated', async () => {79 state.root.memoDashLib.getMemosForUser.mockReturnValue(memos)80 const actions = await mockStoreAndDispatch(state, memoActions.getMemosForUser(alice.username))81 expect(await getAction(actions, userActions.UserActionTypes.USER_UPDATED)).toEqual(82 userActions.userUpdated(alice.username, { memoIds: alice.memoIds })83 )84 })85 })86 describe('getMemos()', () => {87 it('should call memoDashLib.getMemos', async () => {88 await mockStoreAndDispatch(state, memoActions.getMemos())89 expect(spies.getMemos).toHaveBeenCalled()90 })91 describe('received memos', () => {92 const user = testUsers['alice']93 it('should dispatch memosReceived', async () => {94 state.root.memoDashLib.getMemos.mockReturnValue(memos)95 const actions = await mockStoreAndDispatch(state, memoActions.getMemos())96 expect(await getAction(actions, MemoActionTypes.MEMOS_RECEIVED)).toEqual(97 memoActions.memosReceived(memos)98 )99 })100 it('should dispatch getUsers', async () => {101 state.root.memoDashLib.getMemos.mockReturnValue(memos)102 userSelectors.getMissingUsers = jest.fn(() => jest.fn().mockReturnValue(['charlie']))103 const actions = await mockStoreAndDispatch(state, memoActions.getMemos())104 expect(await getAction(actions, userActions.UserActionTypes.USERS_RECEIVED)).toEqual(105 userActions.getUsers([user.username])106 )107 })108 it('should not dispatch getUsers if all users already available', async () => {109 state.root.memoDashLib.getMemos.mockReturnValue(memos)110 const actions = await mockStoreAndDispatch(state, memoActions.getMemos())111 expect(await getAction(actions, userActions.UserActionTypes.USERS_RECEIVED)).toEqual(112 userActions.getUsers([user.username])113 )114 })115 })116 describe('no memos received', () => {117 it('should not dispatch anything ', async () => {118 state.root.memoDashLib.getMemos.mockReturnValue(undefined)119 const actions = await mockStoreAndDispatch(state, memoActions.getMemos())120 expect(actions.length).toEqual(0)121 })122 })123 })124 describe('postMemo(message)', () => {125 it('should call memoDashLib.postMemo', async () => {126 const message = 'message'127 await mockStoreAndDispatch(state, memoActions.postMemo(message))128 expect(spies.postMemo).toHaveBeenCalledWith(message)129 })130 it('should dispatch getMemos', async () => {131 const message = 'message'132 await mockStoreAndDispatch(state, memoActions.postMemo(message))133 expect(spies.getMemos).toHaveBeenCalled()134 })135 })136 describe('likeMemo(username, memoId)', () => {137 const memoId = 1138 it('should call memoDashLib.likeMemo', async () => {139 await mockStoreAndDispatch(state, memoActions.likeMemo(username, memoId))140 expect(spies.likeMemo).toHaveBeenCalledWith(username, memoId)141 })142 it('should call memoDashLib.getMemo', async () => {143 await mockStoreAndDispatch(state, memoActions.likeMemo(username, memoId))144 expect(spies.getMemo).toHaveBeenCalledWith(username, memoId)145 })146 it('should dispatch memoUpdated', async () => {147 const memo = 'memo'148 state.root.memoDashLib.getMemo.mockReturnValue(memo)149 const actions = await mockStoreAndDispatch(state, memoActions.likeMemo())150 expect(await getAction(actions, MemoActionTypes.MEMO_UPDATED)).toEqual(151 memoActions.memoUpdated(memo)152 )153 })154 it('should dispatch likeAdded', async () => {155 const actions = await mockStoreAndDispatch(state, memoActions.likeMemo(username, memoId))156 expect(await getAction(actions, MemoActionTypes.LIKE_ADDED)).toEqual(memoActions.likeAdded())157 })158 })159 describe('removeLike(likeId)', () => {160 const alice = testUsers['alice']161 const likeToRemove = alice.likes[0]162 it('should call memoDashLib.removeLike', async () => {163 await mockStoreAndDispatch(164 state,165 memoActions.removeLike(alice.username, likeToRemove.relation.index)166 )167 expect(spies.removeLike).toHaveBeenCalledWith(likeToRemove.idx)168 })169 it('should call memoDashLib.getMemo', async () => {170 await mockStoreAndDispatch(171 state,172 memoActions.removeLike(alice.username, likeToRemove.relation.index)173 )174 expect(spies.getMemo).toHaveBeenCalledWith(alice.username, likeToRemove.relation.index)175 })176 it('should dispatch likeRemoved', async () => {177 const actions = await mockStoreAndDispatch(178 state,179 memoActions.removeLike(alice.username, likeToRemove.relation.index)180 )181 expect(await getAction(actions, MemoActionTypes.LIKE_REMOVED)).toEqual(182 memoActions.likeRemoved(likeToRemove.idx)183 )184 })185 it('should dispatch memoUpdated', async () => {186 const memo = testMemos[alice.memoIds[0]]187 state.root.memoDashLib.getMemo.mockReturnValue(memo)188 const actions = await mockStoreAndDispatch(189 state,190 memoActions.removeLike(alice.username, likeToRemove.relation.index)191 )192 expect(await getAction(actions, MemoActionTypes.MEMO_UPDATED)).toEqual(193 memoActions.memoUpdated(memo)194 )195 })196 })197 describe('replyToMemo(username, memoId, message)', () => {198 const alice = testUsers['alice']199 const memo = testMemos[alice.memoIds[0]]200 const replyMessage = 'replyMessage'201 it('should call memoDashLib.replyToMemo', async () => {202 await mockStoreAndDispatch(state, memoActions.replyToMemo(alice.username, memo.idx, replyMessage))203 expect(spies.replyToMemo).toHaveBeenCalledWith(alice.username, memo.idx, replyMessage)204 })205 it('should call memoDashLib.getMemo', async () => {206 await mockStoreAndDispatch(state, memoActions.replyToMemo(alice.username, memo.idx, replyMessage))207 expect(spies.getMemo).toHaveBeenCalledWith(alice.username, memo.idx)208 })209 it('should call memoDashLib.getMemoReplies', async () => {210 await mockStoreAndDispatch(state, memoActions.replyToMemo(alice.username, memo.idx, replyMessage))211 expect(spies.getMemoReplies).toHaveBeenCalledWith(alice.username, memo.idx)212 })213 it('should call memoDashLib.getMemosForUser', async () => {214 await mockStoreAndDispatch(state, memoActions.replyToMemo(alice.username, memo.idx, replyMessage))215 expect(spies.getMemosForUser).toHaveBeenCalledWith(alice.username)216 })217 it('should dispatch memoUpdated', async () => {218 state.root.memoDashLib.getMemo.mockReturnValue(memo)219 const actions = await mockStoreAndDispatch(220 state,221 memoActions.replyToMemo(alice.username, memo.idx, replyMessage)222 )223 expect(await getAction(actions, MemoActionTypes.MEMO_UPDATED)).toEqual(224 memoActions.memoUpdated(memo)225 )226 })227 })228 describe('getMemoReplies(username, memoId)', () => {229 const alice = testUsers['alice']230 const memo = testMemos[alice.memoIds[0]]231 it('should call memoDashLib.getMemoReplies', async () => {232 await mockStoreAndDispatch(state, memoActions.getMemoReplies(alice.username, memo.idx))233 expect(spies.getMemoReplies).toHaveBeenCalledWith(alice.username, memo.idx)234 })235 it('should dispatch memoRepliesReceived', async () => {236 state.root.memoDashLib.getMemoReplies.mockReturnValue([memo])237 const actions = await mockStoreAndDispatch(238 state,239 memoActions.getMemoReplies(alice.username, memo.idx)240 )241 expect(await getAction(actions, MemoActionTypes.MEMO_REPLIES_RECEIVED)).toEqual(242 memoActions.memoRepliesReceived(alice.username, memo.idx, [memo])243 )244 })245 })246 describe('deleteMemo(memoId)', () => {247 const alice = testUsers['alice']248 const memo = testMemos[alice.memoIds[0]]249 it('should call memoDashLib.deleteMemo', async () => {250 await mockStoreAndDispatch(state, memoActions.deleteMemo(memo.username, memo.idx))251 expect(spies.deleteMemo).toHaveBeenCalledWith(memo.idx)252 })253 it('should dispatch memoDeleted', async () => {254 const actions = await mockStoreAndDispatch(state, memoActions.deleteMemo(memo.username, memo.idx))255 expect(await getAction(actions, MemoActionTypes.MEMO_DELETED)).toEqual(256 memoActions.memoDeleted(combineMemoId(memo.username, memo.idx))257 )258 })259 })260 describe('editMemo(username, memoId, message)', () => {261 const alice = testUsers['alice']262 const memo = testMemos[alice.memoIds[0]]263 const newMessage = 'newMessage'264 it('should call memoDashLib.editMemo', async () => {265 await mockStoreAndDispatch(state, memoActions.editMemo(alice.username, memo.idx, newMessage))266 expect(spies.editMemo).toHaveBeenCalledWith(memo.idx, newMessage)267 })268 it('should dispatch memoUpdated', async () => {269 state.root.memoDashLib.getMemo.mockReturnValue(memo)270 const actions = await mockStoreAndDispatch(271 state,272 memoActions.replyToMemo(alice.username, memo.idx, newMessage)273 )274 expect(await getAction(actions, MemoActionTypes.MEMO_UPDATED)).toEqual(275 memoActions.memoUpdated(memo)276 )277 })278 })279 })280 })...

Full Screen

Full Screen

memo_test.js

Source:memo_test.js Github

copy

Full Screen

1describe("Memo.constructor()", function() {2 it("throws error when type is invalid", function() {3 expect(() => new StellarBase.Memo("test")).to.throw(/Invalid memo type/);4 });5});6describe("Memo.none()", function() {7 it("converts to/from xdr object", function() {8 let memo = StellarBase.Memo.none().toXDRObject();9 expect(memo.value()).to.be.undefined;10 let baseMemo = StellarBase.Memo.fromXDRObject(memo);11 expect(baseMemo.type).to.be.equal(StellarBase.MemoNone);12 expect(baseMemo.value).to.be.null;13 });14});15describe("Memo.text()", function() {16 it("returns a value for a correct argument", function() {17 expect(() => StellarBase.Memo.text("test")).to.not.throw();18 let memoUtf8 = StellarBase.Memo.text("三代之時")19 let a = new Buffer(memoUtf8.toXDRObject().value(), "utf8");20 let b = new Buffer("三代之時", "utf8");21 expect(a).to.be.deep.equal(b);22 });23 it("converts to/from xdr object", function() {24 let memo = StellarBase.Memo.text("test").toXDRObject();25 expect(memo.arm()).to.equal('text');26 expect(memo.text()).to.equal('test');27 expect(memo.value()).to.equal('test');28 let baseMemo = StellarBase.Memo.fromXDRObject(memo);29 expect(baseMemo.type).to.be.equal(StellarBase.MemoText);30 expect(baseMemo.value).to.be.equal('test');31 });32 it("throws an error when invalid argument was passed", function() {33 expect(() => StellarBase.Memo.text()).to.throw(/Expects string/);34 expect(() => StellarBase.Memo.text({})).to.throw(/Expects string/);35 expect(() => StellarBase.Memo.text(10)).to.throw(/Expects string/);36 expect(() => StellarBase.Memo.text(Infinity)).to.throw(/Expects string/);37 expect(() => StellarBase.Memo.text(NaN)).to.throw(/Expects string/);38 });39 it("throws an error when string is longer than 28 bytes", function() {40 expect(() => StellarBase.Memo.text("12345678901234567890123456789")).to.throw(/Text should be/);41 expect(() => StellarBase.Memo.text("三代之時三代之時三代之時")).to.throw(/Text should be/);42 });43});44describe("Memo.id()", function() {45 it("returns a value for a correct argument", function() {46 expect(() => StellarBase.Memo.id("1000")).to.not.throw();47 expect(() => StellarBase.Memo.id("0")).to.not.throw();48 });49 it("converts to/from xdr object", function() {50 let memo = StellarBase.Memo.id("1000").toXDRObject();51 expect(memo.arm()).to.equal('id');52 expect(memo.id().toString()).to.equal('1000');53 let baseMemo = StellarBase.Memo.fromXDRObject(memo);54 expect(baseMemo.type).to.be.equal(StellarBase.MemoID);55 expect(baseMemo.value).to.be.equal('1000');56 });57 it("throws an error when invalid argument was passed", function() {58 expect(() => StellarBase.Memo.id()).to.throw(/Expects a int64/);59 expect(() => StellarBase.Memo.id({})).to.throw(/Expects a int64/);60 expect(() => StellarBase.Memo.id(Infinity)).to.throw(/Expects a int64/);61 expect(() => StellarBase.Memo.id(NaN)).to.throw(/Expects a int64/);62 expect(() => StellarBase.Memo.id("test")).to.throw(/Expects a int64/);63 });64});65describe("Memo.hash() & Memo.return()", function() {66 it("hash converts to/from xdr object", function() {67 let buffer = new Buffer(32).fill(10);68 let memo = StellarBase.Memo.hash(buffer).toXDRObject();69 expect(memo.arm()).to.equal('hash');70 expect(memo.hash().length).to.equal(32);71 expect(memo.hash()).to.deep.equal(buffer);72 let baseMemo = StellarBase.Memo.fromXDRObject(memo);73 expect(baseMemo.type).to.be.equal(StellarBase.MemoHash);74 expect(baseMemo.value.length).to.equal(32);75 expect(baseMemo.value.toString('hex')).to.be.equal(buffer.toString('hex'));76 });77 it("return converts to/from xdr object", function() {78 let buffer = new Buffer(32).fill(10);79 // Testing string hash80 let memo = StellarBase.Memo.return(buffer.toString("hex")).toXDRObject();81 expect(memo.arm()).to.equal('retHash');82 expect(memo.retHash().length).to.equal(32);83 expect(memo.retHash().toString('hex')).to.equal(buffer.toString('hex'));84 let baseMemo = StellarBase.Memo.fromXDRObject(memo);85 expect(baseMemo.type).to.be.equal(StellarBase.MemoReturn);86 expect(Buffer.isBuffer(baseMemo.value)).to.be.true;87 expect(baseMemo.value.length).to.equal(32);88 expect(baseMemo.value.toString('hex')).to.be.equal(buffer.toString('hex'));89 });90 var methods = [StellarBase.Memo.hash, StellarBase.Memo.return];91 it("returns a value for a correct argument", function() {92 for (let i in methods) {93 let method = methods[i];94 expect(() => method(new Buffer(32))).to.not.throw();95 expect(() => method('0000000000000000000000000000000000000000000000000000000000000000')).to.not.throw();96 }97 });98 it("throws an error when invalid argument was passed", function() {99 for (let i in methods) {100 let method = methods[i];101 expect(() => method()).to.throw(/Expects a 32 byte hash value/);102 expect(() => method({})).to.throw(/Expects a 32 byte hash value/);103 expect(() => method(Infinity)).to.throw(/Expects a 32 byte hash value/);104 expect(() => method(NaN)).to.throw(/Expects a 32 byte hash value/);105 expect(() => method("test")).to.throw(/Expects a 32 byte hash value/);106 expect(() => method([0, 10, 20])).to.throw(/Expects a 32 byte hash value/);107 expect(() => method(new Buffer(33))).to.throw(/Expects a 32 byte hash value/);108 expect(() => method('00000000000000000000000000000000000000000000000000000000000000')).to.throw(/Expects a 32 byte hash value/);109 expect(() => method('000000000000000000000000000000000000000000000000000000000000000000')).to.throw(/Expects a 32 byte hash value/);110 }111 });...

Full Screen

Full Screen

base.js

Source:base.js Github

copy

Full Screen

1/**2 * 3 */4(function ($) {5 $('#memoContent').richText();6 7 $(".file-form").addClass("d-none");8 $(".custom-file-input").on("change", function() {9 var fileName = $(this).val().split("\\").pop();10 $(this).siblings(".custom-file-label").addClass("selected").html(fileName);11 });12 13 $(".file-form").addClass("d-none");14 $('#memoType').change(function(){15 if(!($(this).val() == 'photo')){16 $(".file-form").addClass("d-none");17 }else{18 $(".file-form").removeClass("d-none");19 }20 })21 22 $('#memoEnter').click(function(){23 let memoType = $('#memoType').val();24 let memoTitle = $('#memoTitle').val();25 let memoContent = $('.richText-editor').html();26 params = new FormData();27 params.set('memoType', memoType);28 params.set('memoPhoto', $('#memoPhoto')[0].files[0]);29 params.set('memoTitle', memoTitle);30 params.set('memoContent', memoContent);31 32 let result = false;33 if($(this).data('isNew') && memoType == 'photo'){34 result = !memoType || !memoTitle || !memoContent || !$('#memoPhoto').val();35 }else{36 result = !memoType || !memoTitle || !memoContent37 }38 39 if(result){40 return false;41 } 42 $.ajax({43 type: "POST",44 url: '/memo/insert',45 data : params,46 processData : false,47 contentType : false,48 success: function (data) {49 $('#MemoModal').modal('hide');50 51 setMemo();52 },53 error: function (jqXHR, textStatus, errorThrown) {54 console.log(jqXHR.status);55 console.debug(jqXHR.responseText);56 console.log(errorThrown);57 }58 })59 })60 61 $('#memoUpdate').click(function(){62 let memoType = $('#memoType').val();63 let memoTitle = $('#memoTitle').val();64 let memoContent = $('.richText-editor').html();65 let memoObjectId = $('#MemoModal').data('memoObjectId');66 params = new FormData();67 params.set('memoObjectId', memoObjectId == undefined ? '' : memoObjectId);68 params.set('memoType', memoType);69 params.set('memoPhoto', $('#memoPhoto')[0].files[0]);70 params.set('memoTitle', memoTitle);71 params.set('memoContent', memoContent);72 73 let result = false;74 if($(this).data('isNew') && memoType == 'photo'){75 result = !memoType || !memoTitle || !memoContent || !$('#memoPhoto').val();76 }else{77 result = !memoType || !memoTitle || !memoContent78 }79 80 if(result){81 return false;82 } 83 $.ajax({84 type: "POST",85 url: '/memo/update',86 data : params,87 processData : false,88 contentType : false,89 success: function (data) {90 $('#MemoModal').modal('hide');91 92 setMemo();93 },94 error: function (jqXHR, textStatus, errorThrown) {95 console.log(jqXHR.status);96 console.debug(jqXHR.responseText);97 console.log(errorThrown);98 }99 })100 })101 $('#memoDelete').click(function(){102 let params = $('#MemoModal').data('memoObjectId');103 $.ajax({104 type: "delete",105 url: '/memo/delete/'+params,106 data: JSON.stringify(params),107 dataType: 'json',108 success: function (data) {109 $('#MemoModal').modal('hide');110 111 setMemo();112 },113 error: function (jqXHR, textStatus, errorThrown) {114 console.log(jqXHR.status);115 console.debug(jqXHR.responseText);116 console.log(errorThrown);117 }118 })119 });120 121 $('#MemoModal').data('isNew', true);122 $('#MemoModal').on('show.bs.modal', function(){123 if(!$(this).data('isNew')){124 $('#MemoModal .modal-header .modal-title').html('EDIT MEMO');125 }126 })127 $('#MemoModal').on('hide.bs.modal', function(){128 $('#memoEnter').removeClass('d-none');129 $('#memoUpdate').addClass('d-none');130 $('#memoDelete').addClass('d-none');131 132 $('#memoType').val('');133 $('#memoTitle').val('');134 $('#memoContent').val('');135 $('.richText-editor').html('');136 $('#memoPhoto').val('');137 $('#MemoModal .modal-header .modal-title').html('NEW MEMO');138 $(".custom-file-label").html('MEMO PHOTO');139 $(this).data('isNew', true);140 $(this).data('memoObjectId', '');141 })142}(jQuery));143function hexToRgbNew(hex) {144 var arrBuff = new ArrayBuffer(4);145 var vw = new DataView(arrBuff);146 vw.setUint32(0,parseInt(hex, 16),false);147 var arrByte = new Uint8Array(arrBuff);148 149 return arrByte[1] + "," + arrByte[2] + "," + arrByte[3];150}151const rgbToHex = (r, g, b) => '#' + [r, g, b].map(x => {152 const hex = x.toString(16)153 return hex.length === 1 ? '0' + hex : hex154 }).join('');155function rgbTorgba(rgb, opacity){156 return 'rgba('+rgb+',' + opacity + ')'157}158function hexTorgba(h, opacity){159 let r = 0, g = 0, b = 0;160 161 // 3 digits162 if (h.length == 4) {163 r = "0x" + h[1] + h[1];164 g = "0x" + h[2] + h[2];165 b = "0x" + h[3] + h[3];166 167 // 6 digits168 } else if (h.length == 7) {169 r = "0x" + h[1] + h[2];170 g = "0x" + h[3] + h[4];171 b = "0x" + h[5] + h[6];172 }173 r = Number(r);174 g = Number(g);175 b = Number(b);176 return 'rgba(' + r + ',' + g + ',' + b + ',' + opacity + ')';177}178$('#MemoModalOpenBtn').click(function(){179 $('#MemoModal').modal('show');...

Full Screen

Full Screen

postMemo.js

Source:postMemo.js Github

copy

Full Screen

1function createMemoFromQE() {2 var textArea = document.getElementById('quick_entry_textarea');3 var text = textArea.value.trim();4 if (text.length === 0)5 return;6 var bucket;7 switch (nav.getBucket()) {8 case BUCKET_JOURNAL:9 bucket = BUCKET_JOURNAL;10 break;11 default:12 bucket = BUCKET_HOT_LIST;13 break;14 }15 createMemo(text, false, bucket, false, false, false).then(function() {16 activateQuickEntry(false, true);17 });18}19function getBucketFromClass(className) {20 var res = className.match(/bucket([0-9]+)/);21 if (res)22 return parseInt(res[1]);23 else24 return BUCKET_NONE;25}26function createMemoFromForm(textArea, toolbar) {27 return createMemo(28 textArea.value,29 toolbar.classList.contains("star"),30 getBucketFromClass(toolbar.className),31 toolbar.classList.contains("private"),32 toolbar.classList.contains("can_edit"),33 toolbar.classList.contains("sync_buckets")34 ).catch(function () {35 alertBox.showAlert("Error creating memo.");36 });37}38function editMemoFromForm(id, textArea, toolbar) {39 return editMemo(40 id,41 textArea.value,42 toolbar.classList.contains("star"),43 getBucketFromClass(toolbar.className),44 toolbar.classList.contains("private"),45 toolbar.classList.contains("can_edit"),46 toolbar.classList.contains("sync_buckets")47 ).catch(function () {48 alertBox.showAlert("Error editing memo.");49 });50}51function createMemo(text, star, bucket, priv, friendsCanEdit, syncBuckets) {52 // Check for shortcut chars53 if (text.length > 3) {54 var origMemoText = text;55 var charsToTrim = 0;56 for (var i = 0; i < 3; ++i) {57 switch (text.slice(i, i + 1)) {58 case "*":59 star = true;60 ++charsToTrim;61 break;62 case "^":63 priv = true;64 ++charsToTrim;65 break;66 case "&":67 friendsCanEdit = true;68 ++charsToTrim;69 break;70 default:71 i = 3;72 break;73 }74 }75 text = text.slice(charsToTrim).trim();76 if (text.length === 0) {77 text = origMemoText;78 star = false;79 }80 }8182 return frogDB.getTempMemoId().then(function(id) {83 var newMemoData = {};84 newMemoData.memoId = id;85 newMemoData[KEY_MEMO_TEXT] = text;86 newMemoData[KEY_MEMO_PRIVATE] = priv;87 newMemoData[KEY_MEMO_SHARED] = false;88 newMemoData[KEY_MEMO_SYNC_BUCKETS] = syncBuckets;89 newMemoData[KEY_MEMO_FRIENDS_CAN_EDIT] = friendsCanEdit;90 newMemoData[KEY_MEMO_ALARM] = null;91 newMemoData[KEY_MEMO_BUCKET] = bucket;92 newMemoData[KEY_MEMO_EDITED] = false;93 newMemoData[KEY_MEMO_STAR] = star;94 newMemoData[KEY_MEMO_CAN_EDIT] = true;95 newMemoData[KEY_MEMO_AUTHOR_NAME] = "";96 newMemoData[KEY_MEMO_IS_AUTHOR] = true;97 newMemoData.createDate = newMemoData.moveDate = newMemoData.editDate = utcDateString();98 newMemoData[KEY_MEMO_IS_HISTORIC] = false;99100 var newMemo = new Memo(newMemoData, false);101102 // update UI103 newMemo.insertIntoMemoList();104105 // Update data106 return doMemoChange(POST_CREATE_MEMO, id, newMemo, false);107 });108}109function editMemo(id, text, star, bucket, priv, friendsCanEdit, syncBuckets) {110 return frogDB.fetchMemo(id, false).then(function (m) {111 if (m) {112 m.text = text;113 m.star = star;114 m.setBucket(bucket);115 m.priv = priv;116 m.friendsCanEdit = friendsCanEdit;117 m.syncBuckets = syncBuckets;118 m.edited = true;119 m.editDate = utcDateString();120 m._reset();121 return doMemoChange(POST_EDIT_MEMO, m.id, m, false);122 } else {123 console.error("Could not retrieve memo " + id.toString() + " for editing.");124 return Dexie.Promise.reject();125 }126 }); ...

Full Screen

Full Screen

memo.actions.js

Source:memo.actions.js Github

copy

Full Screen

1import { getMemoDashLib, getCurrentUser, getMissingUsers, getCurrentUsername } from '../selectors'2import { userUpdated, getUsers } from './user.actions'3import { combineMemoId } from '../reducers/memo.reducer'4export const MemoActionTypes = {5 MEMOS_RECEIVED: 'MEMOS_RECEIVED',6 MEMO_UPDATED: 'MEMO_UPDATED',7 MEMO_REPLIES_RECEIVED: 'MEMO_REPLIES_RECEIVED',8 LIKE_REMOVED: 'LIKE_REMOVED',9 LIKE_ADDED: 'LIKE_ADDED',10 MEMO_DELETED: 'MEMO_DELETED'11}12export const getMemosForUser = username => async (dispatch, getState) => {13 const memos = await getMemoDashLib(getState()).getMemosForUser(username)14 if (memos) {15 dispatch(memosReceived(memos))16 const memoIds = memos.map(memo => combineMemoId(memo.username, memo.idx))17 dispatch(userUpdated(username, { memoIds }))18 }19}20export const getMemos = memoIds => async (dispatch, getState) => {21 const state = getState()22 const memos = await getMemoDashLib(state).getMemos(memoIds)23 if (memos) {24 dispatch(memosReceived(memos))25 const usernames = getMissingUsers(memos.map(memo => memo.username))(state)26 if (usernames && usernames.length > 0) {27 dispatch(getUsers(usernames))28 }29 }30}31export const memosReceived = memos => ({32 type: MemoActionTypes.MEMOS_RECEIVED,33 payload: memos34})35export const likeMemo = (username, memoId) => async (dispatch, getState) => {36 const lib = getMemoDashLib(getState())37 await lib.likeMemo(username, memoId)38 const currentUsername = getCurrentUsername(getState())39 const likes = await lib.getUserLikes(currentUsername)40 await dispatch(likeAdded(likes))41 const memo = await lib.getMemo(username, memoId)42 dispatch(memoUpdated(memo))43}44export const removeLike = (username, memoId) => async (dispatch, getState) => {45 const lib = getMemoDashLib(getState())46 const currentUser = getCurrentUser(getState())47 if (currentUser) {48 const like = currentUser.likes.find(like => like.relation.index === memoId)49 if (like) {50 await lib.removeLike(like.idx)51 await dispatch(likeRemoved(like.idx))52 const memo = await lib.getMemo(username, memoId)53 dispatch(memoUpdated(memo))54 }55 }56}57export const likeAdded = likeId => ({58 type: MemoActionTypes.LIKE_ADDED,59 payload: likeId60})61export const likeRemoved = likeId => ({62 type: MemoActionTypes.LIKE_REMOVED,63 payload: likeId64})65export const replyToMemo = (username, memoId, message) => async (dispatch, getState) => {66 const lib = getMemoDashLib(getState())67 await lib.replyToMemo(username, memoId, message)68 const memo = await lib.getMemo(username, memoId)69 dispatch(memoUpdated(memo))70 dispatch(getMemoReplies(username, memoId))71 const currentUsername = getCurrentUsername(getState())72 dispatch(getMemosForUser(currentUsername))73}74export const memoUpdated = memo => ({75 type: MemoActionTypes.MEMO_UPDATED,76 payload: memo77})78export const getMemoReplies = (username, memoId) => async (dispatch, getState) => {79 const lib = getMemoDashLib(getState())80 const replies = await lib.getMemoReplies(username, memoId)81 dispatch(memoRepliesReceived(username, memoId, replies))82}83export const memoRepliesReceived = (username, memoId, replies) => ({84 type: MemoActionTypes.MEMO_REPLIES_RECEIVED,85 payload: { username, memoId, replies }86})87export const postMemo = message => async (dispatch, getState) => {88 const lib = getMemoDashLib(getState())89 await lib.postMemo(message)90 dispatch(getMemos())91}92export const deleteMemo = (username, memoId) => async (dispatch, getState) => {93 const lib = getMemoDashLib(getState())94 await lib.deleteMemo(memoId)95 dispatch(memoDeleted(combineMemoId(username, memoId)))96}97export const memoDeleted = memoId => ({98 type: MemoActionTypes.MEMO_DELETED,99 payload: memoId100})101export const editMemo = (username, memoId, message) => async (dispatch, getState) => {102 const lib = getMemoDashLib(getState())103 await lib.editMemo(memoId, message)104 const memo = await lib.getMemo(username, memoId)105 dispatch(memoUpdated(memo))...

Full Screen

Full Screen

memo.js

Source:memo.js Github

copy

Full Screen

1import ByteBuffer from 'bytebuffer'2import assert from 'assert'3import base58 from 'bs58'4import {Aes, PrivateKey, PublicKey} from './ecc'5import {ops} from './serializer'6const encMemo = ops.encrypted_memo7/**8 Some fields are only required if the memo is marked for decryption (starts with a hash).9 @arg {string|PrivateKey} private_key - WIF or PrivateKey object10 @arg {string} memo - plain text is returned, hash prefix base58 is decrypted11 @return {string} - utf8 decoded string (hash prefix)12*/13export function decode(private_key, memo) {14 assert(memo, 'memo is required')15 assert.equal(typeof memo, 'string', 'memo')16 if(!/^#/.test(memo)) return memo17 memo = memo.substring(1)18 assert(private_key, 'private_key is required')19 checkEncryption()20 private_key = toPrivateObj(private_key)21 memo = base58.decode(memo)22 memo = encMemo.fromBuffer(new Buffer(memo, 'binary'))23 const {from, to, nonce, check, encrypted} = memo24 const pubkey = private_key.toPublicKey().toString()25 const otherpub = pubkey === from.toString() ? to.toString() : from.toString()26 memo = Aes.decrypt(private_key, otherpub, nonce, encrypted, check)27 // remove varint length prefix28 const mbuf = ByteBuffer.fromBinary(memo.toString('binary'), ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)29 try {30 mbuf.mark()31 return '#' + mbuf.readVString()32 } catch(e) {33 mbuf.reset()34 // Sender did not length-prefix the memo35 memo = new Buffer(mbuf.toString('binary'), 'binary').toString('utf-8')36 return '#' + memo37 }38}39/**40 Some fields are only required if the memo is marked for encryption (starts with a hash).41 @arg {string|PrivateKey} private_key - WIF or PrivateKey object42 @arg {string|PublicKey} public_key - Recipient43 @arg {string} memo - plain text is returned, hash prefix text is encrypted44 @arg {string} [testNonce = undefined] - just for testing45 @return {string} - base64 decoded string (or plain text)46*/47export function encode(private_key, public_key, memo, testNonce) {48 assert(memo, 'memo is required')49 assert.equal(typeof memo, 'string', 'memo')50 if(!/^#/.test(memo)) return memo51 memo = memo.substring(1)52 assert(private_key, 'private_key is required')53 assert(public_key, 'public_key is required')54 checkEncryption()55 private_key = toPrivateObj(private_key)56 public_key = toPublicObj(public_key)57 const mbuf = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN)58 mbuf.writeVString(memo)59 memo = new Buffer(mbuf.copy(0, mbuf.offset).toBinary(), 'binary')60 const {nonce, message, checksum} = Aes.encrypt(private_key, public_key, memo, testNonce)61 memo = encMemo.fromObject({62 from: private_key.toPublicKey(),63 to: public_key,64 nonce,65 check: checksum,66 encrypted: message67 })68 // serialize69 memo = encMemo.toBuffer(memo)70 return '#' + base58.encode(new Buffer(memo, 'binary'))71}72let encodeTest = undefined73/**74 Memo encryption has failed in the browser before. An Error will be thrown75 if a memo can't be encrypted and decrypted.76*/77function checkEncryption() {78 if(encodeTest === undefined) {79 let plaintext;80 encodeTest = true // prevent infinate looping81 try {82 const wif = '5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw'83 const pubkey = 'STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA'84 const cyphertext = encode(wif, pubkey, '#memo爱')85 plaintext = decode(wif, cyphertext)86 } catch(e) {87 console.error(e);88 } finally {89 encodeTest = plaintext === '#memo爱'90 }91 }92 if(encodeTest === false)93 throw new Error('This environment does not support encryption.')94}95const toPrivateObj = o => (o ? o.d ? o : PrivateKey.fromWif(o) : o/*null or undefined*/)...

Full Screen

Full Screen

problems.js

Source:problems.js Github

copy

Full Screen

1// Write a function, lucasNumberMemo(n), that takes in a number.2// The function should return the n-th number of the Lucas Sequence.3// The 0-th number of the Lucas Sequence is 2.4// The 1-st number of the Lucas Sequence is 15// To generate the next number of the sequence, we add up the previous two numbers.6//7// For example, the sequence begins: 2, 1, 3, 4, 7, 11, ...8//9// Solve this recursively with memoization.10//11// Examples:12//13// lucasNumberMemo(0) // => 214// lucasNumberMemo(1) // => 115// lucasNumberMemo(40) // => 22882612716// lucasNumberMemo(41) // => 37024845117// lucasNumberMemo(42) // => 59907457818function lucasNumberMemo(n, memo = {}) {19 if (n in memo) return memo[n];20 if (n === 0) return 2;21 if (n === 1) return 1;22 memo[n] = lucasNumberMemo(n - 1, memo) + lucasNumberMemo(n - 2, memo);23 return memo[n];24}25// Write a function, minChange(coins, amount), that accepts an array of coin values26// and a target amount as arguments. The method should the minimum number of coins needed27// to make the target amount. A coin value can be used multiple times.28//29// After you pass the first 3 examples, you'll likely need to memoize your code 30// in order to pass the 4th example in a decent runtime.31//32// Examples:33// 34// minChange([1, 2, 5], 11) // => 3, because 5 + 5 + 1 = 1135// minChange([1, 4, 5], 8)) // => 2, because 4 + 4 = 836// minChange([1, 5, 10, 25], 15) // => 2, because 10 + 5 = 1537// minChange([1, 5, 10, 25], 100) // => 4, because 25 + 25 + 25 + 25 = 10038function minChange(coins, amount, memo = {}) {39 if (amount in memo) return memo[amount];40 if (amount === 0) return 0;41 let numCoins = [];42 for (coin of coins) {43 if (coin <= amount) {44 numCoins.push(minChange(coins, amount - coin, memo) + 1);45 }46 }47 memo[amount] = Math.min(...numCoins);48 return memo[amount];49}50module.exports = {51 lucasNumberMemo,52 minChange...

Full Screen

Full Screen

memoOperations.js

Source:memoOperations.js Github

copy

Full Screen

1import {OperationBase} from "./operationBase";2import {memoService} from "../services/application/memoService";3class MemoOperations extends OperationBase {4 constructor(signer = null, apiClient = null) {5 super(signer)6 this.apiClient = apiClient7 }8 createMemo(memoType, memoString) {9 if("string" !== typeof memoType || "string" !== typeof memoString) {10 throw new Error("invalid param")11 }12 let newMemo = new memoService.dataTypes.Memo(memoType, memoString)13 newMemo.sign(this.cryptoTools())14 return newMemo15 }16 async recordMemo(memoType, memoString) {17 if("string" !== typeof memoType || "string" !== typeof memoString) {18 throw new Error("invalid param")19 }20 let newMemo = new memoService.dataTypes.Memo(memoType, memoString)21 let memoReq = memoService.requests.newMemoRecord(newMemo, this.cryptoTools())22 return await this.apiClient.callApplication(memoReq.toJSON())23 }24}25export {26 MemoOperations...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const path = require('path');3(async () => {4 const browser = await chromium.launch({ headless: false, slowMo: 1000 });5 const context = await browser.newContext({6 recordVideo: {7 dir: path.join(__dirname, 'videos'),8 },9 });10 const page = await context.newPage();11 await page.fill('input[name="q"]', 'Playwright');12 await page.click('input[type="submit"]');13 await page.waitForSelector('text=Playwright');14 await page.click('text=Playwright');15 await page.waitForSelector('text=Test automation framework');16 await page.click('text=Test automation framework');17 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit');18 await page.click('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit');19 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API. Use the same API to automate across all modern browsers. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');20 await page.click('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API. Use the same API to automate across all modern browsers. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');21 await page.waitForSelector('text=Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');22 await page.click('text=Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');23 await page.waitForSelector('text=Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');24 await page.click('text=Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');25 await page.waitForSelector('text=Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');26 await page.click('text=Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false, slowMo: 100, args: ['--start-maximized'] });4 const context = await browser.newContext({ recordVideo: { dir: 'videos/' } });5 const page = await context.newPage();6 await page.fill('input[title="Search"]', 'Playwright');7 await page.click('input[value="Google Search"]');8 await page.waitForSelector('text=Playwright');9 await page.click('text=Playwright');10 await page.screenshot({ path: `example.png` });11 await browser.close();12})();13module.exports = {14 launchOptions: {15 recordVideo: { dir: 'videos/' },16 },17 contextOptions: { ignoreHTTPSErrors: true },18};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { memo } = require('@playwright/test/lib/memo');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const title = await page.title();5 await memo(page, 'title', title);6 await page.click('text=Get started');7 const newTitle = await page.title();8 await memo(page, 'title', newTitle);9 const storedTitle = await memo(page, 'title');10 console.log('storedTitle', storedTitle);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { memo } = require('@playwright/test');2const { chromium } = require('playwright');3const { expect } = require('@playwright/test');4const { test } = require('@playwright/test');5const browser = memo(async () => {6 const browser = await chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 return page;10});11test.use({ browser });12test('Test 1', async ({ browser }) => {13 const title = await browser.title();14 expect(title).toBe('Playwright');15});16test('Test 2', async ({ browser }) => {17 const title = await browser.title();18 expect(title).toBe('Playwright');19});20test('Test 3', async ({ browser }) => {21 const title = await browser.title();22 expect(title).toBe('Playwright');23});24test('Test 4', async ({ browser }) => {25 const title = await browser.title();26 expect(title).toBe('Playwright');27});28test('Test 5', async ({ browser }) => {29 const title = await browser.title();30 expect(title).toBe('Playwright');31});32test('Test 6', async ({ browser }) => {33 const title = await browser.title();34 expect(title).toBe('Playwright');35});36test('Test 7', async ({ browser }) => {37 const title = await browser.title();38 expect(title).toBe('Playwright');39});40test('Test

Full Screen

Using AI Code Generation

copy

Full Screen

1const { memo } = require('@playwright/test/lib/test');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4});5const { memo } = require('@playwright/test/lib/test');6const { test } = require('@playwright/test');7test('test', async ({ page }) => {8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { memo } = require('playwright/lib/utils/memoize');2const memoizedFunction = memo(function() {3 return 'Hello World';4});5const result = memoizedFunction();6console.log(result);7Contributions are welcome! Please see [CONTRIBUTING.md](

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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