Skip to content

Instantly share code, notes, and snippets.

@JunichiIto

JunichiIto/jstree_test.rb

Last active Jul 30, 2019
Embed
What would you like to do?
Drag and drop demo with capybara + jstree
# Modified from https://gist.github.com/trcarden/380d3d2e345a7536e8ae8c2a0a2c13a0
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'selenium-webdriver'
gem 'webdrivers'
gem 'capybara', '3.5.1' # Work
# gem 'capybara', '3.6.0' # Not work
# gem 'capybara' # Not work
gem 'byebug'
gem 'puma'
end
require 'webdrivers'
require "capybara/dsl"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
Capybara.register_driver :w3c do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
# Capybara.register_driver :no_w3c do |app|
# options = Selenium::WebDriver::Chrome::Options.new
# options.add_option('w3c', false)
# Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
# end
sess = Capybara::Session.new(:w3c, app)
sess.visit('/')
sess.assert_text /A.*B.*C/m
occasion_li_1 = sess.find('#j1_1_anchor')
occasion_li_2 = sess.find('#j1_2_anchor')
occasion_li_1.drag_to(occasion_li_2)
sleep 5
sess.assert_no_text /A.*B.*C/m
sess.assert_text /B.*C/m
__END__
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsTree test</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/themes/default/style.min.css" />
</head>
<body>
<div id="container">
<ul>
<li>Child node A</li>
<li>Child node B</li>
<li>Child node C</li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>
<script>
$(function () {
$('#container').jstree({
"core" : { "check_callback" : true }, // so that operations work
"plugins" : ["dnd"]
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment