diff --git a/build/run.translations.tests.sh b/build/run.translations.tests.sh new file mode 100755 index 0000000000..14b5896410 --- /dev/null +++ b/build/run.translations.tests.sh @@ -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 \ No newline at end of file diff --git a/common/Tests/Frontend.Translations.Tests/LocalesTest.cs b/common/Tests/Frontend.Translations.Tests/LocalesTest.cs index 7f1788ca24..17e3fd5fb8 100644 --- a/common/Tests/Frontend.Translations.Tests/LocalesTest.cs +++ b/common/Tests/Frontend.Translations.Tests/LocalesTest.cs @@ -48,7 +48,7 @@ public class Tests { get { - return Path.GetFullPath("..\\..\\..\\..\\..\\..\\"); + return Path.GetFullPath(Utils.ConvertPathToOS("../../../../../../")); } } @@ -58,10 +58,12 @@ public class Tests public List ModuleFolders { get; set; } public List> NotTranslatedToasts { get; set; } public List CommonTranslations { get; set; } - public List ParseJsonErrors { get; set; } - //public List WrongEncodingJsonErrors { get; set; } - - private static readonly string _md5ExcludesPath = "../../../md5-excludes.json"; + public List ParseJsonErrors { get; set; } + public static string ConvertPathToOS { get; private set; } + + //public List WrongEncodingJsonErrors { get; set; } + + 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 { - "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(); 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(); 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(); @@ -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(); 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 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(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 /// /// Converts a file from one encoding to another. /// - /// the file to convert - /// the destination for the converted file - /// the original file encoding - /// the encoding to which the contents should be converted + /// the file to convert + /// the destination for the converted file + /// the original file encoding + /// the encoding to which the contents should be converted //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)) // { diff --git a/common/Tests/Frontend.Translations.Tests/Models/JavaScriptFile.cs b/common/Tests/Frontend.Translations.Tests/Models/JavaScriptFile.cs index cb18443aaa..b68eb6aea9 100644 --- a/common/Tests/Frontend.Translations.Tests/Models/JavaScriptFile.cs +++ b/common/Tests/Frontend.Translations.Tests/Models/JavaScriptFile.cs @@ -32,7 +32,7 @@ public class JavaScriptFile { public JavaScriptFile(string path) { - Path = path.Replace("/", "\\"); + Path = Utils.ConvertPathToOS(path); } public string Path { get; } diff --git a/common/Tests/Frontend.Translations.Tests/Models/SpellCheckResult.cs b/common/Tests/Frontend.Translations.Tests/Models/SpellCheckResult.cs index b75b35f83b..3e10b44567 100644 --- a/common/Tests/Frontend.Translations.Tests/Models/SpellCheckResult.cs +++ b/common/Tests/Frontend.Translations.Tests/Models/SpellCheckResult.cs @@ -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 trademarks = new List() + 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 trademarks = new List() { "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 exclusions = new List() + private static readonly List exclusions = new List() { "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 excludes = File.Exists("../../../spellcheck-excludes.json") + private static readonly List excludes = File.Exists("../../../spellcheck-excludes.json") ? JsonConvert.DeserializeObject>(File.ReadAllText("../../../spellcheck-excludes.json")) : new List(); diff --git a/common/Tests/Frontend.Translations.Tests/Models/TranslationFile.cs b/common/Tests/Frontend.Translations.Tests/Models/TranslationFile.cs index 53688a02a6..598c6f18f9 100644 --- a/common/Tests/Frontend.Translations.Tests/Models/TranslationFile.cs +++ b/common/Tests/Frontend.Translations.Tests/Models/TranslationFile.cs @@ -33,7 +33,7 @@ public class TranslationFile { public TranslationFile(string path, List translations, string md5hash = null) { - FilePath = path.Replace("/", "\\"); + FilePath = Utils.ConvertPathToOS(path); FileName = Path.GetFileName(FilePath); diff --git a/common/Tests/Frontend.Translations.Tests/SpellCheck.cs b/common/Tests/Frontend.Translations.Tests/SpellCheck.cs index 31ccf4c4de..595e1f2655 100644 --- a/common/Tests/Frontend.Translations.Tests/SpellCheck.cs +++ b/common/Tests/Frontend.Translations.Tests/SpellCheck.cs @@ -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; diff --git a/common/Tests/Frontend.Translations.Tests/Utils.cs b/common/Tests/Frontend.Translations.Tests/Utils.cs new file mode 100644 index 0000000000..6f8f432fd9 --- /dev/null +++ b/common/Tests/Frontend.Translations.Tests/Utils.cs @@ -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("/", "\\"); + } + } +} +