Skip to content

Commit

Permalink
Test disabled option links with target don't navigate current window
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Stahl committed Aug 24, 2015
1 parent 7359fdf commit 95cbf36
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2472,13 +2472,18 @@ describe('Select', function() {
describe('optionRendererDisabled', function () {

var optionRenderer;
var link_url = '/link';
var renderLink = function() {
return <a style={{ marginLeft: 5 }} href={ link_url }>Upgrade here!</a>;
var renderLink = function(props) {
return <a {...props} >Upgrade here!</a>;
};

var links = [
{ href: '/link' },
{ href: '/link2', target: '_blank' }
];

var ops = [
{ label: 'Disabled', value: 'disabled', disabled: true, link: renderLink() },
{ label: 'Disabled', value: 'disabled', disabled: true, link: renderLink(links[0]) },
{ label: 'Disabled 2', value: 'disabled_2', disabled: true, link: renderLink(links[1]) },
{ label: 'Enabled', value: 'enabled' },
];

Expand All @@ -2491,7 +2496,7 @@ describe('Select', function() {
var isNavigated = function(path) {
var window_location = global.window.location.href;
return window_location.indexOf(path, window_location.length - path.length) !== -1;
}
};

beforeEach(function () {

Expand All @@ -2509,19 +2514,33 @@ describe('Select', function() {
});
});

it('disabled link is still clickable', function () {
it('disabled option link is still clickable', function () {
var selectArrow = React.findDOMNode(instance).querySelector('.Select-arrow');
TestUtils.Simulate.mouseDown(selectArrow);
var options = React.findDOMNode(instance).querySelectorAll('.Select-option');
var link = options[0].querySelector('a');
var window_location = global.window.location.href;
expect(link, 'to have attributes', {
href: link_url
href: links[0].href
});

expect(isNavigated(links[0].href), 'to be false');
TestUtils.Simulate.click(link);
expect(isNavigated(links[0].href), 'to be true');
});

it('disabled option link with target doesn\'t navigate the current window', function () {
var selectArrow = React.findDOMNode(instance).querySelector('.Select-arrow');
TestUtils.Simulate.mouseDown(selectArrow);
var options = React.findDOMNode(instance).querySelectorAll('.Select-option');
var link = options[1].querySelector('a');
expect(link, 'to have attributes', {
href: links[1].href,
target: '_blank'
});

expect(isNavigated(link_url), 'to be false');
expect(isNavigated(links[0].href), 'to be true');
TestUtils.Simulate.click(link);
expect(isNavigated(link_url), 'to be true');
expect(isNavigated(links[1].href), 'to be false');
});

});
Expand Down

0 comments on commit 95cbf36

Please sign in to comment.