Merge pull request #941 from ONLYOFFICE/bugfix/translation-tests-on-macos
Bugfix/translation tests on macos
This commit is contained in:
commit
ce34f2db28
8
build/run.translations.tests.sh
Executable file
8
build/run.translations.tests.sh
Executable file
@ -0,0 +1,8 @@
|
||||
rd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
echo "Run script directory:" $dir
|
||||
|
||||
dir=$(builtin cd $rd/../; pwd)
|
||||
|
||||
echo "Root directory:" $dir
|
||||
|
||||
dotnet test $dir/common/Tests/Frontend.Translations.Tests/Frontend.Translations.Tests.csproj --filter "TestCategory=FastRunning" -l:html -r $dir/TestsResults
|
@ -48,7 +48,7 @@ public class Tests
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetFullPath("..\\..\\..\\..\\..\\..\\");
|
||||
return Path.GetFullPath(Utils.ConvertPathToOS("../../../../../../"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,9 +59,11 @@ public class Tests
|
||||
public List<KeyValuePair<string, string>> NotTranslatedToasts { get; set; }
|
||||
public List<LanguageItem> CommonTranslations { get; set; }
|
||||
public List<ParseJsonError> ParseJsonErrors { get; set; }
|
||||
public static string ConvertPathToOS { get; private set; }
|
||||
|
||||
//public List<JsonEncodingError> WrongEncodingJsonErrors { get; set; }
|
||||
|
||||
private static readonly string _md5ExcludesPath = "../../../md5-excludes.json";
|
||||
private static readonly string _md5ExcludesPath = Path.GetFullPath(Utils.ConvertPathToOS("../../../md5-excludes.json"));
|
||||
|
||||
//private static string _encodingExcludesPath = "../../../encoding-excludes.json";
|
||||
|
||||
@ -81,26 +83,28 @@ public class Tests
|
||||
|
||||
var moduleWorkspaces = new List<string>
|
||||
{
|
||||
"packages\\client",
|
||||
"packages\\common",
|
||||
"packages\\components",
|
||||
"packages\\editor",
|
||||
"packages\\login"
|
||||
Utils.ConvertPathToOS("packages/client"),
|
||||
Utils.ConvertPathToOS("packages/common"),
|
||||
Utils.ConvertPathToOS("packages/components"),
|
||||
Utils.ConvertPathToOS("packages/editor"),
|
||||
Utils.ConvertPathToOS("packages/login")
|
||||
};
|
||||
|
||||
Workspaces = new List<string>();
|
||||
|
||||
Workspaces.AddRange(moduleWorkspaces);
|
||||
|
||||
Workspaces.Add("public\\locales");
|
||||
|
||||
Workspaces.Add(Utils.ConvertPathToOS("public/locales"));
|
||||
|
||||
var translationFiles = from wsPath in Workspaces
|
||||
let clientDir = Path.Combine(BasePath, wsPath)
|
||||
from filePath in Directory.EnumerateFiles(clientDir, "*.json", SearchOption.AllDirectories)
|
||||
where filePath.Contains("public\\locales\\")
|
||||
where filePath.Contains(Utils.ConvertPathToOS("public/locales/"))
|
||||
select Path.GetFullPath(filePath);
|
||||
|
||||
TestContext.Progress.WriteLine($"Base path = {BasePath}");
|
||||
TestContext.Progress.WriteLine($"Found translationFiles by *.json filter = {translationFiles.Count()}. First path is '{translationFiles.FirstOrDefault()}'");
|
||||
|
||||
TranslationFiles = new List<TranslationFile>();
|
||||
|
||||
foreach (var path in translationFiles)
|
||||
@ -154,22 +158,26 @@ public class Tests
|
||||
catch (Exception ex)
|
||||
{
|
||||
ParseJsonErrors.Add(new ParseJsonError(path, ex));
|
||||
Debug.WriteLine($"File path = {path} failed to parse with error: {ex.Message}");
|
||||
TestContext.Progress.WriteLine($"File path = {path} failed to parse with error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
TestContext.Progress.WriteLine($"Found TranslationFiles = {TranslationFiles.Count()}. First path is '{TranslationFiles.FirstOrDefault()?.FilePath}'");
|
||||
|
||||
var javascriptFiles = (from wsPath in Workspaces
|
||||
let clientDir = Path.Combine(BasePath, wsPath)
|
||||
from file in Directory.EnumerateFiles(clientDir, "*.js", SearchOption.AllDirectories)
|
||||
where !file.Contains("dist\\")
|
||||
select file)
|
||||
from filePath in Directory.EnumerateFiles(clientDir, "*.js", SearchOption.AllDirectories)
|
||||
where !filePath.Contains(Utils.ConvertPathToOS("dist/")) && !filePath.Contains(".test.js") && !filePath.Contains(".stories.js")
|
||||
select Utils.ConvertPathToOS(filePath))
|
||||
.ToList();
|
||||
|
||||
javascriptFiles.AddRange(from wsPath in Workspaces
|
||||
let clientDir = Path.Combine(BasePath, wsPath)
|
||||
from file in Directory.EnumerateFiles(clientDir, "*.jsx", SearchOption.AllDirectories)
|
||||
where !file.Contains("dist\\")
|
||||
select file);
|
||||
from filePath in Directory.EnumerateFiles(clientDir, "*.jsx", SearchOption.AllDirectories)
|
||||
where !filePath.Contains(Utils.ConvertPathToOS("dist/")) && !filePath.Contains(".test.jsx") && !filePath.Contains(".stories.jsx")
|
||||
select Utils.ConvertPathToOS(filePath));
|
||||
|
||||
TestContext.Progress.WriteLine($"Found javascriptFiles by *.js(x) filter = {javascriptFiles.Count()}. First path is '{javascriptFiles.FirstOrDefault()}'");
|
||||
|
||||
JavaScriptFiles = new List<JavaScriptFile>();
|
||||
|
||||
@ -222,6 +230,8 @@ public class Tests
|
||||
JavaScriptFiles.Add(jsFile);
|
||||
}
|
||||
|
||||
TestContext.Progress.WriteLine($"Found JavaScriptFiles = {JavaScriptFiles.Count()}. First path is '{JavaScriptFiles.FirstOrDefault()?.Path}'");
|
||||
|
||||
ModuleFolders = new List<ModuleFolder>();
|
||||
|
||||
var list = TranslationFiles
|
||||
@ -246,6 +256,8 @@ public class Tests
|
||||
})
|
||||
.ToList();
|
||||
|
||||
TestContext.Progress.WriteLine($"Found moduleTranslations = {moduleTranslations.Count()}. First path is '{moduleTranslations.FirstOrDefault()?.ModulePath}'");
|
||||
|
||||
var moduleJsTranslatedFiles = JavaScriptFiles
|
||||
.Select(t => new
|
||||
{
|
||||
@ -261,6 +273,8 @@ public class Tests
|
||||
})
|
||||
.ToList();
|
||||
|
||||
TestContext.Progress.WriteLine($"Found moduleJsTranslatedFiles = {moduleJsTranslatedFiles.Count()}. First path is '{moduleJsTranslatedFiles.FirstOrDefault()?.ModulePath}'");
|
||||
|
||||
foreach (var wsPath in moduleWorkspaces)
|
||||
{
|
||||
var t = moduleTranslations.FirstOrDefault(t => t.ModulePath == wsPath);
|
||||
@ -277,14 +291,21 @@ public class Tests
|
||||
});
|
||||
}
|
||||
|
||||
TestContext.Progress.WriteLine($"Found ModuleFolders = {ModuleFolders.Count()}. First path is '{ModuleFolders.FirstOrDefault()?.Path}'");
|
||||
|
||||
CommonTranslations = TranslationFiles
|
||||
.Where(file => file.FilePath.StartsWith($"{BasePath}public\\locales"))
|
||||
.Where(file => file.FilePath.StartsWith(Utils.ConvertPathToOS($"{BasePath}public/locales")))
|
||||
.Select(t => new LanguageItem
|
||||
{
|
||||
Path = t.FilePath,
|
||||
Language = t.Language,
|
||||
Translations = t.Translations
|
||||
}).ToList();
|
||||
|
||||
TestContext.Progress.WriteLine($"Found CommonTranslations = {CommonTranslations.Count()}. First path is '{CommonTranslations.FirstOrDefault()?.Path}'");
|
||||
|
||||
TestContext.Progress.WriteLine($"Found _md5Excludes = {_md5Excludes.Count()} Path to file '{_md5ExcludesPath}'");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -296,8 +317,8 @@ public class Tests
|
||||
|
||||
public static Tuple<string, string> getPaths(string language)
|
||||
{
|
||||
const string dictionariesPath = @"..\..\..\dictionaries";
|
||||
const string additionalPath = @"..\..\..\additional";
|
||||
const string dictionariesPath = @"../../../dictionaries";
|
||||
const string additionalPath = @"../../../additional";
|
||||
|
||||
var path = dictionariesPath;
|
||||
|
||||
@ -310,8 +331,8 @@ public class Tests
|
||||
break;
|
||||
}
|
||||
|
||||
var dicPath = Path.Combine(path, language, $"{language}.dic");
|
||||
var affPath = Path.Combine(path, language, $"{language}.aff");
|
||||
var dicPath = Utils.ConvertPathToOS(Path.Combine(path, language, $"{language}.dic"));
|
||||
var affPath = Utils.ConvertPathToOS(Path.Combine(path, language, $"{language}.aff"));
|
||||
|
||||
return new Tuple<string, string>(dicPath, affPath);
|
||||
}
|
||||
@ -407,6 +428,7 @@ public class Tests
|
||||
public void DublicatesFilesByMD5HashTest()
|
||||
{
|
||||
var duplicatesByMD5 = TranslationFiles
|
||||
.Where(t => t.Language != "pt-BR")
|
||||
.Where(t => !_md5Excludes.Contains(t.Md5Hash))
|
||||
.GroupBy(t => t.Md5Hash)
|
||||
.Where(grp => grp.Count() > 1)
|
||||
@ -553,7 +575,7 @@ public class Tests
|
||||
var lngFilePaths = lng.Files.Select(f => f.FilePath).ToList();
|
||||
|
||||
var notFoundFilePaths = enFilePaths
|
||||
.Select(p => p.Replace("\\en\\", $"\\{lng.Lng}\\"))
|
||||
.Select(p => p.Replace(Utils.ConvertPathToOS("/en/"), Utils.ConvertPathToOS($"/{lng.Lng}/")))
|
||||
.Where(p => !lngFilePaths.Contains(p));
|
||||
|
||||
message += string.Join("\r\n", notFoundFilePaths);
|
||||
@ -562,7 +584,7 @@ public class Tests
|
||||
|
||||
/*foreach (var path in notFoundFilePaths)
|
||||
{
|
||||
SaveNotFoundLanguage(path.Replace($"\\{lng.Lng}\\", "\\en\\"), path);
|
||||
SaveNotFoundLanguage(path.Replace(Utils.ConvertPathToOS($"\\{lng.Lng}\\"), Utils.ConvertPathToOS("\\en\\")), path);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@ -613,7 +635,7 @@ public class Tests
|
||||
{
|
||||
var lngKeys = lng.Translations.Select(f => f.Key).ToList();
|
||||
|
||||
var enKeys = enLanguages.Where(l => l.Path == lng.Path.Replace($"\\{lng.Language}\\", "\\en\\"))
|
||||
var enKeys = enLanguages.Where(l => l.Path == lng.Path.Replace(Utils.ConvertPathToOS($"/{lng.Language}/"), Utils.ConvertPathToOS("/en/")))
|
||||
.SelectMany(l => l.Translations.Select(f => f.Key))
|
||||
.ToList();
|
||||
|
||||
@ -698,7 +720,7 @@ public class Tests
|
||||
|
||||
if (module.AppliedJsTranslationKeys == null && module.AvailableLanguages != null)
|
||||
{
|
||||
message += $"{++index}. 'ANY LANGUAGES' '{module.Path}' NOT USES";
|
||||
message += $"{++index}. 'ANY LANGUAGES' '{module.Path}' NOT USED\r\n";
|
||||
|
||||
var list = module.AvailableLanguages
|
||||
.SelectMany(l => l.Translations.Select(t => t.Key).ToList())
|
||||
@ -857,15 +879,13 @@ public class Tests
|
||||
switch (folderName)
|
||||
{
|
||||
case "Client":
|
||||
return Workspaces.Find(w => w.Contains("ASC.Web.Client"));
|
||||
case "Files":
|
||||
return Workspaces.Find(w => w.Contains("ASC.Files"));
|
||||
return Workspaces.Find(w => w.Contains("client"));
|
||||
case "Editor":
|
||||
return Workspaces.Find(w => w.Contains("editor"));
|
||||
case "Login":
|
||||
return Workspaces.Find(w => w.Contains("ASC.Web.Login"));
|
||||
case "People":
|
||||
return Workspaces.Find(w => w.Contains("ASC.People"));
|
||||
return Workspaces.Find(w => w.Contains("login"));
|
||||
default:
|
||||
return Path.Combine(BasePath, "public\\locales");
|
||||
return Path.Combine(BasePath, Utils.ConvertPathToOS("public\\locales"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1144,14 +1164,14 @@ public class Tests
|
||||
/// <summary>
|
||||
/// Converts a file from one encoding to another.
|
||||
/// </summary>
|
||||
/// <param name=”sourcePath”>the file to convert</param>
|
||||
/// <param name=”destPath”>the destination for the converted file</param>
|
||||
/// <param name=”sourceEncoding”>the original file encoding</param>
|
||||
/// <param name=”destEncoding”>the encoding to which the contents should be converted</param>
|
||||
/// <param name="sourcePath">the file to convert</param>
|
||||
/// <param name="destPath">the destination for the converted file</param>
|
||||
/// <param name="sourceEncoding">the original file encoding</param>
|
||||
/// <param name="destEncoding">the encoding to which the contents should be converted</param>
|
||||
//public static void ConvertFileEncoding(string sourcePath, string destPath,
|
||||
// Encoding sourceEncoding, Encoding destEncoding)
|
||||
//{
|
||||
// // If the destination’s parent doesn’t exist, create it.
|
||||
// // If the destination's parent doesn't exist, create it.
|
||||
// var parent = Path.GetDirectoryName(Path.GetFullPath(destPath));
|
||||
// if (!Directory.Exists(parent))
|
||||
// {
|
||||
|
@ -32,7 +32,7 @@ public class JavaScriptFile
|
||||
{
|
||||
public JavaScriptFile(string path)
|
||||
{
|
||||
Path = path.Replace("/", "\\");
|
||||
Path = Utils.ConvertPathToOS(path);
|
||||
}
|
||||
|
||||
public string Path { get; }
|
||||
|
@ -35,17 +35,17 @@ namespace Frontend.Translations.Tests.Models;
|
||||
|
||||
public class SpellCheckResult
|
||||
{
|
||||
private static Regex wordRegex = new Regex(@"[\p{L}-]+", RegexOptions.Multiline | RegexOptions.Compiled);
|
||||
private static Regex regVariables = new Regex("\\{\\{([^\\{].?[^\\}]+)\\}\\}", RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
private static Regex htmlTags = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
private static List<string> trademarks = new List<string>()
|
||||
private static readonly Regex wordRegex = new Regex(@"[\p{L}-]+", RegexOptions.Multiline | RegexOptions.Compiled);
|
||||
private static readonly Regex regVariables = new Regex("\\{\\{([^\\{].?[^\\}]+)\\}\\}", RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
private static readonly Regex htmlTags = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
private static readonly List<string> trademarks = new List<string>()
|
||||
{
|
||||
"onlyoffice.com", "onlyoffice.eu", "Office Open XML", "ONLYOFFICE Desktop Editors",
|
||||
"ONLYOFFICE Desktop", "ONLYOFFICE Documents", "Google Drive", "Twitter", "Facebook", "LinkedIn", "Google",
|
||||
"Yandex", "Yandex.Disk", "Dropbox","OneDrive","ONLYOFFICE", "DocuSign", "e-mail",
|
||||
"SharePoint", "Windows Phone", "Enterprise Edition", "AES-256"
|
||||
};
|
||||
private static List<string> exclusions = new List<string>()
|
||||
private static readonly List<string> exclusions = new List<string>()
|
||||
{
|
||||
"ok","doc","docx","xls","xlsx","ppt","pptx","xml","ooxml","jpg","png","mb","ip",
|
||||
"canvas","tag","Disk","Box","Dcs","zip","Android","Authenticator","iOS","Windows",
|
||||
@ -53,7 +53,7 @@ public class SpellCheckResult
|
||||
"Portal","Favicon","URL","QR", "email", "app", "api"
|
||||
};
|
||||
|
||||
private static List<SpellCheckExclude> excludes = File.Exists("../../../spellcheck-excludes.json")
|
||||
private static readonly List<SpellCheckExclude> excludes = File.Exists("../../../spellcheck-excludes.json")
|
||||
? JsonConvert.DeserializeObject<List<SpellCheckExclude>>(File.ReadAllText("../../../spellcheck-excludes.json"))
|
||||
: new List<SpellCheckExclude>();
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class TranslationFile
|
||||
{
|
||||
public TranslationFile(string path, List<TranslationItem> translations, string md5hash = null)
|
||||
{
|
||||
FilePath = path.Replace("/", "\\");
|
||||
FilePath = Utils.ConvertPathToOS(path);
|
||||
|
||||
FileName = Path.GetFileName(FilePath);
|
||||
|
||||
|
@ -56,8 +56,8 @@ public static class SpellCheck
|
||||
|
||||
public static DicPaths GetDictionaryPaths(string lng)
|
||||
{
|
||||
const string dictionariesPath = @"..\..\..\dictionaries";
|
||||
const string additionalPath = @"..\..\..\additional";
|
||||
const string dictionariesPath = @"../../../dictionaries";
|
||||
const string additionalPath = @"../../../additional";
|
||||
|
||||
var path = dictionariesPath;
|
||||
string language;
|
||||
|
14
common/Tests/Frontend.Translations.Tests/Utils.cs
Normal file
14
common/Tests/Frontend.Translations.Tests/Utils.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Frontend.Translations.Tests
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public static string ConvertPathToOS(string path)
|
||||
{
|
||||
return Path.DirectorySeparatorChar == '/' ? path.Replace("\\", "/") : path.Replace("/", "\\");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user