How to use abortController method in wpt

Best JavaScript code snippet using wpt

reducer.test.js

Source:reducer.test.js Github

copy

Full Screen

1import { fromJS } from 'immutable';2import reducer from '../reducer';3describe('UPLOAD | containers | ModalStepper | reducer', () => {4 describe('default action', () => {5 it('should return the initialState', () => {6 const action = {7 type: 'TEST',8 };9 const initialState = fromJS({10 test: true,11 });12 expect(reducer(initialState, action)).toEqual(initialState);13 });14 });15 describe('ADD_FILES_TO_UPLOAD', () => {16 it('should add the files to the empty filesToUpload array and update the current step', () => {17 const action = {18 type: 'ADD_FILES_TO_UPLOAD',19 filesToUpload: {20 0: { name: 'test1', ok: true },21 1: { name: 'test2', ok: false },22 },23 nextStep: 'test',24 };25 const state = fromJS({26 currentStep: 'browse',27 filesToUpload: [],28 });29 const expected = fromJS({30 currentStep: 'test',31 filesToUpload: [32 {33 abortController: new AbortController(),34 file: { name: 'test1', ok: true },35 fileInfo: {36 alternativeText: '',37 caption: '',38 name: 'test1',39 },40 originalName: 'test1',41 hasError: false,42 errorMessage: null,43 isUploading: false,44 originalIndex: 0,45 tempId: null,46 },47 {48 abortController: new AbortController(),49 file: { name: 'test2', ok: false },50 fileInfo: {51 alternativeText: '',52 caption: '',53 name: 'test2',54 },55 originalName: 'test2',56 hasError: false,57 errorMessage: null,58 isUploading: false,59 originalIndex: 1,60 tempId: null,61 },62 ],63 });64 expect(reducer(state, action)).toEqual(expected);65 });66 it('should add the files to the (not empty) filesToUpload array and update the current step', () => {67 const action = {68 type: 'ADD_FILES_TO_UPLOAD',69 filesToUpload: {70 0: { name: 'test2', test: true },71 1: { name: 'test3', test: false },72 },73 nextStep: 'test',74 };75 const state = fromJS({76 currentStep: 'browse',77 filesToUpload: [78 {79 abortController: new AbortController(),80 file: { name: 'test1', ok: true },81 fileInfo: {82 alternativeText: '',83 caption: '',84 name: 'test1',85 },86 originalName: 'test1',87 hasError: false,88 errorMessage: null,89 isUploading: false,90 originalIndex: 0,91 tempId: null,92 },93 ],94 });95 const expected = fromJS({96 currentStep: 'test',97 filesToUpload: [98 {99 abortController: new AbortController(),100 file: { name: 'test1', ok: true },101 fileInfo: {102 alternativeText: '',103 caption: '',104 name: 'test1',105 },106 originalName: 'test1',107 hasError: false,108 errorMessage: null,109 isUploading: false,110 originalIndex: 0,111 tempId: null,112 },113 {114 abortController: new AbortController(),115 file: { name: 'test2', test: true },116 fileInfo: {117 alternativeText: '',118 caption: '',119 name: 'test2',120 },121 originalName: 'test2',122 hasError: false,123 errorMessage: null,124 isUploading: false,125 originalIndex: 1,126 tempId: null,127 },128 {129 abortController: new AbortController(),130 file: { name: 'test3', test: false },131 fileInfo: {132 alternativeText: '',133 caption: '',134 name: 'test3',135 },136 originalName: 'test3',137 hasError: false,138 errorMessage: null,139 isUploading: false,140 originalIndex: 2,141 tempId: null,142 },143 ],144 });145 expect(reducer(state, action)).toEqual(expected);146 });147 it('should work if the filesToUpload is empty', () => {148 const action = {149 type: 'ADD_FILES_TO_UPLOAD',150 filesToUpload: {},151 nextStep: 'test',152 };153 const state = fromJS({154 currentStep: 'browse',155 filesToUpload: [156 {157 abortController: new AbortController(),158 file: { ok: true },159 hasError: false,160 errorMessage: null,161 isUploading: false,162 originalIndex: 0,163 tempId: null,164 },165 ],166 });167 const expected = fromJS({168 currentStep: 'test',169 filesToUpload: [170 {171 abortController: new AbortController(),172 file: { ok: true },173 hasError: false,174 errorMessage: null,175 isUploading: false,176 originalIndex: 0,177 tempId: null,178 },179 ],180 });181 expect(reducer(state, action)).toEqual(expected);182 });183 });184 describe('ADD_URLS_TO_FILES_TO_UPLOAD', () => {185 it('should add the files to the empty filesToUpload array and update the current step', () => {186 const action = {187 type: 'ADD_URLS_TO_FILES_TO_UPLOAD',188 nextStep: 'test',189 };190 const state = fromJS({191 currentStep: 'browse',192 filesToUpload: [],193 filesToDownload: ['http://www.un.com/photo-1', 'http://www.deux.com/photo-2'],194 });195 const firstURL = new URL('http://www.un.com/photo-1');196 const firstURLName = decodeURIComponent(197 firstURL.pathname.substring(firstURL.pathname.lastIndexOf('/') + 1)198 );199 const secondURL = new URL('http://www.deux.com/photo-2');200 const secondURLName = decodeURIComponent(201 secondURL.pathname.substring(secondURL.pathname.lastIndexOf('/') + 1)202 );203 const expected = fromJS({204 currentStep: 'test',205 filesToDownload: [],206 filesToUpload: [207 {208 file: null,209 fileInfo: {210 alternativeText: '',211 caption: '',212 name: firstURLName,213 },214 originalName: firstURLName,215 originalIndex: 0,216 fileURL: firstURL,217 hasError: false,218 errorMessage: null,219 isUploading: false,220 isDownloading: true,221 tempId: 1,222 },223 {224 file: null,225 fileInfo: {226 alternativeText: '',227 caption: '',228 name: secondURLName,229 },230 originalName: secondURLName,231 originalIndex: 1,232 fileURL: secondURL,233 hasError: false,234 errorMessage: null,235 isUploading: false,236 isDownloading: true,237 tempId: 2,238 },239 ],240 });241 const received = reducer(state, action);242 expect(received.get('currentStep')).toEqual(expected.get('currentStep'));243 expect(received.get('filesToDownload')).toEqual(expected.get('filesToDownload'));244 expect(received.get('filesToUpload').toJS()).toEqual(245 expect.arrayContaining([246 expect.objectContaining(expected.getIn(['filesToUpload', '0']).toJS()),247 expect.objectContaining(expected.getIn(['filesToUpload', '1']).toJS()),248 ])249 );250 });251 it('should add the files to the (not empty) filesToUpload array and update the current step', () => {252 const state = fromJS({253 currentStep: 'browse',254 filesToDownload: ['http://www.trois.com/photo-3', 'http://www.quatre.com/photo-4'],255 filesToUpload: [256 {257 abortController: new AbortController(),258 file: { name: 'test1', ok: true },259 fileInfo: {260 alternativeText: '',261 caption: '',262 name: 'test1',263 },264 originalName: 'test1',265 hasError: false,266 errorMessage: null,267 isUploading: false,268 originalIndex: 0,269 tempId: null,270 },271 {272 file: null,273 fileInfo: {274 alternativeText: '',275 caption: '',276 name: 'test1',277 },278 originalName: 'test1',279 originalIndex: 1,280 fileURL: 'test1',281 hasError: false,282 errorMessage: null,283 isUploading: false,284 isDownloading: true,285 tempId: 2,286 },287 ],288 });289 const action = {290 type: 'ADD_URLS_TO_FILES_TO_UPLOAD',291 nextStep: 'test',292 };293 const firstURL = new URL('http://www.trois.com/photo-3');294 const firstURLName = decodeURIComponent(295 firstURL.pathname.substring(firstURL.pathname.lastIndexOf('/') + 1)296 );297 const secondURL = new URL('http://www.quatre.com/photo-4');298 const secondURLName = decodeURIComponent(299 secondURL.pathname.substring(secondURL.pathname.lastIndexOf('/') + 1)300 );301 const expected = fromJS({302 currentStep: 'test',303 filesToDownload: [],304 filesToUpload: [305 {306 abortController: new AbortController(),307 file: { name: 'test1', ok: true },308 fileInfo: {309 alternativeText: '',310 caption: '',311 name: 'test1',312 },313 originalName: 'test1',314 hasError: false,315 errorMessage: null,316 isUploading: false,317 originalIndex: 0,318 tempId: null,319 },320 {321 file: null,322 fileInfo: {323 alternativeText: '',324 caption: '',325 name: 'test1',326 },327 originalName: 'test1',328 originalIndex: 1,329 fileURL: 'test1',330 hasError: false,331 errorMessage: null,332 isUploading: false,333 isDownloading: true,334 tempId: 2,335 },336 {337 file: null,338 fileInfo: {339 alternativeText: '',340 caption: '',341 name: firstURLName,342 },343 originalName: firstURLName,344 originalIndex: 2,345 fileURL: firstURL,346 hasError: false,347 errorMessage: null,348 isUploading: false,349 isDownloading: true,350 tempId: 3,351 },352 {353 file: null,354 fileInfo: {355 alternativeText: '',356 caption: '',357 name: secondURLName,358 },359 originalName: secondURLName,360 originalIndex: 3,361 fileURL: secondURL,362 hasError: false,363 errorMessage: null,364 isUploading: false,365 isDownloading: true,366 tempId: 4,367 },368 ],369 });370 const received = reducer(state, action);371 expect(received.get('currentStep')).toEqual(expected.get('currentStep'));372 expect(received.get('filesToDownload')).toEqual(expected.get('filesToDownload'));373 expect(received.get('filesToUpload').toJS()).toEqual(374 expect.arrayContaining([375 expect.objectContaining(expected.getIn(['filesToUpload', '0']).toJS()),376 expect.objectContaining(expected.getIn(['filesToUpload', '1']).toJS()),377 expect.objectContaining(expected.getIn(['filesToUpload', '2']).toJS()),378 expect.objectContaining(expected.getIn(['filesToUpload', '3']).toJS()),379 ])380 );381 });382 });383 describe('CLEAN_FILES_ERROR', () => {384 it('should not change the filesToUpload property if it is empty', () => {385 const action = {386 type: 'CLEAN_FILES_ERROR',387 };388 const state = fromJS({389 currentStep: 'test',390 filesToUpload: [],391 });392 expect(reducer(state, action)).toEqual(state);393 });394 it('should remove the errors of all files from the filesToUploadArray', () => {395 const action = {396 type: 'CLEAN_FILES_ERROR',397 };398 const state = fromJS({399 currentStep: 'test',400 filesToUpload: [401 {402 abortController: new AbortController(),403 file: { ok: true },404 hasError: true,405 errorMessage: 'error1',406 isUploading: false,407 originalIndex: 0,408 },409 {410 abortController: new AbortController(),411 file: { test: true },412 hasError: true,413 errorMessage: 'error2',414 isUploading: false,415 originalIndex: 1,416 },417 {418 abortController: new AbortController(),419 file: { test: false },420 hasError: true,421 errorMessage: 'error3',422 isUploading: false,423 originalIndex: 2,424 },425 ],426 });427 const expected = fromJS({428 currentStep: 'test',429 filesToUpload: [430 {431 abortController: new AbortController(),432 file: { ok: true },433 hasError: false,434 errorMessage: null,435 isUploading: false,436 originalIndex: 0,437 },438 {439 abortController: new AbortController(),440 file: { test: true },441 hasError: false,442 errorMessage: null,443 isUploading: false,444 originalIndex: 1,445 },446 {447 abortController: new AbortController(),448 file: { test: false },449 hasError: false,450 errorMessage: null,451 isUploading: false,452 originalIndex: 2,453 },454 ],455 });456 expect(reducer(state, action)).toEqual(expected);457 });458 it('should not change the data containing a defined tempId key', () => {459 const action = {460 type: 'CLEAN_FILES_ERROR',461 };462 const state = fromJS({463 currentStep: 'test',464 filesToUpload: [465 {466 abortController: new AbortController(),467 file: { ok: true },468 hasError: true,469 errorMessage: 'error1',470 isUploading: false,471 originalIndex: 0,472 },473 {474 abortController: new AbortController(),475 file: { test: true },476 hasError: true,477 errorMessage: 'error2',478 isUploading: false,479 originalIndex: 1,480 tempId: 1,481 },482 {483 abortController: new AbortController(),484 file: { test: false },485 hasError: true,486 errorMessage: 'error3',487 isUploading: false,488 originalIndex: 2,489 },490 ],491 });492 const expected = fromJS({493 currentStep: 'test',494 filesToUpload: [495 {496 abortController: new AbortController(),497 file: { ok: true },498 hasError: false,499 errorMessage: null,500 isUploading: false,501 originalIndex: 0,502 },503 {504 abortController: new AbortController(),505 file: { test: true },506 hasError: true,507 errorMessage: 'error2',508 isUploading: false,509 originalIndex: 1,510 tempId: 1,511 },512 {513 abortController: new AbortController(),514 file: { test: false },515 hasError: false,516 errorMessage: null,517 isUploading: false,518 originalIndex: 2,519 },520 ],521 });522 expect(reducer(state, action)).toEqual(expected);523 });524 });525 describe('FILE_DOWLOADED', () => {526 it('should update the corresponding file', () => {527 const state = fromJS({528 currentStep: 'browse',529 filesToDownload: [],530 filesToUpload: [531 {532 abortController: new AbortController(),533 file: { name: 'test1', ok: true },534 fileInfo: {535 alternativeText: '',536 caption: '',537 name: 'test1',538 },539 hasError: false,540 errorMessage: null,541 isUploading: false,542 originalIndex: 0,543 tempId: null,544 },545 {546 file: null,547 fileInfo: {548 alternativeText: '',549 caption: '',550 name: 'test1',551 },552 originalIndex: 1,553 fileURL: 'test1',554 hasError: false,555 errorMessage: null,556 isUploading: false,557 isDownloading: true,558 tempId: 2,559 },560 ],561 });562 const action = {563 type: 'FILE_DOWNLOADED',564 fileTempId: 2,565 blob: 'test',566 };567 const expected = fromJS({568 currentStep: 'browse',569 filesToDownload: [],570 filesToUpload: [571 {572 abortController: new AbortController(),573 file: { name: 'test1', ok: true },574 fileInfo: {575 alternativeText: '',576 caption: '',577 name: 'test1',578 },579 hasError: false,580 errorMessage: null,581 isUploading: false,582 originalIndex: 0,583 tempId: null,584 },585 {586 file: 'test',587 fileInfo: {588 alternativeText: '',589 caption: '',590 name: 'test1',591 },592 originalIndex: 1,593 fileURL: 'test1',594 hasError: false,595 errorMessage: null,596 isUploading: false,597 isDownloading: false,598 tempId: 2,599 },600 ],601 });602 expect(reducer(state, action)).toEqual(expected);603 });604 });605 describe('GO_TO', () => {606 it('should update the current step', () => {607 const action = {608 type: 'GO_TO',609 to: 'test',610 };611 const state = fromJS({612 currentStep: 'browse',613 });614 const expected = fromJS({615 currentStep: 'test',616 });617 expect(reducer(state, action)).toEqual(expected);618 });619 });620 describe('INIT_FILE_TO_EDIT', () => {621 it('should set the fileToEdit object correctly', () => {622 const action = {623 type: 'INIT_FILE_TO_EDIT',624 fileToEdit: {625 test: 'test',626 },627 };628 const state = fromJS({629 fileToEdit: null,630 currentStep: 'test',631 });632 const expected = fromJS({633 fileToEdit: {634 test: 'test',635 },636 currentStep: 'test',637 });638 expect(reducer(state, action)).toEqual(expected);639 });640 });641 describe('ON_ABORT_UPLOAD', () => {642 it('should set the isUploading key to false', () => {643 const action = {644 type: 'ON_ABORT_UPLOAD',645 };646 const state = fromJS({647 fileToEdit: {648 test: 'test',649 isUploading: true,650 },651 currentStep: 'test',652 });653 const expected = fromJS({654 fileToEdit: {655 test: 'test',656 isUploading: false,657 },658 currentStep: 'test',659 });660 expect(reducer(state, action)).toEqual(expected);661 });662 });663 describe('ON_CHANGE', () => {664 it('should change the data correctly', () => {665 const action = {666 type: 'ON_CHANGE',667 keys: 'test',668 value: 'test 1',669 };670 const state = fromJS({671 fileToEdit: {672 test: 'test',673 isUploading: true,674 },675 currentStep: 'test',676 });677 const expected = fromJS({678 fileToEdit: {679 test: 'test 1',680 isUploading: true,681 },682 currentStep: 'test',683 });684 expect(reducer(state, action)).toEqual(expected);685 });686 });687 describe('ON_CHANGE_URLS_TO_DOWNLOAD', () => {688 it('should change the data correctly', () => {689 const action = {690 type: 'ON_CHANGE_URLS_TO_DOWNLOAD',691 keys: 'test',692 value: ['test 1', 'test 2'],693 };694 const state = fromJS({695 filesToDownload: [],696 currentStep: 'test',697 });698 const expected = fromJS({699 filesToDownload: ['test 1', 'test 2'],700 currentStep: 'test',701 });702 expect(reducer(state, action)).toEqual(expected);703 });704 });705 describe('ON_SUBMIT_EDIT_EXISTING_FILE', () => {706 it('should set the isUploading key to false', () => {707 const action = {708 type: 'ON_SUBMIT_EDIT_EXISTING_FILE',709 };710 const state = fromJS({711 fileToEdit: {712 test: 'test',713 isUploading: false,714 },715 currentStep: 'test',716 });717 const expected = fromJS({718 fileToEdit: {719 test: 'test',720 isUploading: true,721 },722 currentStep: 'test',723 });724 expect(reducer(state, action)).toEqual(expected);725 });726 });727 describe('ON_SUBMIT_EDIT_NEW_FILE', () => {728 it('should update the filesToUploadList with the fileToEdit data', () => {729 const action = {730 type: 'ON_SUBMIT_EDIT_NEW_FILE',731 };732 const state = fromJS({733 currentStep: 'edit-new',734 filesToUpload: [735 {736 originalIndex: 0,737 file: {738 name: 'test',739 },740 },741 {742 originalIndex: 1,743 file: {744 test: false,745 },746 },747 {748 originalIndex: 2,749 file: {750 name: 'test2',751 },752 },753 ],754 fileToEdit: {755 originalIndex: 1,756 file: {757 test: true,758 otherTest: true,759 },760 },761 });762 const expected = fromJS({763 currentStep: 'edit-new',764 filesToUpload: [765 {766 originalIndex: 0,767 file: {768 name: 'test',769 },770 },771 {772 originalIndex: 1,773 file: {774 test: true,775 otherTest: true,776 },777 },778 {779 originalIndex: 2,780 file: {781 name: 'test2',782 },783 },784 ],785 fileToEdit: null,786 });787 expect(reducer(state, action)).toEqual(expected);788 });789 });790 describe('REMOVE_FILE_TO_UPLOAD', () => {791 it('should remove the file from the filesToUpload array', () => {792 const action = {793 type: 'REMOVE_FILE_TO_UPLOAD',794 fileIndex: 1,795 };796 const state = fromJS({797 currentStep: 'test',798 filesToUpload: [799 {800 abortController: new AbortController(),801 file: { ok: true },802 hasError: true,803 errorMessage: 'error1',804 isUploading: false,805 originalIndex: 0,806 },807 {808 abortController: new AbortController(),809 file: { test: true },810 hasError: true,811 errorMessage: 'error2',812 isUploading: false,813 originalIndex: 1,814 },815 {816 abortController: new AbortController(),817 file: { test: false },818 hasError: true,819 errorMessage: 'error3',820 isUploading: false,821 originalIndex: 2,822 },823 ],824 });825 const expected = fromJS({826 currentStep: 'test',827 filesToUpload: [828 {829 abortController: new AbortController(),830 file: { ok: true },831 hasError: true,832 errorMessage: 'error1',833 isUploading: false,834 originalIndex: 0,835 },836 {837 abortController: new AbortController(),838 file: { test: false },839 hasError: true,840 errorMessage: 'error3',841 isUploading: false,842 originalIndex: 2,843 },844 ],845 });846 expect(reducer(state, action)).toEqual(expected);847 });848 });849 describe('RESET_FILE_TO_UPLOAD', () => {850 it('should set the fileToEdit key to null', () => {851 const action = {852 type: 'RESET_FILE_TO_EDIT',853 };854 const state = fromJS({855 fileToEdit: 'test',856 });857 const expected = fromJS({858 fileToEdit: null,859 });860 expect(reducer(state, action)).toEqual(expected);861 });862 });863 describe('RESET_PROPS', () => {864 it('should return the initialState', () => {865 const action = { type: 'RESET_PROPS' };866 const state = { test: true };867 const expected = fromJS({868 currentStep: 'browse',869 filesToUpload: [],870 filesToDownload: [],871 fileToEdit: null,872 });873 expect(reducer(state, action)).toEqual(expected);874 });875 });876 describe('SET_CROP_RESULT', () => {877 it('should update the fileToEditEntry with the passed data', () => {878 const action = {879 type: 'SET_CROP_RESULT',880 blob: {881 test: true,882 },883 };884 const state = fromJS({885 fileToEdit: {886 originalIndex: 1,887 file: null,888 },889 });890 const expected = fromJS({891 fileToEdit: {892 originalIndex: 1,893 file: {894 test: true,895 },896 },897 });898 expect(reducer(state, action)).toEqual(expected);899 });900 });901 describe('SET_FILE_TO_DOWNLOAD_ERROR', () => {902 it('should update the specified file error', () => {903 const state = fromJS({904 currentStep: 'browse',905 filesToDownload: [],906 filesToUpload: [907 {908 abortController: new AbortController(),909 file: { name: 'test1', ok: true },910 fileInfo: {911 alternativeText: '',912 caption: '',913 name: 'test1',914 },915 hasError: false,916 errorMessage: null,917 isUploading: false,918 originalIndex: 0,919 tempId: null,920 },921 {922 file: null,923 fileInfo: {924 alternativeText: '',925 caption: '',926 name: 'test1',927 },928 fileOriginalName: 'test1-test',929 originalName: 'test1',930 originalIndex: 1,931 fileURL: 'test1',932 hasError: false,933 errorMessage: null,934 isUploading: false,935 isDownloading: true,936 tempId: 2,937 },938 ],939 });940 const action = {941 type: 'SET_FILE_TO_DOWNLOAD_ERROR',942 fileTempId: 2,943 };944 const expected = fromJS({945 currentStep: 'browse',946 filesToDownload: [],947 filesToUpload: [948 {949 abortController: new AbortController(),950 file: { name: 'test1', ok: true },951 fileInfo: {952 alternativeText: '',953 caption: '',954 name: 'test1',955 },956 hasError: false,957 errorMessage: null,958 isUploading: false,959 originalIndex: 0,960 tempId: null,961 },962 {963 file: null,964 fileInfo: {965 alternativeText: '',966 caption: '',967 name: 'test1',968 },969 originalIndex: 1,970 originalName: 'test1',971 fileOriginalName: 'test1-test',972 fileURL: 'test1',973 hasError: true,974 errorMessage: 'test1-test',975 isUploading: false,976 isDownloading: false,977 tempId: 2,978 },979 ],980 });981 expect(reducer(state, action)).toEqual(expected);982 });983 });984 describe('SET_FILE_ERROR', () => {985 it('should update the specified file error', () => {986 const action = {987 type: 'SET_FILE_ERROR',988 fileIndex: 1,989 errorMessage: 'size limit exceeded',990 };991 const state = fromJS({992 currentStep: 'test',993 filesToUpload: [994 {995 abortController: new AbortController(),996 file: { ok: true },997 hasError: false,998 errorMessage: null,999 isUploading: true,1000 originalIndex: 0,1001 },1002 {1003 abortController: new AbortController(),1004 file: { test: true },1005 hasError: false,1006 errorMessage: null,1007 isUploading: true,1008 originalIndex: 1,1009 },1010 {1011 abortController: new AbortController(),1012 file: { test: false },1013 hasError: false,1014 errorMessage: null,1015 isUploading: true,1016 originalIndex: 2,1017 },1018 ],1019 });1020 const expected = fromJS({1021 currentStep: 'test',1022 filesToUpload: [1023 {1024 abortController: new AbortController(),1025 file: { ok: true },1026 hasError: false,1027 errorMessage: null,1028 isUploading: true,1029 originalIndex: 0,1030 },1031 {1032 abortController: new AbortController(),1033 file: { test: true },1034 hasError: true,1035 errorMessage: 'size limit exceeded',1036 isUploading: false,1037 originalIndex: 1,1038 },1039 {1040 abortController: new AbortController(),1041 file: { test: false },1042 hasError: false,1043 errorMessage: null,1044 isUploading: true,1045 originalIndex: 2,1046 },1047 ],1048 });1049 expect(reducer(state, action)).toEqual(expected);1050 });1051 });1052 describe('SET_FILE_TO_EDIT', () => {1053 it('should set the fileToEdit key with the file at the passed index from the filesToUpload list', () => {1054 const action = {1055 type: 'SET_FILE_TO_EDIT',1056 fileIndex: 1,1057 };1058 const state = fromJS({1059 fileToEdit: null,1060 filesToUpload: [1061 {1062 originalIndex: 0,1063 file: {1064 name: 'test0',1065 },1066 },1067 {1068 originalIndex: 1,1069 file: {1070 name: 'test1',1071 },1072 },1073 {1074 originalIndex: 2,1075 file: {1076 name: 'test2',1077 },1078 },1079 ],1080 });1081 const expected = fromJS({1082 fileToEdit: {1083 originalIndex: 1,1084 file: {1085 name: 'test1',1086 },1087 },1088 filesToUpload: [1089 {1090 originalIndex: 0,1091 file: {1092 name: 'test0',1093 },1094 },1095 {1096 originalIndex: 1,1097 file: {1098 name: 'test1',1099 },1100 },1101 {1102 originalIndex: 2,1103 file: {1104 name: 'test2',1105 },1106 },1107 ],1108 });1109 expect(reducer(state, action)).toEqual(expected);1110 });1111 });1112 describe('SET_FILE_TO_EDIT_ERROR', () => {1113 it('should set the specified file error to fileToEdit', () => {1114 const action = {1115 type: 'SET_FILE_TO_EDIT_ERROR',1116 errorMessage: 'Bad request',1117 };1118 const state = fromJS({1119 fileToEdit: {1120 originalIndex: 1,1121 file: {1122 name: 'test1',1123 },1124 hasError: false,1125 errorMessage: null,1126 isUploading: true,1127 },1128 filesToUpload: [1129 {1130 originalIndex: 0,1131 file: {1132 name: 'test0',1133 },1134 },1135 {1136 originalIndex: 1,1137 file: {1138 name: 'test1',1139 },1140 },1141 {1142 originalIndex: 2,1143 file: {1144 name: 'test2',1145 },1146 },1147 ],1148 });1149 const expected = fromJS({1150 fileToEdit: {1151 originalIndex: 1,1152 file: {1153 name: 'test1',1154 },1155 hasError: true,1156 errorMessage: 'Bad request',1157 isUploading: false,1158 },1159 filesToUpload: [1160 {1161 originalIndex: 0,1162 file: {1163 name: 'test0',1164 },1165 },1166 {1167 originalIndex: 1,1168 file: {1169 name: 'test1',1170 },1171 },1172 {1173 originalIndex: 2,1174 file: {1175 name: 'test2',1176 },1177 },1178 ],1179 });1180 expect(reducer(state, action)).toEqual(expected);1181 });1182 });1183 describe('SET_FILES_UPLOADING_STATE', () => {1184 it('should change all the isUploading keys of the filesToUpload to true', () => {1185 const action = {1186 type: 'SET_FILES_UPLOADING_STATE',1187 };1188 const state = fromJS({1189 currentStep: 'test',1190 filesToUpload: [1191 {1192 abortController: new AbortController(),1193 file: { ok: true },1194 hasError: false,1195 errorMessage: 'test',1196 isUploading: true,1197 originalIndex: 0,1198 },1199 {1200 abortController: new AbortController(),1201 file: { test: true },1202 hasError: false,1203 errorMessage: null,1204 isUploading: false,1205 originalIndex: 1,1206 },1207 {1208 abortController: new AbortController(),1209 file: { test: false },1210 hasError: false,1211 errorMessage: null,1212 isUploading: false,1213 originalIndex: 2,1214 },1215 ],1216 });1217 const expected = fromJS({1218 currentStep: 'test',1219 filesToUpload: [1220 {1221 abortController: new AbortController(),1222 file: { ok: true },1223 hasError: false,1224 errorMessage: null,1225 isUploading: true,1226 originalIndex: 0,1227 },1228 {1229 abortController: new AbortController(),1230 file: { test: true },1231 hasError: false,1232 errorMessage: null,1233 isUploading: true,1234 originalIndex: 1,1235 },1236 {1237 abortController: new AbortController(),1238 file: { test: false },1239 hasError: false,1240 errorMessage: null,1241 isUploading: true,1242 originalIndex: 2,1243 },1244 ],1245 });1246 expect(reducer(state, action)).toEqual(expected);1247 });1248 });...

Full Screen

Full Screen

fetch.ts

Source:fetch.ts Github

copy

Full Screen

1/**2 * @license3 * Copyright Google Inc. All Rights Reserved.4 *5 * Use of this source code is governed by an MIT-style license that can be6 * found in the LICENSE file at https://angular.io/license7 */8Zone.__load_patch('fetch', (global: any, Zone: ZoneType, api: _ZonePrivate) => {9 const fetch = global['fetch'];10 const ZoneAwarePromise = global.Promise;11 const symbolThenPatched = api.symbol('thenPatched');12 const fetchTaskScheduling = api.symbol('fetchTaskScheduling');13 const fetchTaskAborting = api.symbol('fetchTaskAborting');14 if (typeof fetch !== 'function') {15 return;16 }17 const OriginalAbortController = global['AbortController'];18 const supportAbort = typeof OriginalAbortController === 'function';19 let abortNative: Function|null = null;20 if (supportAbort) {21 global['AbortController'] = function() {22 const abortController = new OriginalAbortController();23 const signal = abortController.signal;24 signal.abortController = abortController;25 return abortController;26 };27 abortNative = api.patchMethod(28 OriginalAbortController.prototype, 'abort',29 (delegate: Function) => (self: any, args: any) => {30 if (self.task) {31 return self.task.zone.cancelTask(self.task);32 }33 return delegate.apply(self, args);34 });35 }36 const placeholder = function() {};37 global['fetch'] = function() {38 const args = Array.prototype.slice.call(arguments);39 const options = args.length > 1 ? args[1] : null;40 const signal = options && options.signal;41 return new Promise((res, rej) => {42 const task = Zone.current.scheduleMacroTask(43 'fetch', placeholder, args,44 () => {45 let fetchPromise;46 let zone = Zone.current;47 try {48 (zone as any)[fetchTaskScheduling] = true;49 fetchPromise = fetch.apply(this, args);50 } catch (error) {51 rej(error);52 return;53 } finally {54 (zone as any)[fetchTaskScheduling] = false;55 }56 if (!(fetchPromise instanceof ZoneAwarePromise)) {57 let ctor = fetchPromise.constructor;58 if (!ctor[symbolThenPatched]) {59 api.patchThen(ctor);60 }61 }62 fetchPromise.then(63 (resource: any) => {64 if (task.state !== 'notScheduled') {65 task.invoke();66 }67 res(resource);68 },69 (error: any) => {70 if (task.state !== 'notScheduled') {71 task.invoke();72 }73 rej(error);74 });75 },76 () => {77 if (!supportAbort) {78 rej('No AbortController supported, can not cancel fetch');79 return;80 }81 if (signal && signal.abortController && !signal.aborted &&82 typeof signal.abortController.abort === 'function' && abortNative) {83 try {84 (Zone.current as any)[fetchTaskAborting] = true;85 abortNative.call(signal.abortController);86 } finally {87 (Zone.current as any)[fetchTaskAborting] = false;88 }89 } else {90 rej('cancel fetch need a AbortController.signal');91 }92 });93 if (signal && signal.abortController) {94 signal.abortController.task = task;95 }96 });97 };...

Full Screen

Full Screen

Seat.js

Source:Seat.js Github

copy

Full Screen

1import React, { useEffect, useState } from "react";2import {3 listTablesAvailable,4 readReservation,5 assignTable,6} from "../../utils/api";7import { useParams, useHistory } from "react-router";8import ErrorAlert from "../ErrorAlert";9function Seat() {10 const history = useHistory();11 const { reservationId } = useParams();12 const [reservation, setReservations] = useState({});13 const [selectedTable, setSelectedTable] = useState(1);14 const [tables, setTables] = useState([]);15 const [error, setError] = useState(null);16 useEffect(17 function getReservations() {18 const abortController = new AbortController();19 readReservation(reservationId, abortController.signal)20 .then(setReservations)21 .catch(setError);22 return () => abortController.abort();23 },24 [reservationId]25 );26 useEffect(getAvailableTables, [reservation.people]);27 function getAvailableTables() {28 const abortController = new AbortController();29 listTablesAvailable(30 { capacity: reservation.people },31 abortController.signal32 )33 .then(setTables)34 .catch(setError);35 return () => abortController.abort();36 }37 function handleSubmit(e) {38 e.preventDefault();39 40 const abortController = new AbortController();41 assignTable(42 reservation.reservation_id,43 selectedTable,44 abortController.signal45 )46 .then(() => {47 history.push(`/dashboard`);48 })49 .catch(setError);50 return () => abortController.abort();51 }52 return (53 <div>54 {error && <ErrorAlert error={error} />}55 <h2>Seat Selection</h2>56 <form onSubmit={handleSubmit}>57 <div className="form-group col-md-4 form-row align-items-center">58 <h3>Table Selection:</h3>59 <select60 name="table_id"61 onChange={({ target: { value } }) => {62 63 setSelectedTable(value);64 }}65 id="inputState"66 value={selectedTable}67 className="form-control"68 >69 {tables.map((table, i) => (70 <option key={table.table_id} value={table.table_id}>71 {table.table_name} - {table.capacity}72 </option>73 ))}74 </select>75 <button className="btn btn-dark mt-3" type="submit">76 Submit77 </button>78 <button79 className="btn btn-text mt-3"80 onClick={() => history.goBack()}81 >82 Cancel83 </button>84 </div>85 </form>86 </div>87 );88}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');2const controller = new AbortController();3const { signal } = controller;4const timeout = setTimeout(() => {5 controller.abort();6}, 1000);7const fetch = require('node-fetch');8fetch(url, { signal })9 .then(res => res.json())10 .then(json => console.log(json))11 .catch(err => console.error('timeout exceeded'));12const wpt = require('webpagetest');13}, (err, data) => {14 console.log(err);15 console.log(data);16});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');2const { fetch } = require('cross-fetch');3const controller = new AbortController();4const signal = controller.signal;5const options = {6 headers: {7 },8};9fetch(url, options)10 .then((res) => {11 console.log(res);12 })13 .catch((err) => {14 console.log(err);15 });16controller.abort();17const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');18const fetch = require('node-fetch');19const controller = new AbortController();20const signal = controller.signal;21const options = {22 headers: {23 },24};25fetch(url, options)26 .then((res) => {27 console.log(res);28 })29 .catch((err) => {30 console.log(err);31 });32controller.abort();33const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');34const axios = require('axios');35const controller = new AbortController();36const signal = controller.signal;37const options = {38 headers: {39 },40};41axios(url, options)42 .then((res) => {43 console.log(res);44 })45 .catch((err) => {46 console.log(err);47 });48controller.abort();49const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');50const request = require('request');

Full Screen

Using AI Code Generation

copy

Full Screen

1const fetch = require('node-fetch');2const AbortController = require('abort-controller');3const controller = new AbortController();4const signal = controller.signal;5const options = {6};7fetch(url, options)8 .then(res => {9 console.log(res);10 })11 .catch(err => {12 console.log(err);13 });14controller.abort();15[MIT](

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wptClient = wpt('www.webpagetest.org');3const abortController = new AbortController();4const signal = abortController.signal;5const options = {6};7const test = wptClient.runTest(testUrl, options);8abortController.abort();9const wpt = require('webpagetest');10const wptClient = wpt('www.webpagetest.org');11const options = {12};13const test = wptClient.runTest(testUrl, options);14const wpt = require('webpagetest');15const wptClient = wpt('www.webpagetest.org');16const options = {17};18const test = wptClient.runTest(testUrl, options);19const wpt = require('webpagetest');20const wptClient = wpt('www.webpagetest.org');21const options = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt 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