Repository: 4ian/GDevelop
File: Extensions/PlatformBehavior/tests/JumpAndFallingPlatformer.spec.js (JavaScript)

Code before:
      runtimeScene.renderAndStep(1000 / 60);
      expect(object.getY()).to.be.within(
        -229.5833333333333 - epsilon,
        -229.5833333333333 + epsilon
      );
      for (let i = 0; i < 4; ++i) {
        // Verify that pressing the jump key does not change anything
        object.getBehavior('auto1').simulateJumpKey();
        runtimeScene.renderAndStep(1000 / 60);
      }

      // Check that we reached the maximum height
      expect(object.getY()).to.be.above(-240);
      runtimeScene.renderAndStep(1000 / 60);
      expect(object.getY()).to.be.within(-240 - epsilon, -240 + epsilon);
      runtimeScene.renderAndStep(1000 / 60);
      expect(object.getY()).to.be.above(-240);

      // Then let the object fall
      for (let i = 0; i < 60; ++i) {
        runtimeScene.renderAndStep(1000 / 60);
      }
      expect(object.getY()).to.be(-30);
    });

    it('can jump only jump once while the jump key is held', function () {
      // Ensure the object falls on the platform
      for (let i = 0; i < 10; ++i) {
        runtimeScene.renderAndStep(1000 / 60);
      }

      //Check the object is on the platform
      expect(object.getY()).to.be(-30); // -30 = -10 (platform y) + -20 (object height)
      expect(characterBehavior.isFalling()).to.be(false);
      expect(characterBehavior.isFallingWithoutJumping()).to.be(false);
      expect(characterBehavior.isMoving()).to.be(false);

      // The character jumps a first time.
      for (let i = 0; i < 80; ++i) {
        characterBehavior.simulateJumpKey();
        runtimeScene.renderAndStep(1000 / 60);
        characterBehavior.isJumping(true);
      }
      // The character lands back on the floor
      // while the player holds the jump key.
      for (let i = 0; i < 4; ++i) {
        characterBehavior.simulateJumpKey();
        runtimeScene.renderAndStep(1000 / 60);
      }
      characterBehavior.isOnFloor(true);
      expect(object.getY()).to.be(-30);

Review comment (suggestion):
```suggestion
    it('can only jump once while the jump key is held', function () {
```

Code after:
      runtimeScene.renderAndStep(1000 / 60);
      expect(object.getY()).to.be.within(
        -229.5833333333333 - epsilon,
        -229.5833333333333 + epsilon
      );
      for (let i = 0; i < 4; ++i) {
        // Verify that pressing the jump key does not change anything
        object.getBehavior('auto1').simulateJumpKey();
        runtimeScene.renderAndStep(1000 / 60);
      }

      // Check that we reached the maximum height
      expect(object.getY()).to.be.above(-240);
      runtimeScene.renderAndStep(1000 / 60);
      expect(object.getY()).to.be.within(-240 - epsilon, -240 + epsilon);
      runtimeScene.renderAndStep(1000 / 60);
      expect(object.getY()).to.be.above(-240);

      // Then let the object fall
      for (let i = 0; i < 60; ++i) {
        runtimeScene.renderAndStep(1000 / 60);
      }
      expect(object.getY()).to.be(-30);
    });

    it('can only jump once while the jump key is held', function () {
      // Ensure the object falls on the platform
      for (let i = 0; i < 10; ++i) {
        runtimeScene.renderAndStep(1000 / 60);
      }

      //Check the object is on the platform
      expect(object.getY()).to.be(-30); // -30 = -10 (platform y) + -20 (object height)
      expect(characterBehavior.isFalling()).to.be(false);
      expect(characterBehavior.isFallingWithoutJumping()).to.be(false);
      expect(characterBehavior.isMoving()).to.be(false);

      // The character jumps a first time.
      for (let i = 0; i < 80; ++i) {
        characterBehavior.simulateJumpKey();
        runtimeScene.renderAndStep(1000 / 60);
        characterBehavior.isJumping(true);
      }
      // The character lands back on the floor
      // while the player holds the jump key.
      for (let i = 0; i < 4; ++i) {
        characterBehavior.simulateJumpKey();
        runtimeScene.renderAndStep(1000 / 60);
      }
      characterBehavior.isOnFloor(true);
      expect(object.getY()).to.be(-30);