How to use initState method in Playwright Internal

Best JavaScript code snippet using playwright-internal

index.test.js

Source:index.test.js Github

copy

Full Screen

1import configureMockStore from "redux-mock-store";2import thunk from "redux-thunk";3import cloudreveApp, { initState as cloudreveState } from "./index";4import { initState as viewUpdateState } from "../redux/viewUpdate/reducer";5import { initState as explorerState } from "../redux/explorer/reducer";6import {7 setModalsLoading,8 openLoadingDialog,9 openGetSourceDialog,10 openShareDialog,11 openMoveDialog,12 navigateUp,13 navigateTo,14 drawerToggleAction,15 changeViewMethod,16 changeContextMenu,17 dragAndDrop,18 setNavigatorLoadingStatus,19 setNavigatorError,20 addSelectedTargets,21 setNavigator,22 setSelectedTarget,23 removeSelectedTargets,24 toggleDaylightMode,25 applyThemes,26 openCreateFolderDialog,27 openRenameDialog,28 openRemoveDialog,29 openResaveDialog,30 setUserPopover,31 setShareUserPopover,32 setSiteConfig,33 openMusicDialog,34 openRemoteDownloadDialog,35 openTorrentDownloadDialog,36 openDecompressDialog,37 openCompressDialog,38 openCopyDialog,39 closeAllModals,40 toggleSnackbar,41 setSessionStatus,42 enableLoadUploader,43 refreshFileList,44 searchMyFile,45 showImgPreivew,46 refreshStorage,47 saveFile,48 setLastSelect,49 setShiftSelectedIds,50} from "../actions/index";51import { changeSubTitle, setSubtitle } from "../redux/viewUpdate/action";52import {53 updateFileList,54 setFileList,55 setDirList,56 setSortMethod,57 changeSortMethod,58} from "../redux/explorer/action";59const initState = {60 ...cloudreveState,61 viewUpdate: viewUpdateState,62 explorer: explorerState,63};64const middlewares = [thunk];65const mockStore = configureMockStore(middlewares);66describe("index reducer", () => {67 it("should return the initial state", () => {68 expect(cloudreveApp(undefined, { type: "@@INIT" })).toEqual(initState);69 });70 it("should handle redux init", () => {71 expect(cloudreveApp(undefined, { type: "@@redux/INIT" })).toEqual(72 initState73 );74 });75 it("should handle DRAWER_TOGGLE", () => {76 const openAction = drawerToggleAction(true);77 expect(cloudreveApp(initState, openAction)).toEqual({78 ...initState,79 viewUpdate: {80 ...initState.viewUpdate,81 open: true,82 },83 });84 const clossAction = drawerToggleAction(false);85 expect(cloudreveApp(initState, clossAction)).toEqual({86 ...initState,87 viewUpdate: {88 ...initState.viewUpdate,89 open: false,90 },91 });92 });93 it("should handle CHANGE_VIEW_METHOD", () => {94 const action = changeViewMethod("list");95 expect(cloudreveApp(initState, action)).toEqual({96 ...initState,97 viewUpdate: {98 ...initState.viewUpdate,99 explorerViewMethod: "list",100 },101 });102 });103 it("should handle SET_SORT_METHOD", () => {104 const action = setSortMethod("sizeRes");105 expect(cloudreveApp(initState, action)).toEqual({106 ...initState,107 viewUpdate: {108 ...initState.viewUpdate,109 sortMethod: "sizeRes",110 },111 });112 });113 describe("CHANGE_SORT_METHOD", () => {114 const explorerState = {115 fileList: [116 {117 type: "file",118 name: "b",119 size: 10,120 date: "2020/04/30",121 },122 {123 type: "file",124 name: "a",125 size: 11,126 date: "2020/05/01",127 },128 {129 type: "file",130 name: "z",131 size: 110,132 date: "2020/04/29",133 },134 ],135 dirList: [136 {137 type: "dir",138 name: "b_dir",139 size: 10,140 date: "2020/04/30",141 },142 {143 type: "dir",144 name: "a_dir",145 size: 11,146 date: "2020/05/01",147 },148 {149 type: "dir",150 name: "z_dir",151 size: 110,152 date: "2020/04/29",153 },154 ],155 };156 const state = {157 ...initState,158 explorer: {159 ...initState.explorer,160 ...explorerState,161 },162 };163 it("should handle sizePos", async () => {164 const action = changeSortMethod("sizePos");165 const sortFunc = (a, b) => {166 return a.size - b.size;167 };168 const fileList = explorerState.fileList;169 const dirList = explorerState.dirList;170 const store = mockStore(state);171 await store.dispatch(action);172 expect(store.getActions()).toEqual([173 setSortMethod("sizePos"),174 setDirList(dirList.sort(sortFunc)),175 setFileList(fileList.sort(sortFunc)),176 ]);177 });178 it("should handle sizeRes", async () => {179 const action = changeSortMethod("sizePos");180 const sortFunc = (a, b) => {181 return b.size - a.size;182 };183 const fileList = explorerState.fileList;184 const dirList = explorerState.dirList;185 const store = mockStore(state);186 await store.dispatch(action);187 expect(store.getActions()).toEqual([188 setSortMethod("sizePos"),189 setDirList(dirList.sort(sortFunc)),190 setFileList(fileList.sort(sortFunc)),191 ]);192 });193 it("should handle namePos", async () => {194 const action = changeSortMethod("namePos");195 const sortFunc = (a, b) => {196 return a.name.localeCompare(b.name);197 };198 const fileList = explorerState.fileList;199 const dirList = explorerState.dirList;200 const store = mockStore(state);201 await store.dispatch(action);202 expect(store.getActions()).toEqual([203 setSortMethod("namePos"),204 setDirList(dirList.sort(sortFunc)),205 setFileList(fileList.sort(sortFunc)),206 ]);207 });208 it("should handle nameRev", async () => {209 const action = changeSortMethod("nameRev");210 const sortFunc = (a, b) => {211 return b.name.localeCompare(a.name);212 };213 const fileList = explorerState.fileList;214 const dirList = explorerState.dirList;215 const store = mockStore(state);216 await store.dispatch(action);217 expect(store.getActions()).toEqual([218 setSortMethod("nameRev"),219 setDirList(dirList.sort(sortFunc)),220 setFileList(fileList.sort(sortFunc)),221 ]);222 });223 it("should handle timePos", async () => {224 const action = changeSortMethod("timePos");225 const sortFunc = (a, b) => {226 return Date.parse(a.date) - Date.parse(b.date);227 };228 const fileList = explorerState.fileList;229 const dirList = explorerState.dirList;230 const store = mockStore(state);231 await store.dispatch(action);232 expect(store.getActions()).toEqual([233 setSortMethod("timePos"),234 setDirList(dirList.sort(sortFunc)),235 setFileList(fileList.sort(sortFunc)),236 ]);237 });238 it("should handle timeRev", async () => {239 const action = changeSortMethod("timeRev");240 const sortFunc = (a, b) => {241 return Date.parse(b.date) - Date.parse(a.date);242 };243 const fileList = explorerState.fileList;244 const dirList = explorerState.dirList;245 const store = mockStore(state);246 await store.dispatch(action);247 expect(store.getActions()).toEqual([248 setSortMethod("timeRev"),249 setDirList(dirList.sort(sortFunc)),250 setFileList(fileList.sort(sortFunc)),251 ]);252 });253 });254 it("should handle CHANGE_CONTEXT_MENU", () => {255 const action1 = changeContextMenu("empty", false);256 expect(cloudreveApp(initState, action1)).toEqual({257 ...initState,258 viewUpdate: {259 ...initState.viewUpdate,260 contextOpen: false,261 contextType: "empty",262 },263 });264 const action2 = changeContextMenu("aa", true);265 expect(cloudreveApp(initState, action2)).toEqual({266 ...initState,267 viewUpdate: {268 ...initState.viewUpdate,269 contextOpen: true,270 contextType: "aa",271 },272 });273 });274 it("should handle DRAG_AND_DROP", () => {275 const action = dragAndDrop("source", "target");276 expect(cloudreveApp(initState, action)).toEqual({277 ...initState,278 explorer: {279 ...initState.explorer,280 dndSignal: true,281 dndTarget: "target",282 dndSource: "source",283 },284 });285 });286 it("should handle SET_NAVIGATOR_LOADING_STATUE", () => {287 const action = setNavigatorLoadingStatus(true);288 expect(cloudreveApp(initState, action)).toEqual({289 ...initState,290 viewUpdate: {291 ...initState.viewUpdate,292 navigatorLoading: true,293 },294 });295 });296 it("should handle SET_NAVIGATOR_ERROR", () => {297 const action = setNavigatorError(true, "Error Message");298 expect(cloudreveApp(initState, action)).toEqual({299 ...initState,300 viewUpdate: {301 ...initState.viewUpdate,302 navigatorError: true,303 navigatorErrorMsg: "Error Message",304 },305 });306 });307 describe("UPDATE_FILE_LIST", () => {308 const fileList = [309 {310 type: "file",311 name: "b",312 size: 10,313 date: "2020/04/30",314 },315 {316 type: "file",317 name: "a",318 size: 11,319 date: "2020/05/01",320 },321 {322 type: "file",323 name: "z",324 size: 110,325 date: "2020/04/29",326 },327 ];328 const dirList = [329 {330 type: "dir",331 name: "b_dir",332 size: 10,333 date: "2020/04/30",334 },335 {336 type: "dir",337 name: "a_dir",338 size: 11,339 date: "2020/05/01",340 },341 {342 type: "dir",343 name: "z_dir",344 size: 110,345 date: "2020/04/29",346 },347 ];348 const updateAction = updateFileList([...fileList, ...dirList]);349 it("should handle sizePos", async () => {350 const sortFun = (a, b) => {351 return a.size - b.size;352 };353 const state = {354 ...initState,355 viewUpdate: {356 ...initState.viewUpdate,357 sortMethod: "sizePos",358 },359 };360 const store = mockStore(state);361 await store.dispatch(updateAction);362 expect(store.getActions()).toEqual([363 setDirList(dirList.sort(sortFun)),364 setFileList(fileList.sort(sortFun)),365 ]);366 });367 it("should handle sizeRes", async () => {368 const sortFun = (a, b) => {369 return b.size - a.size;370 };371 const state = {372 ...initState,373 viewUpdate: {374 ...initState.viewUpdate,375 sortMethod: "sizeRes",376 },377 };378 const store = mockStore(state);379 await store.dispatch(updateAction);380 expect(store.getActions()).toEqual([381 setDirList(dirList.sort(sortFun)),382 setFileList(fileList.sort(sortFun)),383 ]);384 });385 it("should handle namePos", async () => {386 const sortFun = (a, b) => {387 return a.name.localeCompare(b.name);388 };389 const state = {390 ...initState,391 viewUpdate: {392 ...initState.viewUpdate,393 sortMethod: "namePos",394 },395 };396 const store = mockStore(state);397 await store.dispatch(updateAction);398 expect(store.getActions()).toEqual([399 setDirList(dirList.sort(sortFun)),400 setFileList(fileList.sort(sortFun)),401 ]);402 });403 it("should handle nameRev", async () => {404 const sortFun = (a, b) => {405 return b.name.localeCompare(a.name);406 };407 const state = {408 ...initState,409 viewUpdate: {410 ...initState.viewUpdate,411 sortMethod: "nameRev",412 },413 };414 const store = mockStore(state);415 await store.dispatch(updateAction);416 expect(store.getActions()).toEqual([417 setDirList(dirList.sort(sortFun)),418 setFileList(fileList.sort(sortFun)),419 ]);420 });421 it("should handle timePos", async () => {422 const sortFun = (a, b) => {423 return Date.parse(a.date) - Date.parse(b.date);424 };425 const state = {426 ...initState,427 viewUpdate: {428 ...initState.viewUpdate,429 sortMethod: "timePos",430 },431 };432 const store = mockStore(state);433 await store.dispatch(updateAction);434 expect(store.getActions()).toEqual([435 setDirList(dirList.sort(sortFun)),436 setFileList(fileList.sort(sortFun)),437 ]);438 });439 it("should handle timeRev", async () => {440 const sortFun = (a, b) => {441 return Date.parse(b.date) - Date.parse(a.date);442 };443 const state = {444 ...initState,445 viewUpdate: {446 ...initState.viewUpdate,447 sortMethod: "timeRev",448 },449 };450 const store = mockStore(state);451 await store.dispatch(updateAction);452 expect(store.getActions()).toEqual([453 setDirList(dirList.sort(sortFun)),454 setFileList(fileList.sort(sortFun)),455 ]);456 });457 });458 it("should handle SET_FILE_LIST", () => {459 const action = setFileList([460 {461 type: "file",462 id: "a",463 },464 {465 type: "file",466 id: "b",467 },468 ]);469 expect(470 cloudreveApp(471 {472 ...initState,473 explorer: {474 ...initState.explorer,475 fileList: [{ type: "file", id: "test" }],476 },477 },478 action479 )480 ).toEqual({481 ...initState,482 explorer: {483 ...initState.explorer,484 fileList: [485 {486 type: "file",487 id: "a",488 },489 {490 type: "file",491 id: "b",492 },493 ],494 },495 });496 });497 it("should handle SET_DIR_LIST", () => {498 const action = setDirList([499 {500 type: "dir",501 id: "a",502 },503 {504 type: "dir",505 id: "b",506 },507 ]);508 expect(509 cloudreveApp(510 {511 ...initState,512 explorer: {513 ...initState.explorer,514 dirList: [{ type: "dir", id: "test" }],515 },516 },517 action518 )519 ).toEqual({520 ...initState,521 explorer: {522 ...initState.explorer,523 dirList: [524 {525 type: "dir",526 id: "a",527 },528 {529 type: "dir",530 id: "b",531 },532 ],533 },534 });535 });536 it("should handle ADD_SELECTED_TARGETS", () => {537 const newSelect = [538 {539 type: "file",540 },541 {542 type: "dir",543 },544 ];545 const action = addSelectedTargets(newSelect);546 expect(547 cloudreveApp(548 {549 ...initState,550 explorer: {551 ...initState.explorer,552 selected: [{ type: "file" }],553 },554 },555 action556 )557 ).toEqual({558 ...initState,559 explorer: {560 ...initState.explorer,561 selected: [{ type: "file" }, ...newSelect],562 selectProps: {563 isMultiple: true,564 withFolder: true,565 withFile: true,566 },567 },568 });569 });570 it("should handle SET_SELECTED_TARGET", () => {571 const newSelect = [572 {573 type: "file",574 },575 {576 type: "dir",577 },578 ];579 const action = setSelectedTarget(newSelect);580 expect(581 cloudreveApp(582 {583 ...initState,584 explorer: {585 ...initState.explorer,586 selected: [{ type: "file" }],587 },588 },589 action590 )591 ).toEqual({592 ...initState,593 explorer: {594 ...initState.explorer,595 selected: newSelect,596 selectProps: {597 isMultiple: true,598 withFolder: true,599 withFile: true,600 },601 },602 });603 });604 it("should handle RMOVE_SELECTED_TARGETS", () => {605 const remove = ["1"];606 const action = removeSelectedTargets(remove);607 expect(608 cloudreveApp(609 {610 ...initState,611 explorer: {612 ...initState.explorer,613 selected: [614 { id: "1", type: "file" },615 { id: "2", type: "file" },616 ],617 },618 },619 action620 )621 ).toEqual({622 ...initState,623 explorer: {624 ...initState.explorer,625 selected: [{ id: "2", type: "file" }],626 selectProps: {627 isMultiple: false,628 withFolder: false,629 withFile: true,630 },631 },632 });633 });634 it("should handle NAVIGATOR_TO", async () => {635 const store = mockStore(initState);636 const action = navigateTo("/somewhere");637 await store.dispatch(action);638 expect(store.getActions()).toEqual([setNavigator("/somewhere", true)]);639 });640 it("should handle NAVIGATOR_UP", async () => {641 const navState = {642 ...initState,643 navigator: {644 ...initState.navigator,645 path: "/to/somewhere",646 },647 };648 const store = mockStore(navState);649 const action = navigateUp();650 await store.dispatch(action);651 expect(store.getActions()).toEqual([setNavigator("/to", true)]);652 });653 it("should handle SET_NAVIGATOR", () => {654 const navState = {655 ...initState,656 navigator: {657 ...initState.navigator,658 path: "/to/somewhere",659 },660 };661 const action = setNavigator("/newpath", true);662 expect(cloudreveApp(navState, action)).toEqual({663 ...initState,664 navigator: {665 ...initState.navigator,666 path: "/newpath",667 },668 viewUpdate: {669 ...initState.viewUpdate,670 contextOpen: false,671 navigatorError: false,672 navigatorLoading: true,673 },674 explorer: {675 ...initState.explorer,676 selected: [],677 selectProps: {678 isMultiple: false,679 withFolder: false,680 withFile: false,681 },682 keywords: "",683 },684 });685 expect(window.currntPath).toEqual("/newpath");686 });687 it("should handle TOGGLE_DAYLIGHT_MODE", () => {688 const action = toggleDaylightMode();689 const darkState = {690 ...initState,691 siteConfig: {692 ...initState.siteConfig,693 theme: {694 ...initState.siteConfig.theme,695 palette: {696 ...initState.siteConfig.theme.palette,697 type: "dark",698 },699 },700 },701 };702 const lightState = {703 ...initState,704 siteConfig: {705 ...initState.siteConfig,706 theme: {707 ...initState.siteConfig.theme,708 palette: {709 ...initState.siteConfig.theme.palette,710 type: "light",711 },712 },713 },714 };715 expect(cloudreveApp(initState, action)).toEqual(darkState);716 expect(cloudreveApp(darkState, action)).toEqual(lightState);717 });718 it("should handle APPLY_THEME", () => {719 const action = applyThemes("foo");720 const stateWithThemes = {721 ...initState,722 siteConfig: {723 ...initState.siteConfig,724 themes: JSON.stringify({ foo: "bar" }),725 },726 };727 expect(cloudreveApp(stateWithThemes, action)).toEqual({728 ...stateWithThemes,729 siteConfig: {730 ...stateWithThemes.siteConfig,731 theme: "bar",732 },733 });734 });735 it("should handle OPEN_CREATE_FOLDER_DIALOG", () => {736 const action = openCreateFolderDialog();737 expect(cloudreveApp(initState, action)).toEqual({738 ...initState,739 viewUpdate: {740 ...initState.viewUpdate,741 modals: {742 ...initState.viewUpdate.modals,743 createNewFolder: true,744 },745 contextOpen: false,746 },747 });748 });749 it("should handle OPEN_RENAME_DIALOG", () => {750 const action = openRenameDialog();751 expect(cloudreveApp(initState, action)).toEqual({752 ...initState,753 viewUpdate: {754 ...initState.viewUpdate,755 modals: {756 ...initState.viewUpdate.modals,757 rename: true,758 },759 contextOpen: false,760 },761 });762 });763 it("should handle OPEN_REMOVE_DIALOG", () => {764 const action = openRemoveDialog();765 expect(cloudreveApp(initState, action)).toEqual({766 ...initState,767 viewUpdate: {768 ...initState.viewUpdate,769 modals: {770 ...initState.viewUpdate.modals,771 remove: true,772 },773 contextOpen: false,774 },775 });776 });777 it("should handle OPEN_MOVE_DIALOG", () => {778 const action = openMoveDialog();779 expect(cloudreveApp(initState, action)).toEqual({780 ...initState,781 viewUpdate: {782 ...initState.viewUpdate,783 modals: {784 ...initState.viewUpdate.modals,785 move: true,786 },787 contextOpen: false,788 },789 });790 });791 it("should handle OPEN_RESAVE_DIALOG", () => {792 const action = openResaveDialog();793 expect(cloudreveApp(initState, action)).toEqual({794 ...initState,795 viewUpdate: {796 ...initState.viewUpdate,797 modals: {798 ...initState.viewUpdate.modals,799 resave: true,800 },801 contextOpen: false,802 },803 });804 });805 it("should handle SET_USER_POPOVER", () => {806 // TODO: update to real anchor807 const action = setUserPopover("anchor");808 expect(cloudreveApp(initState, action)).toEqual({809 ...initState,810 viewUpdate: {811 ...initState.viewUpdate,812 userPopoverAnchorEl: "anchor",813 },814 });815 });816 it("should handle SET_SHARE_USER_POPOVER", () => {817 // TODO: update to real anchor818 const action = setShareUserPopover("anchor");819 expect(cloudreveApp(initState, action)).toEqual({820 ...initState,821 viewUpdate: {822 ...initState.viewUpdate,823 shareUserPopoverAnchorEl: "anchor",824 },825 });826 });827 it("should handle OPEN_SHARE_DIALOG", () => {828 // TODO: update to real anchor829 const action = openShareDialog();830 expect(cloudreveApp(initState, action)).toEqual({831 ...initState,832 viewUpdate: {833 ...initState.viewUpdate,834 modals: {835 ...initState.viewUpdate.modals,836 share: true,837 },838 contextOpen: false,839 },840 });841 });842 it("should handle SET_SITE_CONFIG", () => {843 // TODO: update to real anchor844 const action = setSiteConfig({ foo: "bar" });845 expect(cloudreveApp(initState, action)).toEqual({846 ...initState,847 siteConfig: {848 foo: "bar",849 },850 });851 });852 it("should handle SET_SITE_CONFIG", () => {853 // TODO: update to real anchor854 const action = setSiteConfig({ foo: "bar" });855 expect(cloudreveApp(initState, action)).toEqual({856 ...initState,857 siteConfig: {858 foo: "bar",859 },860 });861 });862 it("should handle OPEN_MUSIC_DIALOG", () => {863 const action = openMusicDialog();864 expect(cloudreveApp(initState, action)).toEqual({865 ...initState,866 viewUpdate: {867 ...initState.viewUpdate,868 modals: {869 ...initState.viewUpdate.modals,870 music: true,871 },872 contextOpen: false,873 },874 });875 });876 it("should handle OPEN_REMOTE_DOWNLOAD_DIALOG", () => {877 const action = openRemoteDownloadDialog();878 expect(cloudreveApp(initState, action)).toEqual({879 ...initState,880 viewUpdate: {881 ...initState.viewUpdate,882 modals: {883 ...initState.viewUpdate.modals,884 remoteDownload: true,885 },886 contextOpen: false,887 },888 });889 });890 it("should handle OPEN_TORRENT_DOWNLOAD_DIALOG", () => {891 const action = openTorrentDownloadDialog();892 expect(cloudreveApp(initState, action)).toEqual({893 ...initState,894 viewUpdate: {895 ...initState.viewUpdate,896 modals: {897 ...initState.viewUpdate.modals,898 torrentDownload: true,899 },900 contextOpen: false,901 },902 });903 });904 it("should handle OPEN_DECOMPRESS_DIALOG", () => {905 const action = openDecompressDialog();906 expect(cloudreveApp(initState, action)).toEqual({907 ...initState,908 viewUpdate: {909 ...initState.viewUpdate,910 modals: {911 ...initState.viewUpdate.modals,912 decompress: true,913 },914 contextOpen: false,915 },916 });917 });918 it("should handle OPEN_COMPRESS_DIALOG", () => {919 const action = openCompressDialog();920 expect(cloudreveApp(initState, action)).toEqual({921 ...initState,922 viewUpdate: {923 ...initState.viewUpdate,924 modals: {925 ...initState.viewUpdate.modals,926 compress: true,927 },928 contextOpen: false,929 },930 });931 });932 it("should handle OPEN_GET_SOURCE_DIALOG", () => {933 const action = openGetSourceDialog();934 expect(cloudreveApp(initState, action)).toEqual({935 ...initState,936 viewUpdate: {937 ...initState.viewUpdate,938 modals: {939 ...initState.viewUpdate.modals,940 getSource: true,941 },942 contextOpen: false,943 },944 });945 });946 it("should handle OPEN_COPY_DIALOG", () => {947 const action = openCopyDialog();948 expect(cloudreveApp(initState, action)).toEqual({949 ...initState,950 viewUpdate: {951 ...initState.viewUpdate,952 modals: {953 ...initState.viewUpdate.modals,954 copy: true,955 },956 contextOpen: false,957 },958 });959 });960 it("should handle OPEN_LOADING_DIALOG", () => {961 const action = openLoadingDialog("loading");962 expect(cloudreveApp(initState, action)).toEqual({963 ...initState,964 viewUpdate: {965 ...initState.viewUpdate,966 modals: {967 ...initState.viewUpdate.modals,968 loading: true,969 loadingText: "loading",970 },971 contextOpen: false,972 },973 });974 });975 it("should handle CLOSE_ALL_MODALS", () => {976 const action = closeAllModals();977 expect(cloudreveApp(initState, action)).toEqual({978 ...initState,979 viewUpdate: {980 ...initState.viewUpdate,981 modals: {982 ...initState.viewUpdate.modals,983 createNewFolder: false,984 rename: false,985 move: false,986 remove: false,987 share: false,988 music: false,989 remoteDownload: false,990 torrentDownload: false,991 getSource: false,992 resave: false,993 copy: false,994 loading: false,995 compress: false,996 decompress: false,997 },998 },999 });1000 });1001 it("should handle CHANGE_SUB_TITLE", async () => {1002 const store = mockStore(initState);1003 const action = changeSubTitle("test sub title");1004 await store.dispatch(action);1005 expect(store.getActions()).toEqual([setSubtitle("test sub title")]);1006 expect(document.title).toEqual("test sub title - CloudEnterprise");1007 });1008 it("should handle SET_SUBTITLE", () => {1009 const action = setSubtitle("test sub title 2");1010 expect(cloudreveApp(initState, action)).toEqual({1011 ...initState,1012 viewUpdate: {1013 ...initState.viewUpdate,1014 subTitle: "test sub title 2",1015 },1016 });1017 });1018 it("should handle TOGGLE_SNACKBAR", () => {1019 const action = toggleSnackbar(1020 "top",1021 "right",1022 "something wrong",1023 "error"1024 );1025 expect(cloudreveApp(initState, action)).toEqual({1026 ...initState,1027 viewUpdate: {1028 ...initState.viewUpdate,1029 snackbar: {1030 toggle: true,1031 vertical: "top",1032 horizontal: "right",1033 msg: "something wrong",1034 color: "error",1035 },1036 },1037 });1038 });1039 it("should handle SET_MODALS_LOADING", () => {1040 const action = setModalsLoading("test loading status");1041 expect(cloudreveApp(initState, action)).toEqual({1042 ...initState,1043 viewUpdate: {1044 ...initState.viewUpdate,1045 modalsLoading: "test loading status",1046 },1047 });1048 });1049 it("should handle SET_SESSION_STATUS", () => {1050 const action = setSessionStatus(true);1051 expect(cloudreveApp(initState, action)).toEqual({1052 ...initState,1053 viewUpdate: {1054 ...initState.viewUpdate,1055 isLogin: true,1056 },1057 });1058 });1059 it("should handle ENABLE_LOAD_UPLOADER", () => {1060 const action = enableLoadUploader();1061 expect(cloudreveApp(initState, action)).toEqual({1062 ...initState,1063 viewUpdate: {1064 ...initState.viewUpdate,1065 loadUploader: true,1066 },1067 });1068 });1069 it("should handle REFRESH_FILE_LIST", () => {1070 const action = refreshFileList();1071 expect(cloudreveApp(initState, action)).toEqual({1072 ...initState,1073 navigator: {1074 ...initState.navigator,1075 refresh: false,1076 },1077 explorer: {1078 ...initState.explorer,1079 selected: [],1080 selectProps: {1081 isMultiple: false,1082 withFolder: false,1083 withFile: false,1084 },1085 },1086 });1087 });1088 it("should handle SEARCH_MY_FILE", () => {1089 const action = searchMyFile("keyword");1090 expect(cloudreveApp(initState, action)).toEqual({1091 ...initState,1092 navigator: {1093 ...initState.navigator,1094 path: "/搜索结果",1095 refresh: true,1096 },1097 viewUpdate: {1098 ...initState.viewUpdate,1099 contextOpen: false,1100 navigatorError: false,1101 navigatorLoading: true,1102 },1103 explorer: {1104 ...initState.explorer,1105 selected: [],1106 selectProps: {1107 isMultiple: false,1108 withFolder: false,1109 withFile: false,1110 },1111 keywords: "keyword",1112 },1113 });1114 });1115 it("should handle SHOW_IMG_PREIVEW", () => {1116 const action = showImgPreivew({ type: "file" });1117 const showImgState = {1118 ...initState,1119 explorer: {1120 ...initState.explorer,1121 fileList: [{ type: "file" }, { type: "dir" }],1122 },1123 };1124 expect(cloudreveApp(showImgState, action)).toEqual({1125 ...showImgState,1126 explorer: {1127 ...showImgState.explorer,1128 imgPreview: {1129 ...showImgState.explorer.imgPreview,1130 first: { type: "file" },1131 other: [{ type: "file" }, { type: "dir" }],1132 },1133 },1134 });1135 });1136 it("should handle REFRESH_STORAGE", () => {1137 const action = refreshStorage();1138 expect(cloudreveApp(initState, action)).toEqual({1139 ...initState,1140 viewUpdate: {1141 ...initState.viewUpdate,1142 storageRefresh: true,1143 },1144 });1145 });1146 it("should handle SAVE_FILE", () => {1147 const action = saveFile();1148 expect(cloudreveApp(initState, action)).toEqual({1149 ...initState,1150 explorer: {1151 ...initState.explorer,1152 fileSave: true,1153 },1154 });1155 });1156 it("should handle SET_LAST_SELECT", () => {1157 const action = setLastSelect({ type: "file" }, 1);1158 expect(cloudreveApp(initState, action)).toEqual({1159 ...initState,1160 explorer: {1161 ...initState.explorer,1162 lastSelect: {1163 file: { type: "file" },1164 index: 1,1165 },1166 },1167 });1168 });1169 it("should handle SET_SHIFT_SELECTED_IDS", () => {1170 const action = setShiftSelectedIds(["1", "2"]);1171 expect(cloudreveApp(initState, action)).toEqual({1172 ...initState,1173 explorer: {1174 ...initState.explorer,1175 shiftSelectedIds: ["1", "2"],1176 },1177 });1178 });...

Full Screen

Full Screen

currency.test.js

Source:currency.test.js Github

copy

Full Screen

1import {2 selectBtc,3 selectEth,4 selectOffset,5 fetchBtcRequest,6 fetchEthRequest,7 fetchBtcSuccess,8 fetchBtcFailure,9 fetchEthFailure,10 fetchEthSuccess11} from '../../actions/currency';12import { currency } from '../currency';13const initState = {14 selected: 'btc',15 offset: '2h',16 btc: [],17 eth: [],18 btcLoadingState: {19 isLoading: false,20 isLoaded: false,21 error: false22 },23 ethLoadingState: {24 isLoading: false,25 isLoaded: false,26 error: false27 }28};29describe('currency reducer', () => {30 describe('selectBtc action', () => {31 it('shouldn`t mutate init state', () => {32 expect(currency(initState, selectBtc())).not.toBe(initState);33 });34 it('should put btc to selected field', () => {35 expect(currency(null, selectBtc('btc')).selected).toBe('btc');36 });37 });38 describe('selectEth action', () => {39 it('shouldn`t mutate init state', () => {40 expect(currency(initState, selectEth())).not.toBe(initState);41 });42 it('should put eth to selected field', () => {43 expect(currency(null, selectEth('eth')).selected).toBe('eth');44 });45 });46 describe('selectOffset action', () => {47 it('shouldn`t mutate init state', () => {48 expect(currency(initState, selectOffset())).not.toBe(initState);49 });50 it('should put action.payload to offset field', () => {51 expect(currency(null, selectOffset('data')).offset).toBe('data');52 });53 });54 describe('fetchBtcRequest action', () => {55 it('shouldn`t mutate init state', () => {56 expect(currency(initState, fetchBtcRequest())).not.toBe(initState);57 });58 it('shouldn`t mutate init btcLoadingState object', () => {59 expect(currency(initState, fetchBtcRequest()).btcLoadingState).not.toBe(60 initState.btcLoadingState61 );62 });63 it('should set true to btcLoadingState.isLoading field', () => {64 initState.btcLoadingState.isLoading = false;65 expect(66 currency(initState, fetchBtcRequest()).btcLoadingState.isLoading67 ).toBe(true);68 });69 it('should set false to btcLoadingState.isLoaded field', () => {70 initState.btcLoadingState.isLoaded = true;71 expect(72 currency(initState, fetchBtcRequest()).btcLoadingState.isLoaded73 ).toBe(false);74 });75 it('should set false to btcLoadingState.error field', () => {76 initState.btcLoadingState.error = true;77 expect(currency(initState, fetchBtcRequest()).btcLoadingState.error).toBe(78 false79 );80 });81 });82 describe('fetchBtcSuccess action', () => {83 it('shouldn`t mutate init state', () => {84 expect(currency(initState, fetchBtcSuccess())).not.toBe(initState);85 });86 it('shouldn`t mutate init btcLoadingState object', () => {87 expect(currency(initState, fetchBtcSuccess()).btcLoadingState).not.toBe(88 initState.btcLoadingState89 );90 });91 it('should set false to btcLoadingState.isLoading field', () => {92 initState.btcLoadingState.isLoading = true;93 expect(94 currency(initState, fetchBtcSuccess()).btcLoadingState.isLoading95 ).toBe(false);96 });97 it('should set true to btcLoadingState.isLoaded field', () => {98 initState.btcLoadingState.isLoaded = false;99 expect(100 currency(initState, fetchBtcSuccess()).btcLoadingState.isLoaded101 ).toBe(true);102 });103 it('should set false to btcLoadingState.error field', () => {104 initState.btcLoadingState.error = true;105 expect(currency(initState, fetchBtcSuccess()).btcLoadingState.error).toBe(106 false107 );108 });109 it('should put action.payload to btc field', () => {110 expect(currency(initState, fetchBtcSuccess('data')).btc).toBe('data');111 });112 });113 describe('fetchBtcFailure action', () => {114 it('shouldn`t mutate init state', () => {115 expect(currency(initState, fetchBtcFailure())).not.toBe(initState);116 });117 it('shouldn`t mutate init btcLoadingState object', () => {118 expect(currency(initState, fetchBtcFailure()).btcLoadingState).not.toBe(119 initState.btcLoadingState120 );121 });122 it('should set false to btcLoadingState.isLoading field', () => {123 initState.btcLoadingState.isLoading = true;124 expect(125 currency(initState, fetchBtcFailure()).btcLoadingState.isLoading126 ).toBe(false);127 });128 it('should set true to btcLoadingState.isLoaded field', () => {129 initState.btcLoadingState.isLoaded = false;130 expect(131 currency(initState, fetchBtcFailure()).btcLoadingState.isLoaded132 ).toBe(true);133 });134 it('should put action.error to btcLoadingState.error field', () => {135 initState.btcLoadingState.error = false;136 expect(137 currency(initState, fetchBtcFailure(new Error())).btcLoadingState.error138 ).toBe(true);139 });140 });141 describe('fetchEthRequest action', () => {142 it('shouldn`t mutate init state', () => {143 expect(currency(initState, fetchEthRequest())).not.toBe(initState);144 });145 it('shouldn`t mutate init ethLoadingState object', () => {146 expect(currency(initState, fetchEthRequest()).ethLoadingState).not.toBe(147 initState.ethLoadingState148 );149 });150 it('should set true to ethLoadingState.isLoading field', () => {151 initState.ethLoadingState.isLoading = false;152 expect(153 currency(initState, fetchEthRequest()).ethLoadingState.isLoading154 ).toBe(true);155 });156 it('should set false to ethLoadingState.isLoaded field', () => {157 initState.ethLoadingState.isLoaded = true;158 expect(159 currency(initState, fetchEthRequest()).ethLoadingState.isLoaded160 ).toBe(false);161 });162 it('should set false to ethLoadingState.error field', () => {163 initState.ethLoadingState.error = true;164 expect(currency(initState, fetchEthRequest()).ethLoadingState.error).toBe(165 false166 );167 });168 });169 describe('fetchEthSuccess action', () => {170 it('shouldn`t mutate init state', () => {171 expect(currency(initState, fetchEthSuccess())).not.toBe(initState);172 });173 it('shouldn`t mutate init ethLoadingState object', () => {174 expect(currency(initState, fetchEthSuccess()).ethLoadingState).not.toBe(175 initState.ethLoadingState176 );177 });178 it('should set false to ethLoadingState.isLoading field', () => {179 initState.btcLoadingState.isLoading = true;180 expect(181 currency(initState, fetchEthSuccess()).ethLoadingState.isLoading182 ).toBe(false);183 });184 it('should set true to ethLoadingState.isLoaded field', () => {185 initState.ethLoadingState.isLoaded = false;186 expect(187 currency(initState, fetchEthSuccess()).ethLoadingState.isLoaded188 ).toBe(true);189 });190 it('should set false to ethLoadingState.error field', () => {191 initState.ethLoadingState.error = true;192 expect(currency(initState, fetchEthSuccess()).ethLoadingState.error).toBe(193 false194 );195 });196 it('should put action.payload to eth field', () => {197 expect(currency(initState, fetchEthSuccess('data')).eth).toBe('data');198 });199 });200 describe('fetchEthFailure action', () => {201 it('shouldn`t mutate init state', () => {202 expect(currency(initState, fetchEthFailure())).not.toBe(initState);203 });204 it('shouldn`t mutate init ethLoadingState object', () => {205 expect(currency(initState, fetchEthFailure()).ethLoadingState).not.toBe(206 initState.ethLoadingState207 );208 });209 it('should set false to ethLoadingState.isLoading field', () => {210 initState.ethLoadingState.isLoading = true;211 expect(212 currency(initState, fetchEthFailure()).ethLoadingState.isLoading213 ).toBe(false);214 });215 it('should set true to ethLoadingState.isLoaded field', () => {216 initState.ethLoadingState.isLoaded = false;217 expect(218 currency(initState, fetchEthFailure()).ethLoadingState.isLoaded219 ).toBe(true);220 });221 it('should put action.error to ethLoadingState.error field', () => {222 initState.ethLoadingState.error = false;223 expect(224 currency(initState, fetchEthFailure(new Error())).ethLoadingState.error225 ).toBe(true);226 });227 });...

Full Screen

Full Screen

auth.test.js

Source:auth.test.js Github

copy

Full Screen

1import { authReducer } from './auth';2import {3 LOGIN_FORM_SET_VALUE,4 LOGIN_FORM_SUBMIT_REQUEST,5 LOGIN_FORM_SUBMIT_SUCCESS,6 LOGIN_FORM_SUBMIT_FAILED,7 LOGOUT_FORM_SUBMIT_REQUEST,8 LOGOUT_FORM_SUBMIT_SUCCESS,9 LOGOUT_FORM_SUBMIT_FAILED,10 GET_USER_DATA_REQUEST,11 GET_USER_DATA_SUCCESS,12 GET_USER_DATA_FAILED,13 GET_USER_DATA_SET_VALUE,14} from '../actions/auth';15const initState = {16 form: {17 name: '',18 password: '',19 email: '',20 token: '',21 },22 loginRequest: false,23 loginFailed: false,24 logoutRequest: false,25 logoutFailed: false,26 getUserRequest: false,27 getUserFailed: false,28 getUserLoaded: false,29 user: {},30};31describe('authReducer', () => {32 it('should return the initial state', () => {33 expect(authReducer(undefined, {})).toEqual(initState);34 });35 it('should handle LOGIN_FORM_SET_VALUE', () => {36 expect(37 authReducer(initState, {38 type: LOGIN_FORM_SET_VALUE,39 field: 'email',40 value: 'mail@mail.ru',41 }),42 ).toEqual(43 {44 ...initState,45 form: {46 ...initState.form,47 email: 'mail@mail.ru',48 },49 },50 );51 expect(52 authReducer(initState, {53 type: LOGIN_FORM_SET_VALUE,54 field: 'password',55 value: 'qwerty',56 }),57 ).toEqual(58 {59 ...initState,60 form: {61 ...initState.form,62 password: 'qwerty',63 },64 },65 );66 });67 it('should handle LOGIN_FORM_SUBMIT_REQUEST', () => {68 expect(69 authReducer({70 ...initState,71 form: {72 ...initState.form,73 email: 'mail@mail.ru',74 password: 'qwerty',75 },76 }, {77 type: LOGIN_FORM_SUBMIT_REQUEST,78 }),79 ).toEqual(80 {81 ...initState,82 form: {83 ...initState.form,84 email: 'mail@mail.ru',85 password: 'qwerty',86 },87 loginRequest: true,88 },89 );90 });91 it('should handle LOGIN_FORM_SUBMIT_SUCCESS', () => {92 expect(93 authReducer({94 ...initState,95 form: {96 ...initState.form,97 email: 'mail@mail.ru',98 password: 'qwerty',99 },100 loginRequest: true,101 }, {102 type: LOGIN_FORM_SUBMIT_SUCCESS,103 user: {104 name: 'Дмитрий',105 email: 'mail@mail.ru',106 },107 }),108 ).toEqual(109 {110 ...initState,111 form: {112 ...initState.form,113 email: '',114 password: '',115 },116 user: {117 name: 'Дмитрий',118 email: 'mail@mail.ru',119 },120 loginRequest: false,121 },122 );123 });124 it('should handle LOGIN_FORM_SUBMIT_FAILED', () => {125 expect(126 authReducer({127 ...initState,128 form: {129 ...initState.form,130 email: 'mail@mail.ru',131 password: 'qwerty',132 },133 }, {134 type: LOGIN_FORM_SUBMIT_FAILED,135 }),136 ).toEqual(137 {138 ...initState,139 form: {140 ...initState.form,141 email: 'mail@mail.ru',142 password: 'qwerty',143 },144 loginFailed: true,145 },146 );147 });148 it('should handle LOGOUT_FORM_SUBMIT_REQUEST', () => {149 expect(150 authReducer({151 ...initState,152 form: {153 ...initState.form,154 email: '',155 },156 user: {157 name: 'Дмитрий',158 email: 'mail@mail.ru',159 },160 }, {161 type: LOGOUT_FORM_SUBMIT_REQUEST,162 }),163 ).toEqual(164 {165 ...initState,166 form: {167 ...initState.form,168 email: '',169 },170 user: {171 name: 'Дмитрий',172 email: 'mail@mail.ru',173 },174 logoutRequest: true,175 },176 );177 });178 it('should handle LOGOUT_FORM_SUBMIT_SUCCESS', () => {179 expect(180 authReducer({181 ...initState,182 form: {183 ...initState.form,184 email: '',185 },186 user: {187 name: 'Дмитрий',188 email: 'mail@mail.ru',189 },190 logoutRequest: true,191 }, {192 type: LOGOUT_FORM_SUBMIT_SUCCESS,193 }),194 ).toEqual(195 {196 ...initState,197 form: {198 ...initState.form,199 email: '',200 password: '',201 },202 logoutRequest: false,203 },204 );205 });206 it('should handle LOGOUT_FORM_SUBMIT_FAILED', () => {207 expect(208 authReducer({209 ...initState,210 form: {211 ...initState.form,212 email: '',213 },214 user: {215 name: 'Дмитрий',216 email: 'mail@mail.ru',217 },218 }, {219 type: LOGOUT_FORM_SUBMIT_FAILED,220 }),221 ).toEqual(222 {223 ...initState,224 form: {225 ...initState.form,226 email: '',227 },228 user: {229 name: 'Дмитрий',230 email: 'mail@mail.ru',231 },232 logoutRequest: false,233 logoutFailed: true,234 },235 );236 });237 it('should handle GET_USER_DATA_SET_VALUE', () => {238 expect(239 authReducer({240 ...initState,241 form: {242 ...initState.form,243 email: '',244 },245 user: {246 name: 'Дмитрий',247 email: 'mail@mail.ru',248 },249 }, {250 type: GET_USER_DATA_SET_VALUE,251 field: 'name',252 value: 'Дима',253 }),254 ).toEqual(255 {256 ...initState,257 form: {258 ...initState.form,259 email: '',260 name: '',261 },262 user: {263 name: 'Дима',264 email: 'mail@mail.ru',265 },266 },267 );268 });269 it('should handle GET_USER_DATA_REQUEST', () => {270 expect(271 authReducer({272 ...initState,273 form: {274 ...initState.form,275 email: '',276 },277 user: {278 name: 'Дмитрий',279 email: 'mail@mail.ru',280 },281 }, {282 type: GET_USER_DATA_REQUEST,283 }),284 ).toEqual(285 {286 ...initState,287 form: {288 ...initState.form,289 email: '',290 },291 user: {292 name: 'Дмитрий',293 email: 'mail@mail.ru',294 },295 getUserRequest: true,296 },297 );298 });299 it('should handle GET_USER_DATA_SUCCESS', () => {300 expect(301 authReducer({302 ...initState,303 form: {304 ...initState.form,305 email: '',306 },307 user: {308 name: 'Дмитрий',309 email: 'mail@mail.ru',310 },311 getUserRequest: true,312 }, {313 type: GET_USER_DATA_SUCCESS,314 user: {315 name: 'Дмитрий',316 email: 'mail@mail.ru',317 },318 }),319 ).toEqual(320 {321 ...initState,322 form: {323 ...initState.form,324 email: '',325 },326 user: {327 name: 'Дмитрий',328 email: 'mail@mail.ru',329 },330 getUserRequest: false,331 getUserLoaded: true,332 },333 );334 });335 it('should handle GET_USER_DATA_FAILED', () => {336 expect(337 authReducer({338 ...initState,339 form: {340 ...initState.form,341 email: '',342 },343 user: {344 name: 'Дмитрий',345 email: 'mail@mail.ru',346 },347 }, {348 type: GET_USER_DATA_FAILED,349 }),350 ).toEqual(351 {352 ...initState,353 form: {354 ...initState.form,355 email: '',356 },357 user: {358 name: 'Дмитрий',359 email: 'mail@mail.ru',360 },361 getUserRequest: false,362 getUserFailed: true,363 },364 );365 });...

Full Screen

Full Screen

module.js

Source:module.js Github

copy

Full Screen

1let module = (function(){2 let imgs = document.getElementsByClassName('content-main-image'),3 filter = document.getElementsByClassName('filterSize'),4 resultApi = document.getElementById('sidebar-filter-title'),5 spinner = document.getElementById('spinner')6 let initModule,loadImgs,nextTwentyImgs,prevTwentyImgs,getImgs,7 updateListImg,select,filterName,sortImgs,takeImg8 let initState = {9 select:'all',10 ResultFetch : [],11 ImagesArray : [],12 LargeImgs :[],13 MediumImgs :[],14 SmallImgs :[],15 step : 2016 }17 loadImgs = ()=>{18 spinner.classList.toggle('spin-visible')19 fetch('https://unsplash.it/list')20 .then(response=>response.json()21 .then(data=>{22 initState.ResultFetch = data23 initState.ImagesArray = initState.ResultFetch24 resultApi.innerHTML = `API выдал ${data.length} картинок`25 spinner.classList.toggle('spin-visible')26 return initState.ImagesArray;27 })28 .then(()=>{ 29 for(let i=0;i<20;i++){30 let span = document.createElement('span')31 span.innerText = 32 `${initState.ImagesArray[i].width} x ${initState.ImagesArray[i].height}33 ${initState.ImagesArray[i].author}`34 imgs[i].appendChild(span)35 } 36 sortImgs() 37 })38 )39 }40 nextTwentyImgs = function(){41 let arrImgs = initState.ImagesArray42 if(arrImgs.length<20)return43 for(let i=0;i<20;i++){44 if(arrImgs[initState.step+i]==undefined){45 imgs[i].getElementsByTagName('span')[0].innerHTML=''46 continue;47 }48 imgs[i].getElementsByTagName('span')[0].innerHTML = 49 `${arrImgs[initState.step+i].width} x 50 ${arrImgs[initState.step+i].height} 51 ${arrImgs[initState.step+i].author}`52 }53 initState.step+=20;54 }55 prevTwentyImgs = function(){56 let arrImgs = initState.ImagesArray57 if(arrImgs.length<20)return58 if(initState.step!==20){59 initState.step-=40;60 for(let i=0;i<20;i++){61 imgs[i].getElementsByTagName('span')[0].innerHTML = 62 `${arrImgs[initState.step+i].width} x 63 ${arrImgs[initState.step+i].height} 64 ${arrImgs[initState.step+i].author}`65 }66 initState.step+=2067 }68 } 69 sortImgs = function(){70 initState.ResultFetch.map(item=>{71 item.height>1500&&72 item.width>1500&&73 initState.LargeImgs.push(item) 74 75 item.height>800&&item.height<1499&&76 item.width>800&&item.width<1499&&77 initState.MediumImgs.push(item) 78 79 item.height<799&&initState.SmallImgs.push(item)80 })81 } 82 getImgs = function(size,callback){83 switch(size){84 case 'large':85 initState.select='large'86 initState.ImagesArray=initState.LargeImgs87 resultApi.innerHTML = `Найдено ${initState.LargeImgs.length} картинок`88 callback(initState.LargeImgs)89 break90 case 'medium':91 initState.select='medium'92 initState.ImagesArray=initState.MediumImgs93 resultApi.innerHTML = `Найдено ${initState.MediumImgs.length} картинок`94 callback(initState.MediumImgs)95 break96 case 'small':97 initState.select='small'98 initState.ImagesArray=initState.SmallImgs99 resultApi.innerHTML = `Найдено ${initState.SmallImgs.length} картинок`100 callback(initState.SmallImgs)101 break102 default: 103 initState.select='all'104 initState.ImagesArray=initState.ResultFetch105 resultApi.innerHTML = `Всего ${initState.ResultFetch.length} картинок`106 callback(initState.ResultFetch)107 } 108 console.log(initState.select)109 }110 updateListImg = function(arrImgs){111 for(let i=0;i<20;i++){112 if(arrImgs[i]==undefined){113 imgs[i].getElementsByTagName('span')[0].innerHTML=''114 continue;115 }116 imgs[i].getElementsByTagName('span')[0].innerHTML = 117 `${arrImgs[i].width} x 118 ${arrImgs[i].height}119 ${arrImgs[i].author}`120 }121 initState.step = 20;122 }123 select = function(e,key){124 for(let key of filter) key.classList.remove('select')125 document.getElementById(e.currentTarget.id).classList.add('select')126 }127 takeImg = function(e,element){128 if(element.getElementsByTagName('span')[0].innerHTML=='')return129 element.classList.toggle('active')130 }131 filterName = function(e,callback){132 e.code='Backspace'?initState.ImagesArray=initState.ResultFetch:''133 let resultFilter = [],134 arrForFilter = []135 let inputFilterName = e.currentTarget136 //document.getElementById(inputFilterName.id).nextSibling.innerHTML = inputFilterName.value137 initState.select == 'all' && (arrForFilter=initState.ResultFetch)138 initState.select == 'large' && (arrForFilter=initState.LargeImgs)139 initState.select == 'medium' && (arrForFilter=initState.MediumImgs)140 initState.select == 'small' && (arrForFilter=initState.SmallImgs)141 arrForFilter.forEach(function(element) {142 element.author.indexOf(inputFilterName.value)!=-1&&resultFilter.push(element) 143 }, this);144 callback(resultFilter)145 }146 initModule = ()=>{147 loadImgs()148 for(let key of filter) key.addEventListener('click',(e) => select(e,key))149 for (let key of imgs) key.addEventListener('click',(e)=>takeImg(e,key))150 document.getElementById('largeImg').addEventListener('click',()=>getImgs('large',updateListImg))151 document.getElementById('mediumImg').addEventListener('click',()=>getImgs('medium',updateListImg))152 document.getElementById('smallImg').addEventListener('click',()=>getImgs('small',updateListImg))153 document.getElementById('allImg').addEventListener('click',()=>getImgs(null,updateListImg))154 document.getElementById('arrow-prew').addEventListener('click',()=>prevTwentyImgs())155 document.getElementById('arrow-next').addEventListener('click',()=>nextTwentyImgs())156 document.getElementById('filterName').addEventListener('keyup',(e)=>filterName(e,updateListImg))157 }158 return {159 initModule160 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/* global Rx */2const stage = document.getElementById("stage");3const context = stage.getContext('2d');4context.fillStyle = "green";5const PADDLE_WIDTH = 100;6const PADDLE_HEIGHT = 20;7const BALL_RADIUS = 10;8const BRICK_ROWS = 6;9const BRICK_COLUMNS = 7;10const BRICK_HEIGHT = 20;11const BRICK_GAP = 3;12//球拍的移动速速13const PADDLE_SPEED = 240;14const BALL_SPEED = 100;15const PADDLE_CONTROLS = {16 'ArrowLeft': -1,17 'ArrowRight': 118}19const initState = {20 ball: {21 position: {22 x: stage.width / 2,23 y: stage.height - PADDLE_HEIGHT - BALL_RADIUS24 },25 direction: {26 x: 1,27 y: -128 }29 },30 paddle: {31 position: stage.width / 232 },33 bricks: createBricks(),34 score: 035}36//显示游戏说明37function drawIntro() {38 context.clearRect(0, 0, stage.width, stage.height);39 context.textAlign = "center";40 context.font = '24px Courier New';41 context.fillText("Press [<] and [>]", stage.width / 2, stage.height / 2);42}43//绘制球拍44function drawPaddle(position) {45 context.beginPath();46 context.rect(47 position - PADDLE_WIDTH / 2,48 stage.height - PADDLE_HEIGHT,49 PADDLE_WIDTH,50 PADDLE_HEIGHT51 );52 context.fill();53 context.closePath();54}55function drawScore(score) {56 context.font = "16px";57 context.fillText(score, BRICK_GAP, 16)58}59function createBricks() {60 let width = (stage.width - BRICK_GAP * (BRICK_COLUMNS + 1)) / BRICK_COLUMNS;61 let bricks = [];62 for (i = 0; i < BRICK_ROWS; i++) {63 for (j = 0; j < BRICK_COLUMNS; j++) {64 bricks.push({65 x: BRICK_GAP * (j + 1) + j * width,66 y: BRICK_GAP * (i + 1) + i * BRICK_HEIGHT + 16,67 width: width,68 height: BRICK_HEIGHT69 })70 }71 }72 return bricks;73}74function drawDrick(brick) {75 context.beginPath();76 context.rect(77 brick.x,78 brick.y,79 brick.width,80 brick.height81 );82 context.fill();83 context.closePath();84}85function drawDricks(bricks) {86 bricks.forEach(brick => {87 drawDrick(brick)88 })89}90function drawBall(ball) {91 context.beginPath();92 context.arc(ball.position.x, ball.position.y, BALL_RADIUS, 0, Math.PI * 2);93 context.fill();94 context.closePath();95}96let nextPaddlePosation = initState.paddle.position;97const time$ = Rx.Observable98 //保持60hz的刷新率99 .interval(1000 / 60, Rx.Scheduler.requestAnimationFrame)100 .map(() => ({101 time: Date.now(),102 deltaTime: null103 }))104 .scan((previous, current) => ({105 time: current.time,106 deltaTime: (current.time - previous.time) / 1000107 }))108const keys$ = Rx.Observable109 //merge先到先得110 .merge(111 Rx.Observable.fromEvent(document, 'keydown').map(event => (PADDLE_CONTROLS[event.key] || 0)),112 //释放按键113 Rx.Observable.fromEvent(document, 'keyup').map(event => (0))114 )115 //对数据去重116 .distinctUntilChanged();117//判断球跟砖块是否碰撞118function isCollision(brick, ball) {119 return ball.position.x > brick.x &&120 ball.position.x < brick.x + brick.width &&121 ball.position.y > brick.y &&122 ball.position.y < brick.y + brick.height123}124//采用subject来作为控制器,实现对事件流的操控125let controler$ = new Rx.Subject(); 126//结合时间流以及鼠标时间来控制球拍的位置127time$.withLatestFrom(keys$)128 .merge(controler$)129 .map(value => {130 //更新球拍的位置数据131 initState.paddle.position = initState.paddle.position + value[0].deltaTime * PADDLE_SPEED * value[1];132 //检测球跟砖块的碰撞133 initState.bricks.forEach((brick) => {134 //删除碰撞到的砖块,并且使球专项135 if (isCollision(brick, initState.ball)) {136 let brickIndex = initState.bricks.indexOf(brick);137 initState.bricks.splice(brickIndex, 1);138 initState.score ++;139 initState.ball.direction.y = 1;140 }141 if (initState.ball.position.y < BALL_RADIUS) {142 initState.ball.direction.y = 1;143 } 144 if (initState.ball.position.x > (stage.width - BALL_RADIUS)) {145 initState.ball.direction.x = -1146 }147 if (initState.ball.position.x < BALL_RADIUS) {148 initState.ball.direction.x = 1149 }150 if ((initState.ball.position.y > (stage.height - PADDLE_HEIGHT - BALL_RADIUS))) {151 if ((initState.ball.position.x > initState.paddle.position - PADDLE_WIDTH / 2) && (initState.ball.position.x < initState.paddle.position + PADDLE_WIDTH / 2)) {152 initState.ball.direction.y = -1153 }154 else {155 if (initState.ball.position.y >= stage.height - BALL_RADIUS) {156 console.log(initState.ball.position.x, initState.paddle.position);157 controler$.error("faild")158 }159 }160 }161 if(initState.paddle.position < PADDLE_WIDTH / 2) {162 initState.paddle.position = PADDLE_WIDTH / 2;163 }164 if(initState.paddle.position > (stage.width - PADDLE_WIDTH / 2)) {165 initState.paddle.position = stage.width - PADDLE_WIDTH / 2;166 }167 })168 //更新求的位置数据169 initState.ball.position.x = initState.ball.position.x + value[0].deltaTime * BALL_SPEED * initState.ball.direction.x;170 initState.ball.position.y = initState.ball.position.y + value[0].deltaTime * BALL_SPEED * initState.ball.direction.y;171 console.log(initState);172}).subscribe(() => {173 updateView(initState);174});175function updateView(state) {176 context.clearRect(0, 0, stage.width, stage.height);177 drawPaddle(state.paddle.position);178 drawBall(state.ball);179 drawDricks(state.bricks);180 drawScore(state.score);181}...

Full Screen

Full Screen

storeList.js

Source:storeList.js Github

copy

Full Screen

1import DataChunk from "~/stores/dataChunk";2import SearchStore from "~/stores/searchStore";3import PrimaryModalStore from "~/stores/views/primaryModalStore";4const StoreList = [5 {6 name: "loaderProgress",7 options: {8 initState: { percentage: 0, err: null }9 }10 },11 {12 name: "dataChunk",13 store: DataChunk14 },15 {16 name: "goods",17 options: {18 initState: {}19 }20 },21 {22 name: "sizes",23 options: {24 initState: {}25 }26 },27 {28 name: "shops",29 options: {30 initState: {}31 }32 },33 {34 name: "weather",35 options: {36 initState: {}37 }38 },39 {40 name: "lr",41 options: {42 initState: {}43 }44 },45 {46 name: "sellers",47 options: {48 initState: {}49 }50 },51 {52 name: "dateTime",53 options: {54 initState: {55 time: null,56 dayOfWeek: null,57 date: null58 }59 }60 },61 {62 name: "infoBlock",63 options: {64 initState: { slide: 0 }65 }66 },67 {68 name: "screenSaverSlider",69 options: {70 initState: { current: 1 }71 }72 },73 {74 name: "availableFilters",75 options: {76 initState: {}77 }78 },79 {80 name: "productList",81 options: {82 initState: []83 }84 },85 {86 name: "productListSize",87 options: {88 initState: { size: 0 }89 }90 },91 {92 name: "selectedFilters",93 options: {94 initState: {}95 }96 },97 {98 name: "catalogEvent",99 options: {100 initState: { type: null, value: null }101 }102 },103 {104 name: "search",105 store: SearchStore106 },107 {108 name: "searchResult",109 options: {110 initState: { result: [] }111 }112 },113 {114 name: "primaryModal",115 store: PrimaryModalStore116 },117 {118 name: "previewSliderView",119 options: {120 initState: { slide: 1 }121 }122 },123 {124 name: "orderCities",125 options: {126 initState: { list: [] }127 }128 },129 {130 name: "orderInputFocus",131 options: {132 initState: { focus: "phone" }133 }134 },135 {136 name: "orderInputButton",137 options: {138 initState: { value: null }139 }140 },141 {142 name: "orderPhone",143 options: {144 initState: { number: "" }145 }146 },147 {148 name: "orderPhoneParsed",149 options: {150 initState: { number: "+38 (0__) ___-__-__" }151 }152 },153 {154 name: "orderSeller",155 options: {156 initState: { number: "" }157 }158 },159 {160 name: "sellerName",161 options: {162 initState: { name: null }163 }164 },165 {166 name: "orderSend",167 options: {168 initState: { status: null, answer: null, error: null }169 }170 },171 {172 name: "mainViewGrid",173 options: {174 initState: { grid: 9 }175 }176 },177 {178 name: "productSort",179 options: {180 initState: { sort: "recom", open: false }181 }182 },183 {184 name: "mainModal",185 options: {186 initState: { open: false, currentCategory: "VID_TOVARA_UA" }187 }188 },189 {190 name: "mainViewed",191 options: {192 initState: { cnt: 0 }193 }194 },195 {196 name: "viewport",197 options: {198 initState: { viewport: "/" }199 }200 },201 {202 name: "error",203 options: {204 initState: {205 type: null,206 code: null,207 class: null,208 method: null,209 dependencies: null210 }211 }212 },213 {214 name: "productCardType",215 options: {216 initState: {217 type: null218 }219 }220 },221 {222 name: "productCardState",223 options: {224 initState: {225 open: false,226 key: null,227 item: null,228 spec: false229 }230 }231 },232 {233 name: "restsData",234 options: {235 initState: {236 origin: null,237 parsed: null,238 err: null239 }240 }241 },242 {243 name: "restsTab",244 options: {245 initState: {246 tab: "store"247 }248 }249 },250 {251 name: "availableOrder",252 options: {253 initState: {254 reserve: false,255 delivery: false,256 pickUp: false257 }258 }259 },260 {261 name: "orderSize",262 options: {263 initState: {264 size: null265 }266 }267 },268 {269 name: "orderSizeTarget",270 options: {271 initState: {272 rests: null273 }274 }275 },276 {277 name: "orderStep",278 options: {279 initState: { step: 0 }280 }281 },282 {283 name: "orderType",284 options: {285 initState: { type: null }286 }287 },288 {289 name: "orderDeliveryType",290 options: {291 initState: { type: null }292 }293 },294 {295 name: "orderCity",296 options: {297 initState: { city: null }298 }299 },300 {301 name: "orderStore",302 options: {303 initState: { store: null }304 }305 },306 {307 name: "orderCode",308 options: {309 initState: { code: null }310 }311 }312];...

Full Screen

Full Screen

create-store.js

Source:create-store.js Github

copy

Full Screen

1import { createStore, applyMiddleware, compose } from 'redux'2import createSagaMiddleware from 'redux-saga'3import authMiddleware from './middlewares/auth-middleware'4import reducer from 'reducers/root'5import { canUseDOM, KEY_REFRESH_TOKEN } from './utils/fetch'6import merge from 'lodash.merge'7import { END } from 'redux-saga'8import rootSaga from 'sagas'9import { fromJS } from 'immutable'10import { routerMiddleware } from 'react-router-redux'11const middlewares = [authMiddleware]12// export const sagaMiddleware = createSagaMiddleware()13/**14 * function to create a redux store15 * history {object} from some createHistroy()16 * initState {object} initial state passed to this store17 * @return {object} return a redux store18 */19export default function(history, initState) {20 if (canUseDOM && initState) {21 // @todo: pass refresh token22 // initState = merge({}, initState, { auth: { refreshToken: localStorage.getItem(KEY_REFRESH_TOKEN) } })23 // need to serialize24 initState.app && (initState.app = fromJS(initState.app))25 initState.login && (initState.login = fromJS(initState.login))26 initState.auth && (initState.auth = fromJS(initState.auth))27 initState.simulate && (initState.simulate = fromJS(initState.simulate))28 initState.locale && (initState.locale = fromJS(initState.locale))29 initState.patient && (initState.patient = fromJS(initState.patient))30 fromJSNested(initState.overview)31 initState.record && (initState.record = fromJS(initState.record))32 fromJSNested(initState.admin)33 initState.table && (initState.table = fromJS(initState.table))34 initState.effective && (initState.effective = fromJS(initState.effective))35 initState.globalConfigs && (initState.globalConfigs = fromJS(initState.globalConfigs))36 }37 const sagaMiddleware = createSagaMiddleware()38 const finalCreateStore = compose(39 applyMiddleware(...middlewares, routerMiddleware(history), sagaMiddleware),40 __DEV__ && typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f41 )(createStore)42 const store = finalCreateStore(reducer, initState)43 store.runSaga = sagaMiddleware.run44 store.closeSaga = () => store.dispatch(END)45 // sagaMiddleware.run(updateTimeTask)46 if (canUseDOM && __DEV__ && module.hot) {47 // Enable Webpack hot module replacement for reducers48 module.hot.accept('./reducers/root', () => {49 const nextRootReducer = require('reducers/root').default50 store.replaceReducer(nextRootReducer)51 })52 }53 return store54}55function fromJSPatient(patientState) {56 patientState.profile && (patientState.profile = fromJS(patientState.profile))57 if (patientState.infos) {58 const keys = Object.keys(patientState.infos)59 keys.forEach((key) => {60 patientState.infos[key] = fromJS(patientState.infos[key])61 })62 }63}64function fromJSNested(nestedState) {65 const keys = Object.keys(nestedState)66 keys.forEach((key) => {67 nestedState[key] = fromJS(nestedState[key])68 })...

Full Screen

Full Screen

action.js

Source:action.js Github

copy

Full Screen

1const Zero = () => ({type : "ZERO"})2const One = () => ({type : "ONE"})3const Two = () => ({type : "TWO"})4const Three = () => ({type : "THREE"})5const Four = () => ({type : "FOUR"})6const Five = () => ({type : "FIVE"})7const Six = () => ({type : "SIX"})8const Seven = () => ({type : "SEVEN"})9const Eight = () => ({type : "EIGHT"})10const Nine = () => ({type : "NINE"})11const Plus = () => ({type : "PLUS"})12const Minus = () => ({type : "MINUS"})13const Multiply = () => ({type : "MULTIPLY"})14const Divide = () => ({type : "DIVIDE"})15const Equals = () => ({type : "EQUALS"})16const Clear = () => ({type : "CLEAR"})17const initstate = [];18 19const Action = (state = initstate, action) => {20 if(action.type === "ZERO"){21 console.log(action.type)22 return (initstate.push(0),[...initstate])23 }24 if(action.type === "ONE"){25 console.log(action.type)26 return (initstate.push(1),[...initstate])27 }28 if(action.type === "TWO") {29 console.log(action.type)30 return (initstate.push(2),[...initstate])31 }32 if(action.type === "THREE") {33 console.log(action.type)34 return (initstate.push(3),[...initstate])35 }36 if(action.type === "FOUR") {37 console.log(action.type)38 return (initstate.push(4),[...initstate])39 }40 if(action.type === "FIVE") {41 console.log(action.type)42 return (initstate.push(5),[...initstate])43 }44 if(action.type === "SIX") {45 console.log(action.type)46 return (initstate.push(6),[...initstate])47 }48 if(action.type === "SEVEN") {49 console.log(action.type)50 return (initstate.push(7),[...initstate])51 }52 if(action.type === "EIGHT") {53 console.log(action.type)54 return (initstate.push(8),[...initstate])55 }56 if(action.type === "NINE") {57 console.log(action.type)58 return (initstate.push(9),[...initstate])59 }60 if(action.type === "PLUS") {61 return (initstate.push("+"),[...initstate])62 }63 if(action.type === "MINUS") {64 return (initstate.push("-"),[...initstate])65 }66 if(action.type === "MULTIPLY") {67 return (initstate.push("*"),[...initstate])68 }69 if(action.type === "DIVIDE") {70 return (initstate.push("/"),[...initstate])71 }72 if(action.type === "EQUALS") {73 return (initstate.push("="),[...initstate]) 74 }75 if(action.type === "CLEAR") {76 return state = 077 }78 return state;79}80export default Action;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.close();7 await context.close();8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch({ headless: false });13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.close();16 await context.close();17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch({ headless: false });22 const context = await browser.newContext();23 const page = await context.newPage();24 await page.close();25 await context.close();26 await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch({ headless: false });31 const context = await browser.newContext();32 const page = await context.newPage();33 await page.close();34 await context.close();35 await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch({ headless: false });40 const context = await browser.newContext();41 const page = await context.newPage();42 await page.close();43 await context.close();44 await browser.close();45})();46const { chromium } = require('playwright');47(async () => {48 const browser = await chromium.launch({ headless: false });49 const context = await browser.newContext();50 const page = await context.newPage();51 await page.close();52 await context.close();53 await browser.close();54})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext({ storageState: 'state.json' });5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9{10 {11 }12 {13 {14 }15 }16}17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext({ storageState: 'state.json' });21 const page = await context.newPage();22 await page.screenshot({ path: `example.png` });23 await browser.close();24})();25{26 {27 }28 {29 {30 }31 }32}33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext({ storageState: 'state.json' });37 const page = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { initState } = require('playwright/lib/server/playwright.js');2(async () => {3 const browser = await initState();4 const page = await browser.newPage();5 await page.screenshot({ path: 'example.png' });6 await browser.close();7})();8const { browserType } = require('playwright/lib/server/playwright.js');9(async () => {10 const browser = await browserType('chromium').launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'example.png' });13 await browser.close();14})();15const { launchServer } = require('playwright/lib/server/playwright.js');16(async () => {17 const server = await launchServer({ port: 3000 });18 const browser = await server.browserType('chromium').launch();19 const page = await browser.newPage();20 await page.screenshot({ path: 'example.png' });21 await browser.close();22 await server.close();23})();24const { launchPersistentServer } = require('playwright/lib/server/playwright.js');25(async () => {26 const server = await launchPersistentServer({27 });28 const browser = await server.browserType('chromium').launch();29 const page = await browser.newPage();30 await page.screenshot({ path: 'example.png' });31 await browser.close();32 await server.close();33})();34const { connectOverCDP } = require('playwright/lib/server/playwright.js');35(async () => {36 const page = await browser.newPage();37 await page.screenshot({ path: 'example.png' });38 await browser.close();39})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { initState } = require('playwright/lib/server/state');2const { chromium } = require('playwright');3(async () => {4 const state = await initState();5 const browser = await chromium.launch({ state });6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();11const { initState } = require('playwright/lib/server/state');12const { chromium } = require('playwright');13(async () => {14 const state = await initState();15 const browser = await chromium.launch({ state });16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.screenshot({ path: 'example.png' });19 await browser.close();20})();21const { initState } = require('playwright/lib/server/state');22const { chromium } = require('playwright');23(async () => {24 const state = await initState();25 const browser = await chromium.launch({ state });26 const context = await browser.newContext();27 const page = await context.newPage();28 await page.screenshot({ path: 'example.png' });29 await browser.close();30})();31const { initState } = require('playwright/lib/server/state');32const { chromium } = require('playwright');33(async () => {34 const state = await initState();35 const browser = await chromium.launch({ state });36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.screenshot({ path: 'example.png' });39 await browser.close();40})();41const { initState } = require('playwright/lib/server/state');42const { chromium } = require('playwright');43(async () => {44 const state = await initState();45 const browser = await chromium.launch({ state });46 const context = await browser.newContext();

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const { initState } = require('playwright/lib/server/initState');3const { chromium } = require('playwright');4(async () => {5 const state = await initState();6 const browser = await chromium.connect({7 });8 const page = await browser.newPage();9 await page.screenshot({ path: 'example.png' });10 await browser.close();11})();12const playwright = require('playwright');13const { initState } = require('playwright/lib/server/initState');14const { chromium } = require('playwright');15(async () => {16 const state = await initState();17 const browser = await chromium.connect({18 });19 const page = await browser.newPage();20 await page.screenshot({ path: 'example.png' });21 await browser.close();22})();23const { chromium } = require('playwright');24const browser = await chromium.launch();25const browserWSEndpoint = browser.wsEndpoint();26await browser.close();27const { chromium } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { initState } from 'playwright-core/lib/server/browserContext';2import { Page } from 'playwright-core/lib/server/page';3import { Frame } from 'playwright-core/lib/server/frames';4const page = new Page();5const frame = new Frame();6initState(page, frame);7import { initState } from 'playwright/lib/server/browserContext';8import { Page } from 'playwright/lib/server/page';9import { Frame } from 'playwright/lib/server/frames';10const page = new Page();11const frame = new Frame();12initState(page, frame);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { InternalState } = require('playwright/lib/server/browserContext');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const state = await InternalState.getOrCreate(page);8 await state.initState({9 viewportSize: { width: 1024, height: 768 },10 userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'11 });12 await page.screenshot({ path: `example.png` });13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright');2const { initPlaywrightState } = Playwright;3const { BrowserContext } = require('playwright/lib/server/browserContext');4const { Page } = require('playwright/lib/server/page');5const { Frame } = require('playwright/lib/server/frame');6const { Worker } = require('playwright/lib/server/worker');7const { WebSocketTransport } = require('playwright/lib/server/webSocketTransport');8const { Browser } = require('playwright/lib/server/browser');9const { BrowserServer } = require('playwright/lib/server/browserServer');10const { Android } = require('playwright/lib/server/android');11const { AndroidDevice } = require('playwright/lib/server/androidDevice');12const { helper } = require('playwright/lib/server/helper');13const { debugLogger } = require('playwright/lib/server/logger');14const { Connection } = require('playwright/lib/server/connection');15const { TimeoutSettings } = require('playwright/lib/server/timeoutSettings');16const { Events } = require('playwright/lib/server/events');17const { BrowserType } = require('playwright/lib/server/browserType');18const { Electron } = require('playwright/lib/server/electron');19const { ElectronApplication } = require('playwright/lib/server/electronApplication');20const { ElectronProcess } = require('playwright/lib/server/electronProcess');21const { FFBrowser } = require('playwright/lib/server/firefox/ffBrowser');22const { FFBrowserContext } = require('playwright/lib/server/firefox/ffBrowserContext');23const { FFConnection } = require('playwright/lib/server/firefox/ffConnection');24const { FFPage } = require('playwright/lib/server/firefox/ffPage');25const { FFSession } = require('playwright/lib/server/firefox/ffSession');26const { FFTracing } = require('playwright/lib/server/firefox/ffTracing');27const { FFVideo } = require('playwright/lib/server/firefox/ffVideo');28const { ChromiumBrowser } = require('playwright/lib/server/chromium/chromiumBrowser');29const { ChromiumBrowserContext } = require('playwright/lib/server/chromium/chromiumBrowserContext');30const { ChromiumConnection } = require('playwright/lib/server/chromium/chromiumConnection');31const { ChromiumDownloader } = require('playwright/lib/server/chromium/chromiumDownloader');32const { ChromiumPage } = require('playwright/lib

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