Commit 5e63566b authored by Mike Greiling's avatar Mike Greiling

add InputHelper rspec helper to simulate non-BMP character input

parent 585a2ab5
import 'core-js/es6/map';
import 'core-js/es6/set';
import simulateDrag from './simulate_drag';
import simulateInput from './simulate_input';
// Export to global space for rspec to use
window.simulateDrag = simulateDrag;
window.simulateInput = simulateInput;
function triggerEvents(input) {
input.dispatchEvent(new Event('keydown'));
input.dispatchEvent(new Event('keypress'));
input.dispatchEvent(new Event('input'));
input.dispatchEvent(new Event('keyup'));
}
export default function simulateInput(target, text) {
const input = document.querySelector(target);
if (!input || !input.matches('textarea, input')) {
return false;
}
if (text.length > 0) {
Array.prototype.forEach.call(text, (char) => {
input.value += char;
triggerEvents(input);
});
} else {
triggerEvents();
}
return true;
}
require 'rails_helper'
feature 'GFM autocomplete', :js do
include InputHelper
let(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') }
let(:project) { create(:project) }
let(:label) { create(:label, project: project, title: 'special+') }
......@@ -14,10 +16,14 @@ feature 'GFM autocomplete', :js do
wait_for_requests
end
after do
execute_script("localStorage.clear();");
end
it 'updates issue descripton with GFM reference' do
find('.issuable-edit').click
find('#issue-description').native.send_keys("@#{user.name[0...3]}")
simulateInput('#issue-description', "@#{user.name[0...3]}")
find('.atwho-view .cur').click
......@@ -100,7 +106,7 @@ feature 'GFM autocomplete', :js do
it 'includes items for assignee dropdowns with non-ASCII characters in name' do
page.within '.timeline-content-form' do
find('#note-body').native.send_keys('')
find('#note-body').native.send_keys("@#{user.name[0...8]}")
simulateInput('#note-body', "@#{user.name[0...8]}");
end
expect(page).to have_selector('.atwho-container')
......@@ -128,7 +134,7 @@ feature 'GFM autocomplete', :js do
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('')
note.native.send_keys("~#{label.title[0]}")
simulateInput('#note-body', "~#{label.title[0]}")
note.click
end
......@@ -195,7 +201,7 @@ feature 'GFM autocomplete', :js do
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('')
note.native.send_keys(":cartwheel")
note.native.send_keys(":cartwheel_")
note.click
end
......@@ -228,7 +234,8 @@ feature 'GFM autocomplete', :js do
note.click
end
find('.atwho-view li', text: '/assign').native.send_keys(:tab)
find('.atwho-view li', text: '/assign')
note.native.send_keys(:tab)
user_item = find('.atwho-view li', text: user.username)
expect(user_item).to have_content(user.username)
......
# see app/assets/javascripts/test_utils/simulate_input.js
module InputHelper
def simulateInput(selector, input = '')
evaluate_script("window.simulateInput(#{selector.to_json}, #{input.to_json});")
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment