Added browser tests for translations and inline translations.
This commit is contained in:
parent
7a1bbfa4a0
commit
477fb1d3da
9 changed files with 315 additions and 47 deletions
|
@ -180,8 +180,12 @@ class Index extends App.ControllerContent
|
||||||
delete params.field
|
delete params.field
|
||||||
|
|
||||||
if params.id
|
if params.id
|
||||||
method = 'PUT'
|
if params.target is ''
|
||||||
url = "#{@apiPath}/translations/#{params.id}"
|
method = 'DELETE'
|
||||||
|
url = "#{@apiPath}/translations/#{params.id}"
|
||||||
|
else
|
||||||
|
method = 'PUT'
|
||||||
|
url = "#{@apiPath}/translations/#{params.id}"
|
||||||
else
|
else
|
||||||
method = 'POST'
|
method = 'POST'
|
||||||
url = "#{@apiPath}/translations"
|
url = "#{@apiPath}/translations"
|
||||||
|
|
|
@ -1,22 +1,32 @@
|
||||||
class Widget extends App.Controller
|
class Widget extends App.Controller
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
|
@rebind()
|
||||||
|
App.Event.bind('auth', => @rebind())
|
||||||
|
App.Event.bind('i18n:inline_translation', => @toogle())
|
||||||
|
|
||||||
|
rebind: =>
|
||||||
|
$(document).off('keydown.translation')
|
||||||
|
|
||||||
# only admins can do this
|
# only admins can do this
|
||||||
return if !@isRole('Admin')
|
return if !@isRole('Admin')
|
||||||
|
|
||||||
# bind on key down
|
# bind on key down
|
||||||
# if ctrl+alt+t is pressed, enable translation_inline and fire ui:rerender
|
# 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
|
if e.altKey && e.ctrlKey && e.keyCode is 84
|
||||||
if @active
|
@toogle()
|
||||||
@disable()
|
|
||||||
@active = false
|
|
||||||
else
|
|
||||||
@enable()
|
|
||||||
@active = true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
toogle: =>
|
||||||
|
if @active
|
||||||
|
@disable()
|
||||||
|
@active = false
|
||||||
|
return
|
||||||
|
|
||||||
|
@enable()
|
||||||
|
@active = true
|
||||||
|
|
||||||
enable: ->
|
enable: ->
|
||||||
# load in collection if needed
|
# load in collection if needed
|
||||||
meta = App.i18n.meta()
|
meta = App.i18n.meta()
|
||||||
|
@ -37,7 +47,6 @@ class Widget extends App.Controller
|
||||||
element.data 'before', element.text()
|
element.data 'before', element.text()
|
||||||
element
|
element
|
||||||
.on 'blur.translation', '.translation', (e) ->
|
.on 'blur.translation', '.translation', (e) ->
|
||||||
console.log('blur')
|
|
||||||
element = $(e.target)
|
element = $(e.target)
|
||||||
source = element.attr('title')
|
source = element.attr('title')
|
||||||
|
|
||||||
|
@ -65,7 +74,7 @@ class Widget extends App.Controller
|
||||||
locale: App.i18n.get()
|
locale: App.i18n.get()
|
||||||
source: source
|
source: source
|
||||||
target: translation_new
|
target: translation_new
|
||||||
initial_target: ''
|
target_initial: ''
|
||||||
)
|
)
|
||||||
translation.save()
|
translation.save()
|
||||||
|
|
||||||
|
@ -80,4 +89,4 @@ class Widget extends App.Controller
|
||||||
# rerender controllers
|
# rerender controllers
|
||||||
App.Event.trigger('ui:rerender')
|
App.Event.trigger('ui:rerender')
|
||||||
|
|
||||||
App.Config.set( 'translation_inline', Widget, 'Widgets' )
|
App.Config.set('translation_inline', Widget, 'Widgets')
|
||||||
|
|
|
@ -63,11 +63,11 @@ class App.Auth
|
||||||
|
|
||||||
# update config
|
# update config
|
||||||
for key, value of data.config
|
for key, value of data.config
|
||||||
App.Config.set( key, value )
|
App.Config.set(key, value)
|
||||||
|
|
||||||
# refresh default collections
|
# refresh default collections
|
||||||
if data.collections
|
if data.collections
|
||||||
App.Collection.resetCollections( data.collections )
|
App.Collection.resetCollections(data.collections)
|
||||||
|
|
||||||
# empty session
|
# empty session
|
||||||
App.Session.init()
|
App.Session.init()
|
||||||
|
@ -81,18 +81,18 @@ class App.Auth
|
||||||
|
|
||||||
# set locale
|
# set locale
|
||||||
locale = window.navigator.userLanguage || window.navigator.language || 'en-us'
|
locale = window.navigator.userLanguage || window.navigator.language || 'en-us'
|
||||||
App.i18n.set( locale )
|
App.i18n.set(locale)
|
||||||
|
|
||||||
# rebuild navbar with new navbar items
|
# rebuild navbar with new navbar items
|
||||||
App.Event.trigger( 'auth' )
|
App.Event.trigger('auth')
|
||||||
App.Event.trigger( 'auth:logout' )
|
App.Event.trigger('auth:logout')
|
||||||
App.Event.trigger( 'ui:rerender' )
|
App.Event.trigger('ui:rerender')
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# clear local store
|
# clear local store
|
||||||
if type isnt 'check'
|
if type isnt 'check'
|
||||||
App.Event.trigger( 'clearStore' )
|
App.Event.trigger('clearStore')
|
||||||
|
|
||||||
# update model definition
|
# update model definition
|
||||||
if data.models
|
if data.models
|
||||||
|
@ -103,33 +103,34 @@ class App.Auth
|
||||||
|
|
||||||
# update config
|
# update config
|
||||||
for key, value of data.config
|
for key, value of data.config
|
||||||
App.Config.set( key, value )
|
App.Config.set(key, value)
|
||||||
|
|
||||||
# refresh default collections
|
# refresh default collections
|
||||||
if data.collections
|
if data.collections
|
||||||
App.Collection.resetCollections( data.collections )
|
App.Collection.resetCollections(data.collections)
|
||||||
|
|
||||||
# load assets
|
# load assets
|
||||||
if data.assets
|
if data.assets
|
||||||
App.Collection.loadAssets( data.assets )
|
App.Collection.loadAssets(data.assets)
|
||||||
|
|
||||||
# store user data
|
# store user data
|
||||||
sessionUser = App.User.fullLocal(data.session.id)
|
sessionUser = App.User.fullLocal(data.session.id)
|
||||||
App.Session.set( sessionUser )
|
console.log('set', sessionUser)
|
||||||
|
App.Session.set(sessionUser)
|
||||||
|
|
||||||
# trigger auth ok with new session data
|
# trigger auth ok with new session data
|
||||||
App.Event.trigger( 'auth', data.session )
|
App.Event.trigger('auth', data.session)
|
||||||
|
|
||||||
# init of i18n
|
# init of i18n
|
||||||
preferences = App.Session.get( 'preferences' )
|
preferences = App.Session.get('preferences')
|
||||||
if preferences && preferences.locale
|
if preferences && preferences.locale
|
||||||
locale = preferences.locale
|
locale = preferences.locale
|
||||||
if !locale
|
if !locale
|
||||||
locale = window.navigator.userLanguage || window.navigator.language || 'en-us'
|
locale = window.navigator.userLanguage || window.navigator.language || 'en-us'
|
||||||
App.i18n.set( locale )
|
App.i18n.set(locale)
|
||||||
|
|
||||||
App.Event.trigger( 'auth:login', data.session )
|
App.Event.trigger('auth:login', data.session)
|
||||||
App.Event.trigger( 'ui:rerender' )
|
App.Event.trigger('ui:rerender')
|
||||||
|
|
||||||
|
|
||||||
@_logout: (data) ->
|
@_logout: (data) ->
|
||||||
|
@ -138,10 +139,10 @@ class App.Auth
|
||||||
# empty session
|
# empty session
|
||||||
App.Session.init()
|
App.Session.init()
|
||||||
|
|
||||||
App.Event.trigger( 'auth' )
|
App.Event.trigger('auth')
|
||||||
App.Event.trigger( 'auth:logout' )
|
App.Event.trigger('auth:logout')
|
||||||
App.Event.trigger( 'ui:rerender' )
|
App.Event.trigger('ui:rerender')
|
||||||
App.Event.trigger( 'clearStore' )
|
App.Event.trigger('clearStore')
|
||||||
|
|
||||||
@_loginError: ->
|
@_loginError: ->
|
||||||
App.Log.error 'Auth', '_loginError:error'
|
App.Log.error 'Auth', '_loginError:error'
|
||||||
|
@ -150,7 +151,7 @@ class App.Auth
|
||||||
App.Session.init()
|
App.Session.init()
|
||||||
|
|
||||||
# rebuild navbar
|
# rebuild navbar
|
||||||
App.Event.trigger( 'auth' )
|
App.Event.trigger('auth')
|
||||||
App.Event.trigger( 'auth:logout' )
|
App.Event.trigger('auth:logout')
|
||||||
App.Event.trigger( 'ui:rerender' )
|
App.Event.trigger('ui:rerender')
|
||||||
App.Event.trigger( 'clearStore' )
|
App.Event.trigger('clearStore')
|
||||||
|
|
|
@ -229,9 +229,15 @@ class _i18nSingleton extends Spine.Module
|
||||||
|
|
||||||
setMap: (source, target, format = 'string') =>
|
setMap: (source, target, format = 'string') =>
|
||||||
if format is 'time'
|
if format is 'time'
|
||||||
@mapTime[source] = target
|
if target is ''
|
||||||
|
delete @mapTime[source]
|
||||||
|
else
|
||||||
|
@mapTime[source] = target
|
||||||
else
|
else
|
||||||
@mapString[source] = target
|
if target is ''
|
||||||
|
delete @mapString[source]
|
||||||
|
else
|
||||||
|
@mapString[source] = target
|
||||||
|
|
||||||
notTranslatedFeatureEnabled: (locale) ->
|
notTranslatedFeatureEnabled: (locale) ->
|
||||||
if locale.substr(0,2) is 'en'
|
if locale.substr(0,2) is 'en'
|
||||||
|
|
|
@ -28,13 +28,13 @@ class App.Run extends App.Controller
|
||||||
@frontendTimeUpdate()
|
@frontendTimeUpdate()
|
||||||
|
|
||||||
# start navbars
|
# start navbars
|
||||||
@setupWidget( 'Navigations', 'nav', @el )
|
@setupWidget('Navigations', 'nav', @el)
|
||||||
|
|
||||||
# start widgets
|
# start widgets
|
||||||
@setupWidget( 'Widgets', 'widget', @el )
|
@setupWidget('Widgets', 'widget', @el)
|
||||||
|
|
||||||
# bind to fill selected text into
|
# bind to fill selected text into
|
||||||
App.ClipBoard.bind( @el )
|
App.ClipBoard.bind(@el)
|
||||||
|
|
||||||
App.Event.trigger('app:ready')
|
App.Event.trigger('app:ready')
|
||||||
|
|
||||||
|
@ -99,4 +99,4 @@ class App.Content extends App.ControllerWidgetPermanent
|
||||||
|
|
||||||
Spine.Route.setup()
|
Spine.Route.setup()
|
||||||
|
|
||||||
App.Config.set( 'content', App.Content, 'Widgets' )
|
App.Config.set('content', App.Content, 'Widgets')
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
<div><%- @T('English is the source language, so we have nothing to translate.') %></div>
|
|
|
@ -28,9 +28,10 @@ elif [ "$LEVEL" == '2' ]; then
|
||||||
rm test/browser/prefereces_test.rb
|
rm test/browser/prefereces_test.rb
|
||||||
rm test/browser/setting_test.rb
|
rm test/browser/setting_test.rb
|
||||||
rm test/browser/signup_password_change_and_reset_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_session_test.rb
|
||||||
rm test/browser/taskbar_task_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
|
elif [ "$LEVEL" == '3' ]; then
|
||||||
echo "slicing level 3"
|
echo "slicing level 3"
|
||||||
|
@ -45,9 +46,10 @@ elif [ "$LEVEL" == '3' ]; then
|
||||||
rm test/browser/maintenance_message_test.rb
|
rm test/browser/maintenance_message_test.rb
|
||||||
rm test/browser/manage_test.rb
|
rm test/browser/manage_test.rb
|
||||||
rm test/browser/signup_password_change_and_reset_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_session_test.rb
|
||||||
rm test/browser/taskbar_task_test.rb
|
rm test/browser/taskbar_task_test.rb
|
||||||
rm test/browser/switch_to_user_test.rb
|
rm test/browser/translation_test.rb
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "ERROR: Invalid level $LEVEL - 1, 2 or 3 is available"
|
echo "ERROR: Invalid level $LEVEL - 1, 2 or 3 is available"
|
||||||
|
|
248
test/browser/translation_test.rb
Normal file
248
test/browser/translation_test.rb
Normal 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
|
|
@ -347,8 +347,7 @@ class TestCase < Test::Unit::TestCase
|
||||||
|
|
||||||
instance = params[:browser] || @browser
|
instance = params[:browser] || @browser
|
||||||
if params[:js]
|
if params[:js]
|
||||||
instance.execute_script(params[:js])
|
return instance.execute_script(params[:js])
|
||||||
return
|
|
||||||
end
|
end
|
||||||
fail "Invalid execute params #{params.inspect}"
|
fail "Invalid execute params #{params.inspect}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue