test_action-select-snapshot.js (1218B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests the reducer responding to the action `selectSnapshot(snapshot)` 8 */ 9 10 const actions = require("resource://devtools/client/memory/actions/snapshot.js"); 11 const { 12 snapshotState: states, 13 } = require("resource://devtools/client/memory/constants.js"); 14 15 add_task(async function () { 16 const front = new StubbedMemoryFront(); 17 await front.attach(); 18 const store = Store(); 19 20 for (let i = 0; i < 5; i++) { 21 store.dispatch(actions.takeSnapshot(front)); 22 } 23 24 await waitUntilState( 25 store, 26 ({ snapshots }) => snapshots.length === 5 && snapshots.every(isDone) 27 ); 28 29 for (let i = 0; i < 5; i++) { 30 info(`Selecting snapshot[${i}]`); 31 store.dispatch(actions.selectSnapshot(store.getState().snapshots[i].id)); 32 await waitUntilState(store, ({ snapshots }) => snapshots[i].selected); 33 34 const { snapshots } = store.getState(); 35 ok(snapshots[i].selected, `snapshot[${i}] selected`); 36 equal( 37 snapshots.filter(s => !s.selected).length, 38 4, 39 "All other snapshots are unselected" 40 ); 41 } 42 }); 43 44 function isDone(s) { 45 return s.state === states.SAVED; 46 }