Added browser tests for translations and inline translations.

This commit is contained in:
Martin Edenhofer 2015-12-18 17:18:09 +01:00
parent 7a1bbfa4a0
commit 477fb1d3da
9 changed files with 315 additions and 47 deletions

View file

@ -180,6 +180,10 @@ class Index extends App.ControllerContent
delete params.field
if params.id
if params.target is ''
method = 'DELETE'
url = "#{@apiPath}/translations/#{params.id}"
else
method = 'PUT'
url = "#{@apiPath}/translations/#{params.id}"
else

View file

@ -1,21 +1,31 @@
class Widget extends App.Controller
constructor: ->
super
@rebind()
App.Event.bind('auth', => @rebind())
App.Event.bind('i18n:inline_translation', => @toogle())
rebind: =>
$(document).off('keydown.translation')
# only admins can do this
return if !@isRole('Admin')
# bind on key down
# if ctrl+alt+t is pressed, enable translation_inline and fire ui:rerender
$(document).on('keydown', (e) =>
$(document).on('keydown.translation', (e) =>
if e.altKey && e.ctrlKey && e.keyCode is 84
@toogle()
)
toogle: =>
if @active
@disable()
@active = false
else
return
@enable()
@active = true
)
enable: ->
# load in collection if needed
@ -37,7 +47,6 @@ class Widget extends App.Controller
element.data 'before', element.text()
element
.on 'blur.translation', '.translation', (e) ->
console.log('blur')
element = $(e.target)
source = element.attr('title')
@ -65,7 +74,7 @@ class Widget extends App.Controller
locale: App.i18n.get()
source: source
target: translation_new
initial_target: ''
target_initial: ''
)
translation.save()

View file

@ -115,6 +115,7 @@ class App.Auth
# store user data
sessionUser = App.User.fullLocal(data.session.id)
console.log('set', sessionUser)
App.Session.set(sessionUser)
# trigger auth ok with new session data

View file

@ -229,7 +229,13 @@ class _i18nSingleton extends Spine.Module
setMap: (source, target, format = 'string') =>
if format is 'time'
if target is ''
delete @mapTime[source]
else
@mapTime[source] = target
else
if target is ''
delete @mapString[source]
else
@mapString[source] = target

View file

@ -1 +0,0 @@
<div><%- @T('English is the source language, so we have nothing to translate.') %></div>

View file

@ -28,9 +28,10 @@ elif [ "$LEVEL" == '2' ]; then
rm test/browser/prefereces_test.rb
rm test/browser/setting_test.rb
rm test/browser/signup_password_change_and_reset_test.rb
rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb
rm test/browser/switch_to_user_test.rb
rm test/browser/translation_test.rb
elif [ "$LEVEL" == '3' ]; then
echo "slicing level 3"
@ -45,9 +46,10 @@ elif [ "$LEVEL" == '3' ]; then
rm test/browser/maintenance_message_test.rb
rm test/browser/manage_test.rb
rm test/browser/signup_password_change_and_reset_test.rb
rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb
rm test/browser/switch_to_user_test.rb
rm test/browser/translation_test.rb
else
echo "ERROR: Invalid level $LEVEL - 1, 2 or 3 is available"

View file

@ -0,0 +1,248 @@
# encoding: utf-8
require 'browser_test_helper'
class TranslationTest < TestCase
def test_preferences
@browser = browser_instance
login(
username: 'master@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all()
click(css: 'a[href="#current_user"]')
click(css: 'a[href="#profile"]')
click(css: 'a[href="#profile/language"]')
select(
css: '.language_item select[name="locale"]',
value: 'English (United States)',
)
click(css: '.content button[type="submit"]')
sleep 2
watch_for(
css: 'body',
value: 'Language',
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/translation"]')
watch_for(
css: '#content',
value: 'English is the source language, so we have nothing to translate',
)
click(css: 'a[href="#current_user"]')
click(css: 'a[href="#profile"]')
click(css: 'a[href="#profile/language"]')
select(
css: '.language_item select[name="locale"]',
value: 'Deutsch',
)
click(css: '.content button[type="submit"]')
watch_for(
css: 'body',
value: 'Sprache',
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/translation"]')
set(
css: '#content input.js-Item[data-source="Translations"]',
value: 'Übersetzung2',
)
click(css: '#global-search')
click(css: 'a[href="#dashboard"]')
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/translation"]')
sleep 4
match(
css: '#content .sidebar',
value: 'Übersetzung2',
)
match(
css: '#content input.js-Item[data-source="Translations"]',
value: 'Übersetzung2',
)
execute(
js: "$('.js-Item[data-source=Translations]').parents('tr').find('.js-Reset:visible').click()",
)
sleep 5
match(
css: '#content .sidebar',
value: 'Übersetzung2',
)
match_not(
css: '#content input.js-Item[data-source="Translations"]',
value: 'Übersetzung2',
)
click(css: 'a[href="#dashboard"]')
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/translation"]')
sleep 2
match_not(
css: '#content .sidebar',
value: 'Übersetzung2',
)
match_not(
css: '#content input.js-Item[data-source="Translations"]',
value: 'Übersetzung2',
)
match_not(
css: '#content .sidebar',
value: 'Übersetzung2',
)
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
watch_for(
css: 'span.translation[title="Overviews"]',
value: 'Übersichten',
)
set(
css: 'span.translation[title="Overviews"]',
value: 'Übersichten123',
)
sleep 1
click(css: '#global-search')
sleep 5
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
sleep 5
exists_not(
css: 'span.translation[title="Overviews"]',
)
match(
css: '.js-menu',
value: 'Übersichten123',
)
reload()
exists_not(
css: 'span.translation[title="Overviews"]',
)
match(
css: '.js-menu',
value: 'Übersichten123',
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/translation"]')
sleep 4
match(
css: '#content input.js-Item[data-source="Overviews"]',
value: 'Übersichten123',
)
execute(
js: "$('.js-Item[data-source=Overviews]').parents('tr').find('.js-Reset:visible').click()",
)
sleep 5
click(css: 'a[href="#dashboard"]')
sleep 5
match_not(
css: '.js-menu',
value: 'Übersichten123',
)
match(
css: '.js-menu',
value: 'Übersichten',
)
click(css: 'a[href="#current_user"]')
click(css: 'a[href="#profile"]')
click(css: 'a[href="#profile/language"]')
select(
css: '.language_item select[name="locale"]',
value: 'English (United States)',
)
click(css: '.content button[type="submit"]')
sleep 2
watch_for(
css: 'body',
value: 'Language',
)
sleep 5
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
watch_for(
css: 'span.translation[title="Overviews"]',
value: 'Overviews',
)
set(
css: 'span.translation[title="Overviews"]',
value: 'Overviews123',
)
sleep 1
click(css: '#global-search')
sleep 5
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
sleep 5
exists_not(
css: 'span.translation[title="Overviews"]',
)
match(
css: '.js-menu',
value: 'Overviews123',
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/translation"]')
sleep 4
match(
css: '#content input.js-Item[data-source="Overviews"]',
value: 'Overviews123',
)
match_not(
css: '#content',
value: 'English is the source language, so we have nothing to translate',
)
execute(
js: "$('.js-Item[data-source=Overviews]').parents('tr').find('.js-Reset:visible').click()",
)
watch_for(
css: '#content',
value: 'English is the source language, so we have nothing to translate',
)
end
end

View file

@ -347,8 +347,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser
if params[:js]
instance.execute_script(params[:js])
return
return instance.execute_script(params[:js])
end
fail "Invalid execute params #{params.inspect}"
end