Skip to content

Commit

Permalink
acceptance test for harvesting fields
Browse files Browse the repository at this point in the history
  • Loading branch information
customcommander committed Oct 5, 2024
1 parent 3545bb3 commit bb33b0c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ const machine = src.createMachine({
},
"feed": {
"after": {
"200": "breed"
"50": "breed"
}
},
"breed": {
"after": {
"200": "done"
"50": "done"
}
},
"done": {
Expand Down
2 changes: 1 addition & 1 deletion src/task-104.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {base} from './task-lib.js';

function plow({params}, game_context) {
const {space_id} = params;
const {space_id} = params; // throw if undefined?
game_context.farmyard[space_id] = {type: 'field'};
return game_context;
}
Expand Down
9 changes: 1 addition & 8 deletions src/task-113.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ const machine = base.createMachine({
'task.selected': [
{
target: 'select-space',
guard: and(['has-empty-fields?', or(['has-grain?', 'has-vegetable?'])]),
actions: {
type: 'display-selection',
params: {
task_id: 113,
opts: ['select.sow']
}
}
guard: and(['has-empty-fields?', or(['has-grain?', 'has-vegetable?'])])
},
{
actions: {
Expand Down
51 changes: 45 additions & 6 deletions test/acceptance/001.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
Feature:
Feature: Harvest - Field Phase

Scenario: Turns
Scenario: Fields are automatically harvested
Given I start playing
Then the current turn is 1
When I select "Take 1 Grain"
And I select "Take x Wood"
Then the current turn is 2

# Turn 1
* I select "Take 1 Grain"
* I select "Plow 1 Field"
* I plow A1

# Turn 2
* I select "Take 1 Grain"
* I select "Plow 1 Field"
* I plow A2

# Turn 3
* I select "Sow and/or Bake bread"
* I sow grain on A1
* I sow grain on A2
* I select "Take x Wood"

# Turn 4
* I select "Take x Clay"
* I select "Take x Reed"

# Harvest
Then I have 2 grain in my supply
And I have 2 grain on A1
And I have 2 grain on A2

# Turn 5
* I select "Take x Clay"
* I select "Take x Reed"

# Turn 6
* I select "Take x Clay"
* I select "Take x Reed"

# Turn 7
* I select "Take x Clay"
* I select "Take x Reed"

# Harvest
Then I have 4 grain in my supply
And I have 1 grain on A1
And I have 1 grain on A2

29 changes: 25 additions & 4 deletions test/acceptance/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,36 @@ Given('I start playing', async function () {

When('I select {string}', async function (selection) {
const task_map = {
'Take 1 Grain': 103,
'Take x Wood': 107,
'Take x Clay': 108,
'Take x Reed': 109
'Take 1 Grain' : 103,
'Plow 1 Field' : 104,
'Take x Wood' : 107,
'Take x Clay' : 108,
'Take x Reed' : 109,
'Sow and/or Bake bread': 113
};

await this.send({type: 'task.selected', task_id: task_map[selection]});
});

Then('I plow {word}', async function (space_id) {
await this.send({type: 'select.plow', task_id: '104', space_id});
});

Then('I sow grain on {word}', async function (space_id) {
await this.send({type: 'select.sow-grain', task_id: '113', space_id});
});

Then('I have {int} {word} in my supply', async function (quantity, type) {
await this.assert(({supply}) => supply[type] === quantity);
});

Then('I have {int} {word} on {word}', async function (quantity, type, space_id) {
await this.assert(({farmyard}) => {
const space = farmyard[space_id];
return space[type] === quantity;
});
});

Then('the current turn is {int}', async function (expected_turn) {
await this.assert(({turn}) => turn === expected_turn);
});
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ setWorldConstructor(class extends World {
async start() {
this.game = game();
this.game.start();
await this.wait(200);
await this.wait(250);
}

async send(ev) {
await this.wait(250);
this.game.send(ev);
await this.wait(200);
}

async wait(ms) {
Expand Down

0 comments on commit bb33b0c

Please sign in to comment.