Skip to content

Commit

Permalink
Added fixes for FoundryVTT 9 and cleaned up testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lupestro committed Oct 31, 2021
1 parent 4ece988 commit edf35ab
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 101 deletions.
11 changes: 4 additions & 7 deletions test/TESTCASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,20 @@

### Token with No Torches, No Cantrips

* Player aattempts to activate torch on Token
* Player attempts to activate torch on Token
* When:
- [ ] Light Radius settings are default (20 units/ 40 units, 0 units/0 units)
- [ ] Player Torches setting are checked
- [ ] Joined as Player
- [ ] Token HUD is open in scene
- [ ] Torch button is not activated
* Expect:
- [ ] Torch button icon shows disabled status - orange slash through it
* Do: Player clicks torch button on token HUD
* Expect:
- [ ] Nothing happens
- [ ] Torch button does not appear

* GM aattempts to activate torch on Token
* GM attempts to activate torch on Token
* When:
- [ ] Light Radius settings are default (20 units/ 40 units, 0 units/0 units)
- [ ] Player Torches setting are checked
- [ ] Player Torches setting is checked
- [ ] GM Uses Inventory is checked
- [ ] Joined as GM
- [ ] Token HUD is open in scene
Expand Down
2 changes: 1 addition & 1 deletion test/env/TESTENV.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ For each version of Foundry you'll be testing with, set it up for testing:
3. Install the systems, then the modules, and then the test worlds.
* For Torch:
* Systems: `DnD5e` and `Simple Worldbuilding System`
* Modules: `Translation: Spanish \[Core]` and the module under test
* Modules: `Translation: Spanish \[Core]`, `Quench`, and the module under test
* Worlds: `torch-test-simple` and `torch-test-dnd5e`:
* https://raw.githubusercontent.com/League-of-Foundry-Developers/torch/master/test/torch-test-simple/world.json
* https://raw.githubusercontent.com/League-of-Foundry-Developers/torch/master/test/torch-test-5e/world.json
Expand Down
1 change: 1 addition & 0 deletions test/env/vttstart.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rem Set up structure for keeping data paths
if not exist %~dp0Data mkdir %~dp0Data
rem Determine Foundry subtree to use for this major version
IF "%1"=="" ( SET "VTTNUM=8" ) ELSE ( SET "VTTNUM=%1" )
if "%VTTNUM%"=="9" SET VTTVER=foundryvtt-0.9.226
if "%VTTNUM%"=="8" SET VTTVER=foundryvtt-0.8.8
if "%VTTNUM%"=="7" SET VTTVER=foundryvtt-0.7.10
if "%VTTVER%"=="" ECHO "Invalid Foundry major version specified" && EXIT /B -1
Expand Down
1 change: 1 addition & 0 deletions test/env/vttstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fi
case ${1:-8} in
7) vttver="foundryvtt-0.7.10";;
8) vttver="foundryvtt-0.8.8";;
9) vttver="foundryvtt-0.9.226";;
esac
if [ -z ${vttver} ]; then
echo "Invalid Foundry major version specified"
Expand Down
4 changes: 2 additions & 2 deletions test/generic-basic-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export let torchGenericBasicTests = (context) => {
describe('Tests Run As Gamemaster', () => {
it('gamemaster controls the token light levels when playerTorches is false',
async () => {
await game.settings.set('torch','playerTorches', true);
await game.settings.set('torch', 'playerTorches', false);
await torchButtonToggles(assert, game, ACTOR, 20, 40);
});
it('gamemaster controls the token light levels when playerTorches is true',
async () => {
await game.settings.set('torch','playerTorches', true);
await game.settings.set('torch', 'playerTorches', true);
await torchButtonToggles(assert, game, ACTOR, 20, 40);
});
});
Expand Down
115 changes: 89 additions & 26 deletions test/test-cases.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,122 @@

import { waitUntil } from './test-utils.js';

let getLightRadii = (data) => {
return data.light
? { bright: data.light.bright, dim: data.light.dim }
: { bright: data.brightLight, dim: data.dimLight };
}
let lightRadiiForUpdate = async (data, bright, dim) => {
return data.light
? { "light.bright": bright, "ight.dim": dim }
: { "brightLight": bright,"dimLight": dim };
}

export let torchButtonToggles = async (
assert, game, actor, brightOnRadius, dimOnRadius, brightOffRadius = 0, dimOffRadius = 0
assert, game, actor, brightOnRadius, dimOnRadius,
brightOffRadius = 0, dimOffRadius = 0
) => {
let token = game.scenes.current.tokens.find(token => token.name === actor);
game.canvas.hud.token.bind(token.object);
let token = game.scenes.current.tokens.find(
token => token.name === actor);

// Open the token HUD for the targeted token
let tokenHUD = game.canvas.hud.token;
tokenHUD.bind(token.object);
await waitUntil(() => {
return game.canvas.hud.token.element.find(`.col.left div`).length > 0;
return tokenHUD.element.find(`.col.left div`).length > 0;
}, "HUD is up");
let hudButtons = game.canvas.hud.token.element.find(`.col.left div`);
assert.isTrue(hudButtons.first().hasClass('torch'), 'First button is the Torch button');

// Examine the initial condition of the HUD
let hudButtons = tokenHUD.element.find(`.col.left div`);
assert.isTrue(
hudButtons.first().hasClass('torch'),
'First button is the Torch button');
console.log("OldValue upon entry:", token.data.flags.torch?.oldValue);
hudButtons = game.canvas.hud.token.element.find(`.col.left div`);
hudButtons = tokenHUD.element.find(`.col.left div`);
assert.isFalse(
hudButtons.first().hasClass('active'),
"Torch isn't active before click");

// Click to turn on light
hudButtons.first().find('i').click();
let expectedFlag = `${brightOffRadius}/${dimOffRadius}`;
await waitUntil(() => {
return token.data.brightLight > brightOffRadius;
return getLightRadii(token.data).bright > brightOffRadius;
},"Torch is lit");
assert.equal(token.data.brightLight, brightOnRadius, 'Bright light is the configured value for ON');
assert.equal(token.data.dimLight, dimOnRadius, 'Dim light is the configured value for ON');
hudButtons = game.canvas.hud.token.element.find(`.col.left div`);
await waitUntil(() => {
return token.data.flags.torch?.oldValue === expectedFlag;
}, "Torch flag is set");

// Check conditions after turning on light
assert.equal(
getLightRadii(token.data).bright, brightOnRadius,
'Bright light is the configured value for ON');
assert.equal(
getLightRadii(token.data).dim, dimOnRadius,
'Dim light is the configured value for ON');
hudButtons = tokenHUD.element.find(`.col.left div`);
await waitUntil(() => {
return hudButtons.first().hasClass('active');
}, "Torch button active after first click");

// Click to turn off light
hudButtons.first().find('i').click();
await waitUntil(() => {
return token.data.brightLight < brightOnRadius;
return getLightRadii(token.data).bright < brightOnRadius;
}, "Torch is unlit");
assert.equal(token.data.brightLight, brightOffRadius, 'Bright light is the configured value for OFF');
assert.equal(token.data.dimLight, dimOffRadius, 'Dim light is the configured value for OFF');
await waitUntil(() => {
return token.data.flags.torch?.oldValue === null;
}, "Torch flag is cleared");

// Check conditions after turning off light
assert.equal(
getLightRadii(token.data).bright, brightOffRadius,
'Bright light is the configured value for OFF');
assert.equal(
getLightRadii(token.data).dim, dimOffRadius,
'Dim light is the configured value for OFF');
assert.isFalse(
hudButtons.first().hasClass('active'),
"Torch button inactive after second click");
}

export let torchButtonAbsent = async (
assert, game, actor, brightOffRadius = 0, dimOffRadius = 0
) => {
let token = game.scenes.current.tokens.find(token => token.name === actor);
game.canvas.hud.token.bind(token.object);
let token = game.scenes.current.tokens.find(
token => token.name === actor);
let tokenHUD = game.canvas.hud.token;

// Open the token HUD for the targeted token
tokenHUD.bind(token.object);
await waitUntil(() => {
return game.canvas.hud.token.element.find(`.col.left div`).length > 0;
return tokenHUD.element.find(`.col.left div`).length > 0;
}, "HUD is up");
let hudButtons = game.canvas.hud.token.element.find(`.col.left div`);
assert.isFalse(hudButtons.first().hasClass('torch'), 'First button is the Torch button');
assert.equal(token.data.brightLight, brightOffRadius);
assert.equal(token.data.dimLight, dimOffRadius);

// Verify that light button isn't on HUD
let hudButtons = tokenHUD.element.find(`.col.left div`);
assert.isFalse(
hudButtons.first().hasClass('torch'),
'First button is the Torch button');

// Verify that the lights are off
assert.equal(getLightRadii(token.data).bright, brightOffRadius);
assert.equal(getLightRadii(token.data).dim, dimOffRadius);
}

export let cleanup = async (
assert, game, actor, brightOffRadius = 0, dimOffRadius = 0
) => {
// Make sure playerTorches is off
if (game.users.current.name === 'Gamemaster') {
await game.settings.set('torch','playerTorches', true);
}
let token = game.scenes.current.tokens.find(token => token.name === actor);
await token.update({
"data.brightLight": brightOffRadius,
"data.dimLight": dimOffRadius
});
// Make sure lights are off
let token = game.scenes.current.tokens.find(
token => token.name === actor);
await token.update(
lightRadiiForUpdate(token.data, brightOffRadius, dimOffRadius));

// Make sure token HUD is closed
await game.canvas.hud.token.clear();
}
7 changes: 6 additions & 1 deletion test/vttlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ do
rm $targetdir/$(basename $file)
ln -s $file $targetdir/$(basename $file)
done
if [ ! -d $targetdir/test ]; then
mkdir $targetdir/test
fi
# Replace javascript in test directory with link
for file in $clonedir/test/*.js
do
echo test/$(basename $file)
rm $targetdir/test/$(basename $file)
if [ -f "$targetdir/test/$(basename $file)" ]; then
rm $targetdir/test/$(basename $file)
fi
ln -s $file $targetdir/test/$(basename $file)
done
Loading

0 comments on commit edf35ab

Please sign in to comment.