Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(YawPitchControl): add unit test and refactor src #42

Merged
merged 3 commits into from
Nov 1, 2017

Conversation

happyhj
Copy link
Contributor

@happyhj happyhj commented Oct 30, 2017

Issue

#35

Details

add unit test and refactor YawPitchControl.js for better testability.
also, fixed typo at MoveKeyInput.spec.js

also, fixed typo at MoveKeyInput.spec.js

ref #35
@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 37.278% when pulling d93989b on YawPitchControl#35 into a396865 on master.

@jongmoon jongmoon self-requested a review October 31, 2017 01:31
if (evt.delta.fov !== 0) {
this._setPanScale(evt.pos.fov);
this._updateControlScale();
}
this._triggerChange();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree removing code because it is process by change event. but how about change event name? current is "change" but... I think it would be better to notice it's release event.

Copy link
Contributor Author

@happyhj happyhj Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not to provide a release event will be discussed in a separate issue.

Issue opened
#43

this._applyOptions(changedKeyList, beforeOptions);
return this;
}

_option(key, value) {
if (arguments.length >= 2) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you know it makes available following.

this.option("key", "value")

And I think it is general pattern (interface) for setting value. If it is not unreachable it would be better to add some test case.

Copy link
Contributor Author

@happyhj happyhj Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, in '_option' method, it's not using key, value parameter anymore.
It supports three API patterns below.

this._option("key"); // Getter
this._option(); // Global Getter
this._option({ 
    "key": value
}); // Setter

The value portion of the argument is expected to be deleted.

}

_applyOptions(keys, prevOptions) {
// If one of below is changed, call updateControlScale()
if (keys.some(key =>
key === "showPole" || key === "fov" || key === "aspectRatio")) {
this._setYawPitchRange(prevOptions);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to change code to exit recursive. but It is missing to change yaw/pitch range if fov or aspect ratio is changed.

Copy link
Contributor Author

@happyhj happyhj Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean. I will fix that.

I changed _getValidYawRange, _getValidPitchRange methods to use new fov and aspectRatio parameter.

const horizontalFov = fov * ratio;
const isValid = !(newYawRange[1] - newYawRange[0] < horizontalFov);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right? Isn't your intend following?

// ! is removed
const isValid = (newYawRange[1] - newYawRange[0] < horizontalFov);

Although it's your intend I think It would be better to not put ! like below

const isValid = (newYawRange[1] - newYawRange[0] >= horizontalFov);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will fix that.

this.option("pitchRange", prevPitchRange);
_getValidPitchRange(newPitchRange) {
const fov = this.axes.get().fov;
const isValid = !(newPitchRange[1] - newPitchRange[0] < fov);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will fix that, too

if (isValid) {
return newPitchRange;
} else {
return this.options.pitchRange || [-PITCH_RANGE_HALF, PITCH_RANGE_HALF];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about default range as fov ranges instead of DEFAULT?

// Then
const appliedOption = this.inst.option();
expect(appliedOption.yawRange).to.deep.equal([-180, 180]);
expect(appliedOption.pitchRange).to.deep.equal([-90, 90]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related with code that I commented above.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ignore this comment.

@@ -203,6 +221,23 @@ describe("YawPitchControl", function() {
done();
}
});

it("should lookAt trigger change event once when enable called multiple times.", () => {
// Given

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case for checking axes not connected PanInput multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Exactly.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK Thank you!

inst.option("yawRange", [-1, 1]);

// Then
console.log(inst.option("yawRange"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No expect code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add assertion.

inst.option("pitchRange", [-1, 1]);

// Then
console.log(inst.option("pitchRange"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No expect code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add assertion.

@happyhj happyhj mentioned this pull request Oct 31, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 37.456% when pulling 21fbe0f on YawPitchControl#35 into a396865 on master.

@@ -168,25 +170,28 @@ const YawPitchControl = class YawPitchControl extends Component {

// adjustOption
if (changedKeyList.some(key => key === "yawRange")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@happyhj how about moving this call to _applyOption. and I have other things to talk . let's take meeting.

Copy link

@jongmoon jongmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 37.439% when pulling cb08f66 on YawPitchControl#35 into a396865 on master.

@happyhj happyhj merged commit 98f6af5 into master Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants