Merge pull request #2656 from overleaf/jpa-import-709

[misc] fileOperationI18nNames: drop blocking DOM access

GitOrigin-RevId: e6aab686fc8d4fe3b5515033b88548278c7bf7c0
This commit is contained in:
Timothée Alby 2020-03-09 08:36:29 -05:00 committed by Copybot
parent fbbb39b0c0
commit 620b95fbe8
3 changed files with 10 additions and 21 deletions

View file

@ -56,7 +56,6 @@ script(type="text/ng-template", id="historyFileEntityTpl")
file-entity="childEntity"
)
script(type="template", id="file_action_edited_str") #{ translate('file_action_edited') }
script(type="template", id="file_action_renamed_str") #{ translate('file_action_renamed') }
script(type="template", id="file_action_created_str") #{ translate('file_action_created') }
script(type="template", id="file_action_deleted_str") #{ translate('file_action_deleted') }
- var fileActionI18n = ['edited', 'renamed', 'created', 'deleted'].reduce((acc, i) => {acc[i] = translate('file_action_' + i); return acc}, {})
script(type="text/javascript").
window.fileActionI18n = JSON.parse('!{StringHelper.stringifyJsonForScript(fileActionI18n)}')

View file

@ -1,8 +1,11 @@
define([], function() {
if (window.fileActionI18n !== undefined) {
return window.fileActionI18n
}
return {
edited: document.getElementById('file_action_edited_str').innerText,
renamed: document.getElementById('file_action_renamed_str').innerText,
created: document.getElementById('file_action_created_str').innerText,
deleted: document.getElementById('file_action_deleted_str').innerText
edited: 'edited',
renamed: 'renamed',
created: 'created',
deleted: 'deleted'
}
})

View file

@ -25,19 +25,6 @@ chai.Assertion.addMethod('equalPos', function(expectedPos) {
// Mock ExposedSettings
window.ExposedSettings = {}
// Mock the file operation I18n names that are stored in the DOM
function mockFileOperationI18nNames(id, text) {
const el = document.createElement('div')
el.id = id
el.innerText = text
el.setAttribute('hidden', true)
document.body.appendChild(el)
}
mockFileOperationI18nNames('file_action_edited_str', 'edited')
mockFileOperationI18nNames('file_action_renamed_str', 'renamed')
mockFileOperationI18nNames('file_action_created_str', 'created')
mockFileOperationI18nNames('file_action_deleted_str', 'deleted')
/*
* Bundle all test files together into a single bundle, and run tests against
* this single bundle.