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

[Slide] Add test coverage for componentDidMount() #6679

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/transitions/Slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ function getTranslateValue(props, element) {
return `translate3d(${0 - (rect.left + rect.width)}px, 0, 0)`;
} else if (direction === 'up') {
return `translate3d(0, calc(100vh - ${rect.top}px), 0)`;
} else if (direction === 'down') {
return `translate3d(0, ${0 - (rect.top + rect.height)}px, 0)`;
}

return 'translate3d(0, 0, 0)';
// direction === 'down'
Copy link
Member

@oliviertassinari oliviertassinari May 21, 2017

Choose a reason for hiding this comment

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

I have cherry-picked that changed into #6911, good catch 👍 !
But I'm closing this PR as has been inactive for quite some time. The test is inconsistent across the different browser. I'm not sure what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! I actually knew I needed to deal with it and didn't get around. Thanks!

return `translate3d(0, ${0 - (rect.top + rect.height)}px, 0)`;
}

export default class Slide extends Component {
Expand Down
42 changes: 41 additions & 1 deletion src/transitions/Slide.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import React from 'react';
import { assert } from 'chai';
import { spy } from 'sinon';
import { createShallow } from 'src/test-utils';
import ReactDOM from 'react-dom';
import { createShallow, createMount } from 'src/test-utils';
import Slide from './Slide';
import transitions, { easing, duration } from '../styles/transitions';

Expand Down Expand Up @@ -181,4 +182,43 @@ describe('<Slide />', () => {
});
});
});

describe('slidemount', () => {
let mount;
let mountWrapper;
let instance;

before(() => {
mount = createMount();
mountWrapper = mount(<Slide><div /></Slide>);
});

after(() => {
mount.cleanUp();
});

it('default value', () => {
mountWrapper.setProps({ in: false });
instance = mountWrapper.instance();
instance.componentDidMount();
const transitionElement = ReactDOM.findDOMNode(mountWrapper.instance().transition);
if (transitionElement instanceof window.HTMLElement) {
assert.strictEqual(transitionElement.style.transform, 'translate3d(0, 0px, 0)');
} else {
assert.fail('transition property of instance should be an HTMLElement');
}
});

it('non-default value', () => {
mountWrapper.setProps({ in: false, direction: 'right' });
instance = mountWrapper.instance();
instance.componentDidMount();
const transitionElement = ReactDOM.findDOMNode(mountWrapper.instance().transition);
if (transitionElement instanceof window.HTMLElement) {
assert.strictEqual(transitionElement.style.transform, 'translate3d(0px, 0, 0)');
} else {
assert.fail('transition property of instance should be an HTMLElement');
}
});
});
});