How to use applyAction method in wpt

Best JavaScript code snippet using wpt

applyAction.spec.ts

Source:applyAction.spec.ts Github

copy

Full Screen

...6const WATERS_RISE_CARD:number = 20;7describe("applyAction:DrawTreasureCard", () => {8 it("should remove a treasure card from the deck", () => {9 let board = { ...b1, treasureCardsToDraw: 1, treasureStack: [ 1, 2, 3 ]};10 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);11 expect(board.treasureStack).toEqual([ 1, 2]);12 });13 it("should add card to player hand", () => {14 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, 3 ]};15 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);16 expect(board.players[0].cards).toEqual([19, 6, 3]);17 });18 it("should reduce cards left to draw", () => {19 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, 3 ]};20 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);21 expect(board.treasureCardsToDraw).toEqual(1);22 });23 it("waters rise... do not add card to player hand", () => {24 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, WATERS_RISE_CARD ]};25 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);26 expect(board.players[0].cards).toEqual(b1.players[0].cards);27 });28 it("waters rise... add card to treasure discard", () => {29 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, WATERS_RISE_CARD ], treasureDiscard: [ 5 ]};30 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);31 expect(board.treasureStack).toEqual([ 1, 2 ]);32 expect(board.treasureDiscard).toEqual([ 5, WATERS_RISE_CARD ]);33 });34 it("waters rise... add card to treasure discard (first discard)", () => {35 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, WATERS_RISE_CARD ], treasureDiscard: []};36 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);37 expect(board.treasureStack).toEqual([ 1, 2 ]);38 expect(board.treasureDiscard).toEqual([ WATERS_RISE_CARD ]);39 });40 it("waters rise... should increase water level by one", () => {41 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, WATERS_RISE_CARD ], waterLevel: 3};42 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);43 expect(board.waterLevel).toEqual(4);44 });45 it("waters rise... should reduce cards left to draw", () => {46 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, WATERS_RISE_CARD ]};47 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);48 expect(board.treasureCardsToDraw).toEqual(1);49 });50 it("waters rise... should shuffle flood discard and add to stack", () => {51 let board = { ...b1, treasureCardsToDraw: 2, treasureStack: [ 1, 2, WATERS_RISE_CARD ],52 floodStack: [ 1 , 2 ], floodDiscard: [ 3 , 4 ]};53 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);54 expect(board.floodDiscard).toEqual([]);55 expect(board.floodStack.length).toBe(4);56 if (board.floodStack[3] === 4) {57 expect(board.floodStack).toEqual([ 1, 2, 3, 4]);58 } else {59 expect(board.floodStack).toEqual([ 1, 2, 4, 3]);60 }61 });62 it("should shuffle deck first if stack empty", () => {63 let board = { ...b1, treasureCardsToDraw: 1, treasureStack: [ ], treasureDiscard: [ 1, 2 ]};64 board = applyAction(board, { type: ActionType.DrawTreasureCard}, 0);65 expect(board.treasureStack.length).toBe(1);66 if (board.treasureStack[0] === 1) {67 // Note: after shuffling, a card was drawn.68 expect(board.treasureStack).toEqual([ 1 ]);69 expect(board.players[0].cards).toEqual([19, 6, 2]);70 } else {71 expect(board.treasureStack).toEqual([ 2 ]);72 expect(board.players[0].cards).toEqual([19, 6, 1]);73 }74 expect(board.treasureDiscard).toEqual([ ]);75 });76});77describe("applyAction:DrawFloodCard", () => {78 it("should remove a flood card from the deck", () => {79 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ 1, 2, 3 ]};80 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);81 expect(board.floodStack).toEqual([ 1, 2 ]);82 });83 it("should add a flood card to discard", () => {84 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ 1, 2, 3 ], floodDiscard: []};85 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);86 expect(board.floodDiscard).toEqual([ 3 ]);87 });88 it("should add a flood card to discard (first discard)", () => {89 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ 1, 2, 3 ], floodDiscard: [ 4, 5 ]};90 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);91 expect(board.floodDiscard).toEqual([ 4, 5, 3 ]);92 });93 it("should flood tile if not flooded", () => {94 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ 1, 2, 10 ],95 tiles: [null, null, { id: 10, flooded: false }, { id: 11, flooded: true } ]96 };97 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);98 expect(board.tiles).toEqual([null, null, { id: 10, flooded: true }, { id: 11, flooded: true } ]);99 });100 it("should remove tile if flooded", () => {101 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ 1, 2, 11 ],102 tiles: [null, null, { id: 10, flooded: false }, { id: 11, flooded: true } ]103 };104 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);105 expect(board.tiles).toEqual([null, null, { id: 10, flooded: false }, null ]);106 });107 it("should remove card if flooded", () => {108 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ 1, 2, 11 ], floodDiscard: [ 3, 4 ],109 tiles: [null, null, { id: 10, flooded: false }, { id: 11, flooded: true } ]110 };111 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);112 expect(board.floodStack).toEqual([ 1, 2 ]);113 expect(board.floodDiscard).toEqual([ 3, 4 ]);114 });115 it("should shuffle deck first if stack empty", () => {116 let board = { ...b1, floodCardsToDraw: 1, floodStack: [ ], floodDiscard: [ 1, 2 ]};117 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);118 expect(board.floodStack.length).toBe(1);119 if (board.floodStack[0] === 1) {120 // Note: after shuffling, a card was drawn.121 expect(board.floodStack).toEqual([ 1 ]);122 expect(board.floodDiscard).toEqual([ 2 ]);123 } else {124 expect(board.floodStack).toEqual([ 2 ]);125 expect(board.floodDiscard).toEqual([ 1 ]);126 }127 });128});129describe("applyAction:GiveTreasureCard", () => {130 it("should remove card from current player", () => {131 let board = { ...b1, currentPlayer: 1, players: [132 { id: 0, role: 5, location: 19, cards: [19, 6] },133 { id: 1, role: 2, location: 18, cards: [9, 23, 14] },134 { id: 2, role: 1, location: 18, cards: [5, 6] }135 ]};136 board = applyAction(board, { type: ActionType.GiveTreasureCard, player: 2, card: 23 }, 1);137 expect(board.players[1].cards).toEqual([ 9, 14 ]);138 });139 it("should add card to receiving player", () => {140 let board = { ...b1, currentPlayer: 1, players: [141 { id: 0, role: 5, location: 19, cards: [19, 6] },142 { id: 1, role: 2, location: 18, cards: [9, 23, 14] },143 { id: 2, role: 1, location: 18, cards: [5, 6] }144 ]};145 board = applyAction(board, { type: ActionType.GiveTreasureCard, player: 2, card: 23 }, 1);146 expect(board.players[2].cards).toEqual([ 5, 6, 23 ]);147 });148 it("should take an action", () => {149 let board = { ...b1, currentPlayer: 1, actionsRemaining: 3, players: [150 { id: 0, role: 5, location: 19, cards: [19, 6] },151 { id: 1, role: 2, location: 18, cards: [9, 23, 14] },152 { id: 2, role: 1, location: 18, cards: [5, 6] }153 ]};154 board = applyAction(board, { type: ActionType.GiveTreasureCard, player: 2, card: 23 }, 1);155 expect(board.actionsRemaining).toEqual(2);156 });157});158describe("applyAction:CaptureTreasure", () => {159 it("should set correct treasure to true", () => {160 // treasure 2161 let board:BoardState = { ...b1, players: [162 { id: 0, role: 5, location: 10, cards: [10, 11, 12, 13] },163 { id: 1, role: 2, location: 19, cards: [23, 14] }164 ], treasuresCaptured: [true, false, false, true]}; 165 board = applyAction(board, { type: ActionType.CaptureTreasure }, 0);166 expect(board.treasuresCaptured).toEqual([true, false, true, true]);167 });168 it("should remove four cards of same treasure type and add them to discard pile", () => {169 let board:BoardState = { ...b1, players: [170 { id: 0, role: 5, location: 10, cards: [10, 11, 12, 13] },171 { id: 1, role: 2, location: 19, cards: [23, 14] }172 ], treasureDiscard: [3]}; 173 board = applyAction(board, { type: ActionType.CaptureTreasure }, 0);174 expect(board.players[0].cards).toEqual([]);175 expect(board.treasureDiscard).toEqual([3, 10, 11, 12, 13]);176 });177 it("should remove four cards of same treasure type and add them to discard pile (mixed w/ other card)", () => {178 let board:BoardState = { ...b1, players: [179 { id: 0, role: 5, location: 10, cards: [10, 13, 11, 0, 14] },180 { id: 1, role: 2, location: 19, cards: [23, 14] }181 ], treasureDiscard: [3]}; 182 board = applyAction(board, { type: ActionType.CaptureTreasure }, 0);183 expect(board.players[0].cards).toEqual([0]);184 expect(board.treasureDiscard).toEqual([3, 10, 13, 11, 14]);185 });186 it("should remove four cards of same treasure type and add them to discard pile (mixed with special card)", () => {187 let board:BoardState = { ...b1, players: [188 { id: 0, role: 5, location: 10, cards: [24, 12, 13, 11, 14] },189 { id: 1, role: 2, location: 19, cards: [23, 14] }190 ], treasureDiscard: []}; 191 board = applyAction(board, { type: ActionType.CaptureTreasure }, 0);192 expect(board.players[0].cards).toEqual([24]);193 expect(board.treasureDiscard).toEqual([12, 13, 11, 14]);194 });195 it("should remove ONLY four cards of same treasure type and add them to discard pile", () => {196 let board:BoardState = { ...b1, players: [197 { id: 0, role: 5, location: 10, cards: [10, 11, 12, 13, 14] },198 { id: 1, role: 2, location: 19, cards: [23, 14] }199 ], treasureDiscard: [3]}; 200 board = applyAction(board, { type: ActionType.CaptureTreasure }, 0);201 expect(board.players[0].cards).toEqual([14]);202 expect(board.treasureDiscard).toEqual([3, 10, 11, 12, 13]);203 });204 it("should take an action", () => {205 // treasure 2206 let board:BoardState = { ...b1, players: [207 { id: 0, role: 5, location: 10, cards: [10, 11, 12, 13] },208 { id: 1, role: 2, location: 19, cards: [23, 14] }209 ], actionsRemaining: 2}; 210 board = applyAction(board, { type: ActionType.CaptureTreasure }, 0);211 expect(board.actionsRemaining).toEqual(1);212 });213});214describe("applyAction indicates loss", () => {215 it("LOSS when water level too high", () => {216 let board = { ...b1, floodCardsToDraw: 2, waterLevel: 9};217 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);218 expect(board.outcome).toEqual(Outcome.LOSE);219 });220 it("NOT LOSS when water level okay", () => {221 let board = { ...b1, floodCardsToDraw: 2, waterLevel: 8};222 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);223 expect(board.outcome).toEqual(Outcome.NONE);224 });225 it("LOSS when exit sunk", () => {226 let board = { ...b1, floodCardsToDraw: 2,227 tiles: b1.tiles.filter((_, i) => i !== 14)}; // remove exit tile228 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);229 expect(board.outcome).toEqual(Outcome.LOSE);230 });231 it("LOSS when no tiles left for uncaptured treasure", () => {232 let board = { ...b1, floodCardsToDraw: 2, treasuresCaptured: [true, true, false, true],233 tiles: b1.tiles.filter((_, i) => i !== 10 && i !== 21)}; // remove both coffee tiles234 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);235 expect(board.outcome).toEqual(Outcome.LOSE);236 });237 it("NOT LOSS when one tile left for uncaptured treasure", () => {238 let board = { ...b1, floodCardsToDraw: 2, treasuresCaptured: [true, true, false, true],239 tiles: b1.tiles.filter((_, i) => i !== 10)}; // remove both coffee tiles240 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);241 expect(board.outcome).toEqual(Outcome.NONE);242 });243 it("NOT LOSS when no tiles left for captured treasure", () => {244 let board = { ...b1, floodCardsToDraw: 2, treasuresCaptured: [true, false, true, true],245 tiles: b1.tiles.filter((_, i) => i !== 10 && i !== 21)}; // remove both coffee tiles246 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);247 expect(board.outcome).toEqual(Outcome.NONE);248 });249 it("LOSS when player in water and can't move", () => {250 let board = { ...b1, floodCardsToDraw: 2,251 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 0 } ]252 };253 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);254 expect(board.outcome).toEqual(Outcome.LOSE);255 });256 it("NOT LOSS when player in water and can move", () => {257 let board = { ...b1, floodCardsToDraw: 2,258 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 1 } ]259 };260 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);261 expect(board.outcome).toEqual(Outcome.NONE);262 });263 it("LOSS when player in water and cannot move diagonally, swim, or fly", () => {264 let tiles = mockTiles(`265 **266 ---.267 ***...268 ..**..269 -...270 ..271 `);272 let board = { ...b1, tiles, floodCardsToDraw: 2, floodStack: [ 1, 2, 9 ],273 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 16, role: Role.NAVIGATOR } ]274 };275 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);276 expect(board.outcome).toEqual(Outcome.LOSE);277 });278 it("NOT LOSS when explorer in water and can move diagonally", () => {279 let tiles = mockTiles(`280 **281 ---.282 ***...283 ..**..284 -...285 ..286 `);287 let board = { ...b1, tiles, floodCardsToDraw: 2, floodStack: [ 1, 2, 9 ],288 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 16, role: Role.EXPLORER } ]289 };290 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);291 expect(board.outcome).toEqual(Outcome.NONE);292 });293 it("LOSS when explorer in water and cannot move diagonally", () => {294 let tiles = mockTiles(`295 **296 ---.297 ***...298 ..**..299 -...300 ..301 `);302 let board = { ...b1, tiles, floodCardsToDraw: 2, floodStack: [ 1, 2, 9 ],303 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 17, role: Role.EXPLORER } ]304 };305 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);306 expect(board.outcome).toEqual(Outcome.LOSE);307 });308 it("NOT LOSS when diver in water and can swim to safety", () => {309 let tiles = mockTiles(`310 **311 ---.312 ***...313 ..**..314 -...315 ..316 `);317 let board = { ...b1, tiles, floodCardsToDraw: 2, floodStack: [ 1, 2, 9 ],318 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 17, role: Role.DIVER } ]319 };320 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);321 expect(board.outcome).toEqual(Outcome.NONE);322 });323 it("NOT LOSS when pilot in water", () => {324 let tiles = mockTiles(`325 **326 ---.327 ***...328 .-**..329 ....330 ..331 `);332 let board = { ...b1, tiles, floodCardsToDraw: 2, floodStack: [ 1, 2, 9 ],333 players: [ ...b1.players.slice(0, 1), { ...b1.players[2], location: 28, role: Role.PILOT } ]334 };335 board = applyAction(board, { type: ActionType.DrawFloodCard}, 0);336 expect(board.outcome).toEqual(Outcome.NONE);337 });338});339describe("applyAction:Win", () => {340 it("should be available when player has Helicopter lift card & all players on exit & all treasures captured", () => {341 let board:BoardState = { ...b1, players: [342 { id: 0, role: 5, location: EXIT_LOCATION, cards: [10, HELICOPTER_LIFT_CARD, 11, 13] },343 { id: 1, role: 2, location: EXIT_LOCATION, cards: [19, 14] }344 ], treasuresCaptured: [ true, true, true, true ]}; 345 board = applyAction(board, { type: ActionType.Win}, 0);346 expect(board.outcome).toEqual(Outcome.WIN);347 });348});349describe("applyAction:Fly", () => {350 it("should set location and special", () => {351 let board:BoardState = { ...b1, players: [352 { id: 0, role: Role.PILOT, location: 19, cards: [19, 6] },353 { id: 1, role: 2, location: 18, cards: [9, 23, 14] }354 ]};355 board = applyAction(board, { type: ActionType.Fly, location: 2 }, 0);356 expect(board.players[0].location).toBe(2);357 expect(board.roleSpecial).toBe(true);358 });359 it("should set location but not special when escaping sunk tile", () => {360 let board:BoardState = { ...b1, players: [361 { id: 0, role: Role.PILOT, location: 15, cards: [19, 6] },362 { id: 1, role: 2, location: 18, cards: [9, 23, 14] }363 ]};364 board = applyAction(board, { type: ActionType.Fly, location: 2 }, 0);365 expect(board.players[0].location).toBe(2);366 expect(board.roleSpecial).toBeUndefined();367 });368});369describe("applyAction special", () => {370 it("should clear special for diver at end of turn", () => {371 let board:BoardState = { ...b1, players: [372 { id: 0, role: Role.DIVER, location: 20, cards: [10, 13] },373 { id: 1, role: Role.NAVIGATOR, location: EXIT_LOCATION, cards: [19, 14] }374 ], actionsRemaining: 1, roleSpecial: true}; 375 board = applyAction(board, { type: ActionType.Move, location: 21}, 0);376 expect(board.roleSpecial).toBeUndefined();377 });378 it("should clear special for engineer for any action", () => {379 let board:BoardState = { ...b1, players: [380 { id: 0, role: Role.ENGINEER, location: 20, cards: [10, 13] },381 { id: 1, role: Role.NAVIGATOR, location: EXIT_LOCATION, cards: [19, 14] }382 ], actionsRemaining: 2, roleSpecial: true}; 383 board = applyAction(board, { type: ActionType.Move, location: 21}, 0);384 expect(board.roleSpecial).toBeUndefined();385 });386 it("should not clear special for diver for any action", () => {387 let board:BoardState = { ...b1, players: [388 { id: 0, role: Role.DIVER, location: 20, cards: [10, 13] },389 { id: 1, role: Role.NAVIGATOR, location: EXIT_LOCATION, cards: [19, 14] }390 ], actionsRemaining: 2, roleSpecial: true}; 391 board = applyAction(board, { type: ActionType.Move, location: 21}, 0);392 expect(board.roleSpecial).toBe(true);393 });394});395describe("applyAction:ShoreUp for Engineer", () => {396 it("should flip tile & use action", () => {397 let board:BoardState = { ...b1, actionsRemaining: 2 };398 expect(board.tiles[19].flooded).toBe(true);399 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 0);400 expect(board.tiles[19].flooded).toBe(false);401 expect(board.actionsRemaining).toBe(1);402 expect(board.roleSpecial).toBeUndefined();403 });404 it("should flip tile & use last action", () => {405 let board:BoardState = { ...b1, actionsRemaining: 1 };406 expect(board.tiles[19].flooded).toBe(true);407 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 0);408 expect(board.tiles[19].flooded).toBe(false);409 expect(board.actionsRemaining).toBe(0);410 expect(board.treasureCardsToDraw).toBe(2);411 expect(board.roleSpecial).toBeUndefined();412 });413 it("should flip tile, use action, and set special for Engineer", () => {414 let board:BoardState = { ...b1, actionsRemaining: 2, currentPlayer: 2 };415 expect(board.tiles[19].flooded).toBe(true);416 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 2);417 expect(board.tiles[19].flooded).toBe(false);418 expect(board.actionsRemaining).toBe(1);419 expect(board.roleSpecial).toBe(true);420 });421 it("should flip tile, unset special, but not use action for Engineer's free second shore up", () => {422 let board:BoardState = { ...b1, actionsRemaining: 2, currentPlayer: 2, roleSpecial: true };423 expect(board.tiles[19].flooded).toBe(true);424 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 2);425 expect(board.tiles[19].flooded).toBe(false);426 expect(board.actionsRemaining).toBe(2); // still 2427 expect(board.roleSpecial).toBeUndefined(); // unset428 });429 it("should flip tile, unset special, but not use action near end for Engineer", () => {430 let board:BoardState = { ...b1, actionsRemaining: 1, currentPlayer: 2, roleSpecial: true };431 expect(board.tiles[19].flooded).toBe(true);432 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 2);433 expect(board.tiles[19].flooded).toBe(false);434 expect(board.actionsRemaining).toBe(1);435 expect(board.treasureCardsToDraw).toBe(0);436 expect(board.roleSpecial).toBeUndefined();437 });438 it("should flip tile, use action, and set special, but not end turn for Engineer", () => {439 let board:BoardState = { ...b1, actionsRemaining: 1, currentPlayer: 2 };440 expect(board.tiles[19].flooded).toBe(true);441 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 2);442 expect(board.tiles[19].flooded).toBe(false);443 expect(board.actionsRemaining).toBe(0);444 expect(board.treasureCardsToDraw).toBe(0); // not over yet445 expect(board.roleSpecial).toBe(true);446 });447 it("should flip tile, unset special and end turn at end for Engineer", () => {448 let board:BoardState = { ...b1, actionsRemaining: 0, currentPlayer: 2, roleSpecial: true };449 expect(board.tiles[19].flooded).toBe(true);450 board = applyAction(board, { type: ActionType.ShoreUp, location: 19}, 2);451 expect(board.tiles[19].flooded).toBe(false);452 expect(board.actionsRemaining).toBe(0);453 expect(board.treasureCardsToDraw).toBe(2); // over454 expect(board.roleSpecial).toBeUndefined();455 });...

Full Screen

Full Screen

queries.spec.js

Source:queries.spec.js Github

copy

Full Screen

...17 afterEach(() => {18 Date.now.mockRestore()19 })20 it('should init correctly', () => {21 applyAction(22 initQuery(23 'a',24 new Q({25 doctype: 'io.cozy.todos'26 })27 )28 )29 expect(state).toMatchSnapshot()30 })31 describe('updates', () => {32 beforeEach(() => {33 applyAction(34 initQuery(35 'a',36 new Q({37 doctype: 'io.cozy.todos'38 })39 )40 )41 })42 it('should correctly update', () => {43 applyAction(44 receiveQueryResult('a', {45 data: [TODO_1, TODO_2]46 })47 )48 expect(state).toMatchSnapshot()49 })50 it('should correctly update two queries', () => {51 applyAction(52 initQuery(53 'b',54 new Q({55 doctype: 'io.cozy.todos'56 })57 )58 )59 applyAction(60 receiveQueryResult('a', {61 data: [TODO_1, TODO_2]62 })63 )64 expect(state).toMatchSnapshot()65 })66 it('should correctly update a query with a selector', () => {67 const query = new Q({68 doctype: 'io.cozy.todos'69 })70 applyAction(initQuery('b', query.where({ done: true })))71 applyAction(72 receiveQueryResult('a', {73 data: [TODO_3]74 })75 )76 expect(state).toMatchSnapshot()77 })78 it('should correctly update a query with a $gt: null selector', () => {79 const query = new Q({80 doctype: 'io.cozy.todos'81 })82 applyAction(83 initQuery(84 'b',85 query.where({86 done: true,87 _id: {88 $gt: null89 }90 })91 )92 )93 applyAction(94 receiveQueryResult('a', {95 data: [TODO_3]96 })97 )98 expect(state).toMatchSnapshot()99 })100 it('should not update a query not concerned even with a selector', () => {101 const query = new Q({102 doctype: 'io.cozy.todos'103 })104 applyAction(initQuery('b', query.where({ done: false })))105 applyAction(106 receiveQueryResult('a', {107 data: [TODO_3]108 })109 )110 expect(state).toMatchSnapshot()111 })112 it('should not crash if data is null', () => {113 const query = new Q({114 doctype: 'io.cozy.todos',115 id: 'not-existing-doc'116 })117 applyAction(initQuery('b', query))118 applyAction(119 receiveQueryResult('b', {120 data: null121 })122 )123 expect(state).toMatchSnapshot()124 })125 it('should only update queries with the right id selector', () => {126 const query = new Q({127 doctype: 'io.cozy.todos',128 id: TODO_3._id129 })130 applyAction(initQuery('b', query))131 applyAction(132 receiveQueryResult('a', {133 data: [TODO_2]134 })135 )136 expect(state.b.lastUpdate).toBe(null)137 applyAction(138 receiveQueryResult('a', {139 data: [TODO_3]140 })141 )142 expect(state.b.lastUpdate).not.toBe(null)143 })144 })145})146describe('selectors', () => {147 it('should convert $gt selectors when their value is null', () => {148 const selector = {149 somefield: 'somevalue',150 convertMe: {151 $gt: null...

Full Screen

Full Screen

HumanAgent.js

Source:HumanAgent.js Github

copy

Full Screen

...35 /*36 if (shoot) {37 if (up) {38 if (left) {39 this.player.applyAction(Action.upleftshoot);40 } else if (right) {41 this.player.applyAction(Action.uprightshoot);42 } else {43 this.player.applyAction(Action.upshoot);44 }45 } else if (down) {46 if (left) {47 this.player.applyAction(Action.downleftshoot);48 } else if (right) {49 this.player.applyAction(Action.downrightshoot);50 } else {51 this.player.applyAction(Action.downshoot);52 }53 } else {54 if (left) {55 this.player.applyAction(Action.leftshoot);56 } else if (right) {57 this.player.applyAction(Action.rightshoot);58 } else {59 this.player.applyAction(Action.nomoveshoot);60 }61 }62 } else {63 if (up) {64 if (left) {65 this.player.applyAction(Action.upleft);66 } else if (right) {67 this.player.applyAction(Action.upright);68 } else {69 this.player.applyAction(Action.up);70 }71 } else if (down) {72 if (left) {73 this.player.applyAction(Action.downleft);74 } else if (right) {75 this.player.applyAction(Action.downright);76 } else {77 this.player.applyAction(Action.down);78 }79 } else {80 if (left) {81 this.player.applyAction(Action.left);82 } else if (right) {83 this.player.applyAction(Action.right);84 } else {85 this.player.applyAction(Action.nomove);86 }87 }88 }89*/90 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.runTest(options, function(err, data) {5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log('Test ID: ' + data.data.testId);9 console.log('Owner Key: ' + data.data.ownerKey);10 console.log('Json Url: ' + data.data.jsonUrl);11 console.log('User Url: ' + data.data.userUrl);12 console.log('Summary CSV: ' + data.data.summaryCSV);13 console.log('Detail CSV: ' + data.data.detailCSV);14 }15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var options = {3};4wpt.applyAction('test', options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11- `runs` - The number of test runs to perform (default 1)12- `fvonly` - First View only testing (default 0)13- `location` - The location to test from (default 'Dulles:Chrome')14- `connectivity` - The connectivity profile to test with (default 'Cable')15- `video` - Capture a video of the test (default 1)16- `timeline` - Capture a timeline of the test (default 0)17- `sensitive` - Include header data in the test result (default 0)18- `block` - Block a URL from being loaded (default '')19- `label` - A label to be assigned to the test (default '')20- `aftRenderingTime` - Number of milliseconds to wait for AFT (default 3000)21- `web10` - Enable Web10 (default 0)22- `web10ID` - The ID of the Web10 test to use (default 0)23- `mobile` - Simulate a mobile device (default 0)24- `mobileDevice` - The device to emulate (default 'Motorola Droid 3')25- `mobileCarrier` - The carrier to emulate (default 'Verizon')26- `mobileConnection` - The connection type to emulate (default '3G')27- `mobileLocation` - The location to use for the test (default 'Dulles_MotoDroid3')28- `script` - The script to execute (default '')29- `scriptname` - The name of the script (default '')30- `scriptblock` - Block a URL from being loaded in the script (default '')31- `scriptlabel` - A label to be assigned to the script (default '')32- `scriptWait` - Wait for an event to occur before continuing (default 0)33- `scriptClick` - Click on an element before continuing (default 0)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('wptool');2var wp = new wptool();3if(error) {4console.log(error);5} else {6console.log(body);7}8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('./wpt');2wpt.applyAction('start');3wpt.applyAction('stop');4### `wpt.on('action', action => {})`5const wpt = require('./wpt');6wpt.on('action', action => {7 console.log(`The WPT changed state to ${action}.`);8});9wpt.on('time', time => {10 console.log(`The WPT changed time to ${time}.`);11});12### `wpt.reset()`13const wpt = require('./wpt');14wpt.applyAction('start');15wpt.reset();16### `wpt.start()`17const wpt = require('./wpt');18wpt.applyAction('stop');19wpt.start();20### `wpt.stop()`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var currentState = {3 {4 },5 {6 }7};8var actionToApply = "start";9wpt.applyAction(currentState, actionToApply, function(newState, nextActions) {10 console.log("new state:");11 console.log(newState);12 console.log("next actions:");13 console.log(nextActions);14});

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