Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

fix: modal using animation frame and tests #228

Closed
wants to merge 1 commit into from
Closed

Conversation

suwarnoong
Copy link
Contributor

Tests for Modal #201

@suwarnoong suwarnoong requested a review from a team March 6, 2019 06:41
it("closed correctly", async () => {
const button = wrapper.find(".fd-modal__close");
button.trigger("click");
wrapper.setProps({ active: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to set this prop to false, will it set to false after clicking the button

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, that is because the click event only emit "close" and "update:active" and it does not set the active to false.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we should add "this.isActive = false" in the private close()

Copy link
Contributor

@ChristianKienle ChristianKienle Mar 7, 2019

Choose a reason for hiding this comment

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

I think adding this.isActive = false will fix the issues @suwarnoong has down below (the sync-issue).

If your test looks exactly like the example then the sync issues will vanish.

This is because the example is going though the vue template compiler which is causing to catch the update:active-event and updates the state.

Our modal breaks down once the consumer is doing this:

<FdModal :active="false"></FdModal>

and not

<FdModal :active.sync="active"></FdModal>

Meaning: Our modal relies upon the fact that the consuming app is either using .sync or listening for the update-event accordingly + is binding the active-prop.

For this PR I suggest to do what @xujing-shen suggests but make a mental note (=> or an issue) to have a closer look at the modal component again. I think FdModal should me more resilient and support different modes of operation...

Copy link
Contributor

Choose a reason for hiding this comment

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

Note to myself: This is maybe a great question for our Q/A with Chris.

Copy link
Contributor Author

@suwarnoong suwarnoong Mar 8, 2019

Choose a reason for hiding this comment

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

Adding this.isActive = false in the close() will only close the FdModal for the very first time. But isActive value (in Modal.vue) is not propagated to parent (Example.vue). Meaning, the parent variable will still be true. Subsequent, the showModal will not trigger the watch for the active.

image

If the consumer doesn't use .sync, alternatively, they could listen on @close event and set the parent variable to false.

But, in my personal opinion, perhaps, we should only let parent to hide/show through hide() show() methods instead of just a variable. But this implementation will be different with fundamental-react. Are we allow to have different implementation?

<Modal onClose={this.showHideModal} show={this.state.bShowInfoModal}>
  ...
</Modal>

// show / hide information modal
showHideModal = () => {
  this.setState(prevState => ({
    bShowInfoModal: !prevState.bShowInfoModal
  }));
};

Copy link
Contributor

Choose a reason for hiding this comment

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

You are correct. If the consume is not using :visible.sync then it won't work. This is what I meant by saying:

Meaning: Our modal relies upon the fact that the consuming app is either using .sync or listening for the update-event accordingly + is binding the active-prop.

In the end, :active.sync="active" is syntactic sugar for:

<FdModal @update:active="active = $event" :active="active"  >

I think, when I wrote the code for FdModel I was heavily influenced by: https://element.eleme.io/#/en-US/component/dialog.

We are allowed to have different implementations. After all: We are all using different frameworks which have different features and philosophies. :)

With regards to your "methods-idea": Personally I think calling a method is less convenient than to have a sync-prop. It is also not less prone to errors. But: I think there is no right and wrong and there is no best way to do things. Every solution has pro and cons. I also think that bootstrap-vue has a different but very well designed solution:

https://bootstrap-vue.js.org/docs/components/modal#toggle-modal-visibility

Their solution is more or less what I had in mind for FdPopper. :D The world is so small.

If you want to add an open(…) method: Why not? :)

@ChristianKienle
Copy link
Contributor

I just tested our modal component and it does not seem to work. I mean the default example in our docs... Does it work for you? :D

@suwarnoong
Copy link
Contributor Author

suwarnoong commented Mar 6, 2019

Oops. doesn't seems to work too. The culprit is the .sync after :active. Once I remove that, it is fine.

But the X button on modal header isn't closing. If we add this.isActive = false in the close() as suggested by xujing, we also need to add ignoreElements on the ClickAwayContainer.

@ChristianKienle
Copy link
Contributor

Oops. doesn't seems to work too. The culprit is the .sync after :active. Once I remove that, it is fine.

But the X button on modal header isn't closing. If we add this.isActive = false in the close() as suggested by xujing, we also need to add ignoreElements on the ClickAwayContainer.

#230 should solve this for you. You could just merge this PR into your branch...

However, I am wondering how and why this worked in the past - also without the fix.

@suwarnoong
Copy link
Contributor Author

The modal works now in docs.
But the test-utils doesn't seems working prop.sync, even after I set the sync: true during mounting. In this case, I am still updating the active prop manually.

@ChristianKienle Should this PR be kept as multiple commits since there is a merge from other branch? Or perhaps combine as single commit.

const wrapper = mount(Modal, {
// does not work. infact it is default value
// https://github.com/vuejs/vue-test-utils/pull/1062
sync: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should work for prop.sync (vuejs/vue-test-utils#1062) but no luck

Copy link
Contributor

Choose a reason for hiding this comment

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

The modal works now in docs.
But the test-utils doesn't seems working prop.sync, even after I set the sync: true during mounting. In this case, I am still updating the active prop manually.

@ChristianKienle Should this PR be kept as multiple commits since there is a merge from other branch? Or perhaps combine as single commit.

I think you can squash the commits and turn multiple commits into a single one. You have the option to select that option by clicking on the arrow of the merge button.

// Temporary manually modify the active prop
// Tried with $nextTick but no luck
// expect(wrapper.props('active')).toBe(false);
wrapper.setProps({ active: false });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the update:active is not updating active to false. Hence, perform manual update for this test.

@suwarnoong suwarnoong changed the title test: add tests for Modal component fix: modal using animation frame and tests Mar 8, 2019
@suwarnoong
Copy link
Contributor Author

Seems like this PR is no longer relevant. Closed for now

@suwarnoong suwarnoong closed this Mar 22, 2019
@suwarnoong suwarnoong deleted the test/modal branch March 22, 2019 01:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants