Skip to content

Commit

Permalink
Web: Tests: Fix translations test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeySafronov committed Jan 20, 2022
1 parent 5c34a2b commit 7e919c9
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions common/Tests/Frontend.Translations.Tests/LocalesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,18 @@ from file in Directory.EnumerateFiles(clientDir, "*.jsx", SearchOption.AllDirect
{
var jsFileText = File.ReadAllText(path);

var toastMatches = notTranslatedToastsRegex.Matches(jsFileText).ToList();

if (toastMatches.Any())
if (!path.Contains("asc-web-components"))
{
foreach (var toastMatch in toastMatches)
var toastMatches = notTranslatedToastsRegex.Matches(jsFileText).ToList();

if (toastMatches.Any())
{
var found = toastMatch.Value;
if (!string.IsNullOrEmpty(found) && !NotTranslatedToasts.Exists(t => t.Value == found))
NotTranslatedToasts.Add(new KeyValuePair<string, string>(path, found));
foreach (var toastMatch in toastMatches)
{
var found = toastMatch.Value;
if (!string.IsNullOrEmpty(found) && !NotTranslatedToasts.Exists(t => t.Value == found))
NotTranslatedToasts.Add(new KeyValuePair<string, string>(path, found));
}
}
}

Expand Down Expand Up @@ -202,7 +205,6 @@ from file in Directory.EnumerateFiles(clientDir, "*.jsx", SearchOption.AllDirect
{
ModulePath = g.Key,
Languages = g.ToList().Select(t => t.Language).ToList()
.ToList()
})
.ToList();

Expand All @@ -221,17 +223,17 @@ from file in Directory.EnumerateFiles(clientDir, "*.jsx", SearchOption.AllDirect
})
.ToList();

foreach (var ws in moduleWorkspaces)
foreach (var wsPath in moduleWorkspaces)
{
var t = moduleTranslations.FirstOrDefault(t => t.ModulePath == ws);
var j = moduleJsTranslatedFiles.FirstOrDefault(t => t.ModulePath == ws);
var t = moduleTranslations.FirstOrDefault(t => t.ModulePath == wsPath);
var j = moduleJsTranslatedFiles.FirstOrDefault(t => t.ModulePath == wsPath);

if (j == null && t == null)
continue;

ModuleFolders.Add(new ModuleFolder
{
Path = ws,
Path = wsPath,
AvailableLanguages = t?.Languages,
AppliedJsTranslationKeys = j?.TranslationKeys
});
Expand Down Expand Up @@ -624,13 +626,18 @@ public void UselessModuleTranslationKeysTest()

var message = $"Some i18n-keys are not found in js: \r\nKeys: \r\n\r\n";

var index = 0;

for (int i = 0; i < ModuleFolders.Count; i++)
{
var module = ModuleFolders[i];

if (module.Path == "packages\\asc-web-components")
continue;

if (module.AppliedJsTranslationKeys == null && module.AvailableLanguages != null)
{
message += $"{i}. 'ANY LANGUAGES' '{module.Path}' NOT USES";
message += $"{++index}. 'ANY LANGUAGES' '{module.Path}' NOT USES";

var list = module.AvailableLanguages
.SelectMany(l => l.Translations.Select(t => t.Key).ToList())
Expand All @@ -643,13 +650,17 @@ public void UselessModuleTranslationKeysTest()

var notCommonKeys = module.AppliedJsTranslationKeys
.Where(k => !k.StartsWith("Common:"))
.OrderBy(t => t)
.ToList();

var onlyCommonKeys = module.AppliedJsTranslationKeys
.Except(notCommonKeys)
.Select(k => k.Replace("Common:", ""))
.OrderBy(t => t)
.ToList();

notCommonKeys = notCommonKeys.Select(k => k.Substring(k.IndexOf(":") + 1)).ToList();

if (onlyCommonKeys.Any())
{
foreach (var lng in CommonTranslations)
Expand All @@ -661,7 +672,7 @@ public void UselessModuleTranslationKeysTest()
if (!list.Any())
continue;

message += $"{i}. '{lng.Language}' '{module.Path}' \r\n {string.Join("\r\n", list)} \r\n";
message += $"{++index}. '{lng.Language}' '{module.Path}' \r\n {string.Join("\r\n", list)} \r\n";

notFoundi18nKeys.Add(new KeyValuePair<string, List<string>>(lng.Language, list));
}
Expand All @@ -671,7 +682,7 @@ public void UselessModuleTranslationKeysTest()
{
if (notCommonKeys.Any())
{
message += $"{i}. 'ANY LANGUAGES' '{module.Path}' \r\n {string.Join("\r\n", notCommonKeys)} \r\n";
message += $"{++index}. 'ANY LANGUAGES' '{module.Path}' \r\n {string.Join("\r\n", notCommonKeys)} \r\n";

notFoundi18nKeys.Add(new KeyValuePair<string, List<string>>("ANY LANGUAGES", notCommonKeys));
}
Expand All @@ -683,13 +694,13 @@ public void UselessModuleTranslationKeysTest()
{
var list = lng.Translations
.Select(t => t.Key)
.Except(notCommonKeys.Select(k => k.Substring(k.IndexOf(":") + 1)))
.Except(notCommonKeys)
.ToList();

if (!list.Any())
continue;

message += $"{i}. '{lng.Language}' '{module.Path}' \r\n {string.Join("\r\n", list)} \r\n";
message += $"{++index}. '{lng.Language}' '{module.Path}' \r\n {string.Join("\r\n", list)} \r\n";

notFoundi18nKeys.Add(new KeyValuePair<string, List<string>>(lng.Language, list));
}
Expand Down

0 comments on commit 7e919c9

Please sign in to comment.