public void PrepareElementsOnPage_FromShell_MakesVernacularAndNationalEmpty() { var contents = @"<div class='bloom-page numberedPage A5Portrait bloom-monolingual' id='f4a22289-1755-4b79-afc1-5d20eaa892fe'> <div class='marginBox'> <div class='bloom-imageContainer'> <img alt='' src='test.png' height='20' width='20'/> </div> <div class='bloom-translationGroup normal-style'> <div style='' class='bloom-editable' contenteditable='true' lang='en'>The Mother said, Nurse! The Nurse answered.</div> <div style='' class='bloom-editable' contenteditable='true' lang='tpi'>Mama i tok: Sista. Sista i tok: Bai mi stori long yu.</div> </div> </div></div>"; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 5); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='en' and contains(., 'The Mother')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='tpi' and contains(., 'Mama i tok')]", 1); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='xyz' and contains(., 'The Mother')]"); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='xyz' and contains(., 'Mama i tok')]"); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr' and contains(., 'The Mother')]"); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr' and contains(., 'Mama i tok')]"); }
public void ShouldNormallyShowEditable_SituationsWhereNationalLanguagesShouldBeShown() { var bookData = new BookData(new HtmlDom("<html><body></body></html>"), _collectionSettings, null); bookData.SetMultilingualContentLanguages("xyz", "fr", "es"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "V", "N1" }, "", "", bookData), "The data-default-languages calls for the vernacular and n1"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N1" }, "", "", bookData), "The data-default-languages calls for the n1; it should show."); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N1", "N2" }, "", "", bookData), "The data-default-languages calls for both national languages"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "N1", "N2" }, "", "", bookData), "The data-default-languages calls for both national languages"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "auto" }, "fr", "es", bookData), "Auto and Trilingual, so should show all three languages."); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "auto" }, "fr", "es", bookData), "Auto and Trilingual, so should show all three languages."); bookData.SetMultilingualContentLanguages("xyz"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N1" }, "", "", bookData), "The data-default-languages calls for the N1; it should show, even when not in the auto list."); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "N1" }, "", "", bookData), "The data-default-languages calls for the N1; it should show, even when not in the auto list."); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N2" }, "", "", bookData), "The data-default-languages calls for the N1; it should show, even when not in the auto list."); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "N2" }, "", "", bookData), "The data-default-languages calls for the N1; it should show, even when not in the auto list."); }
public void UpdateContentLanguageClasses_PrototypeHasUnderlinedText_CopyHasNone() { var contents = @"<html><body><div class='bloom-page numberedPage A5Portrait bloom-monolingual' id='f4a22289-1755-4b79-afc1-5d20eaa892fe'> <div class='marginBox'> <div class='bloom-translationGroup normal-style'> <div style='' class='bloom-editable plain-style' contenteditable='true' lang='en'>The <i>Mother</i> said, <u>Nurse!</u> The Nurse <b>answered</b>.</div> </div></div></div></body></html>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], bookData); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'plain-style') and contains(@class, 'bloom-editable')]", 3); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'normal-style') and contains(@class, 'bloom-translationGroup')]", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='en' and contains(., 'The Mother')]", 1); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr']/u"); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr']/b"); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr']/i"); }
public void SortTranslationGroups_YieldsExpectedOrder() { var doc = new XmlDocument(); var input = new List <XmlElement>(); for (int i = 0; i < 7; i++) { var div = doc.CreateElement("div"); input.Add(div); div.SetAttribute("data-which", i.ToString()); } input[1].SetAttribute("tabindex", "4"); input[3].SetAttribute("tabindex", "2"); input[5].SetAttribute("tabindex", "3"); input[6].SetAttribute("tabindex", "1"); var output = TranslationGroupManager.SortTranslationGroups(input); // Bafflingly, this assert seems to work for any pair of items from the list. //Assert.That(output[0], Is.EqualTo(input[6])); Assert.That(output[0].Equals(input[6])); Assert.That(output[1].Equals(input[3])); Assert.That(output[2].Equals(input[5])); Assert.That(output[3].Equals(input[1])); Assert.That(output[4].Equals(input[0])); Assert.That(output[5].Equals(input[2])); Assert.That(output[6].Equals(input[4])); }
public void PrepareElementsInPageOrDocument_TransfersNormalStyleCorrectly() { var contents = @"<html><body><div class='bloom-page' > <div class='bloom-translationGroup normal-style'> <div class='bloom-editable plain-style' lang='xyz'></div> <div class='bloom-editable' lang='en'></div> <div class='bloom-editable' lang='fr'></div> <div class='bloom-editable fancy-style' lang='es'></div> <div lang='pt'>not editable</div> </div> </div></body></html>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], bookData); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'normal-style') and contains(@class, 'bloom-editable')]", 2); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'plain-style') and contains(@class, 'bloom-editable')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'fancy-style') and contains(@class, 'bloom-editable')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='bloom-translationGroup']/div", 5); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='bloom-translationGroup']/div[not(contains(@class, 'bloom-editable') or contains(@class, 'normal-style'))]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'normal-style') and contains(@class, 'bloom-translationGroup')]", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='bloom-translationGroup']", 1); }
public void PrepareElementsInPageOrDocument_HasGenerateTranslationsDiv_GeneratesTranslations() { var contents = @"<html><body><div class='bloom-page'> <div class='bloom-translationGroup'> <div class='bloom-editable' lang='en' data-generate-translations='true' data-i18n='Test.L10N.ID'>English Text</div> </div> </div></body></html>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-generate-translations]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-i18n]", 1); //SUT TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], bookData); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='bloom-translationGroup']", 1); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@data-generate-translations]"); AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@data-i18n]"); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='bloom-translationGroup']/div", 5); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable')]", 5); // We start with an English div AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @lang='en' and text()='English Text']", 1); // These three are included because they are languages of the collection. (We also have a translation for French.) AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @lang='fr' and not(text())]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @lang='xyz' and not(text())]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @lang='es' and text()='Spanish Text']", 1); // This one is included because we have a translation available AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @lang='zh-CN' and text()='Chinese Text']", 1); }
public void ShouldNormallyShowEditable_SituationsWhereVernacularShouldNotBeShown() { Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "N1" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the vernacular "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "N2" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the vernacular "); }
private void AdvanceToNextGroup() { _groupOnPageIndex++; // We arrange for this to be always true initially while (_groupOnPageIndex >= _groupsOnPage.Count) { _currentPageIndex++; if (_currentPageIndex >= _pages.Count) { _currentGroup = null; _currentPage = null; return; } _currentPage = _pages[_currentPageIndex]; if (HtmlDom.NumberOfPage(_currentPage) == "") { _groupsOnPage = new List <XmlElement>(0); // skip xmatter or similar page } else { _groupsOnPage = TranslationGroupManager.SortedGroupsOnPage(_currentPage); } _groupOnPageIndex = 0; } _currentGroup = _groupsOnPage[_groupOnPageIndex]; }
public void UpdateContentLanguageClasses_PrototypeElementHasImageContainer_ImageContainerCopiedToNewSibling() { const string contents = @"<div class='bloom-page'> <div class='bloom-translationGroup'> <div class='bloom-editable' lang='123'> Do not copy me. <br>Do not copy me.</br> <p>Do not copy me.</p> <div class='bloom-imageContainer'> <img src='foo.png'></img> <div contentEditable='true' class='caption'>Do not copy me</div> </div> Do not copy me. <p>Do not copy me.</p> <p class='foo bloom-cloneToOtherLanguages bar'>Do copy me.</p> </div> </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object); //the added french should have all the structure including a copy of the image container div, but none of the text except from the bloom-cloneToOtherLanguages paragraph AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']/div/img[@src='foo.png']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']/div/div[@contentEditable='true']", 1); //should clear out the caption text (using a raw contentEditable for the caption just becuase bloom-editables inside of bloom-editables is beyond my ambitions at the moment. AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']/div/div[contains(@class,'caption') and @contentEditable='true' and not(text())]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']/*[contains(text(),'Do not')]", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']//br", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']//p[not(contains(@class,'bloom-cloneToOtherLanguages'))]", 0); // get rid of all paragraphs, except for... AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']//p[contains(@class,'bloom-cloneToOtherLanguages')]", 1); // the one with "bloom-cloneToOtherLanguages" AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']/*[contains(text(),'Do copy me')]", 1); }
/// <summary> /// This is where all the excitement happens. We update the specified group /// with the data from the spreadsheet row. /// </summary> /// <param name="row"></param> /// <param name="group"></param> private void PutRowInGroup(ContentRow row, XmlElement group) { var sheetLanguages = _sheet.Languages; foreach (var lang in sheetLanguages) { var colIndex = _sheet.GetRequiredColumnForLang(lang); var content = row.GetCell(colIndex).Content; var editable = HtmlDom.GetEditableChildInLang(group, lang); if (editable == null) { if (IsEmptyCell(content)) { continue; // Review: or make an empty one? } editable = TranslationGroupManager.MakeElementWithLanguageForOneGroup(group, lang); } if (IsEmptyCell(content)) { editable.ParentNode.RemoveChild(editable); } else { editable.InnerXml = content; } } if (RemoveOtherLanguages) { HtmlDom.RemoveOtherLanguages(@group, sheetLanguages); } }
public void ShouldNormallyShowEditable_SituationsWhereNumberedLanguagesShouldBeShown() { Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "L1" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the L1"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "L2" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the L2."); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "L3" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the L3."); }
public void ShouldNormallyShowEditable_SituationsWhereVernacularShouldNotBeShown() { var bookData = new BookData(new HtmlDom("<html><body></body></html>"), _collectionSettings, null); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "N1" }, "", "", bookData), "The data-default-languages calls for the vernacular "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "N2" }, "", "", bookData), "The data-default-languages calls for the vernacular "); }
public void ShouldNormallyShowEditable_SituationsWhereFirstNationalLanguageShouldNotBeShown() { Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "V" }, "fr", "", _collectionSettings.Object), "The data-default-languages calls only for the vernacular "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "V" }, "fr", "", _collectionSettings.Object), "The data-default-languages calls only for the vernacular "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N2" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the second national language only "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "auto" }, "es", "", _collectionSettings.Object), "Bilingual, the second language is set to the second national language."); }
private void GetElementsFromCurrentPage() { _imageContainersOnPage = GetImageContainers(_currentPage); // For now we are ignoring image description slots as possible destinations for text. // It's difficult to know whether a page intentionally has one or not, as empty ones // can easily be added by just turning on the tool, and they can confuse alignment // of images and main text blocks. var allGroups = TranslationGroupManager.SortedGroupsOnPage(_currentPage, true); _groupsOnPage = allGroups.Where(x => !x.Attributes["class"].Value.Contains("bloom-imageDescription")).ToList(); }
public void ShouldNormallyShowEditable_SituationsWhereFirstNationalLanguageShouldNotBeShown() { var bookData = new BookData(new HtmlDom("<html><body></body></html>"), _collectionSettings, null); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "V" }, "fr", "", bookData), "The data-default-languages calls only for the vernacular "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "V" }, "fr", "", bookData), "The data-default-languages calls only for the vernacular "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N2" }, "", "", bookData), "The data-default-languages calls for the second national language only "); Assert.IsFalse(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "auto" }, "es", "", bookData), "Bilingual, the second language is set to the second national language."); }
public void PrepareElementsOnPage_HasLabelElementInsideTranslationGroup_LeavesUntouched() { var contents = @"<div class='bloom-page bloom-translationGroup'> <label class='bloom-bubble'>something helpful</label> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//label[@class='bloom-bubble']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//label[@class='bloom-bubble' and text()='something helpful']", 1); }
public void PrepareElementsOnPage_HasEmptyTranslationGroup_MakesVernacularAndNational() { var contents = @"<div class='bloom-page bloom-translationGroup'> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 3); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 1); }
public void ShouldNormallyShowEditable_SituationsWhereNationalLanguagesShouldBeShown() { Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "V", "N1" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the vernacular and n1"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N1" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the n1; it should show."); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "N1", "N2" }, "", "", _collectionSettings.Object), "The data-default-languages calls for both national languages"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "N1", "N2" }, "", "", _collectionSettings.Object), "The data-default-languages calls for both national languages"); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("fr", new[] { "auto" }, "fr", "es", _collectionSettings.Object), "Auto and Trilingual, so should show all three languages."); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("es", new[] { "auto" }, "fr", "es", _collectionSettings.Object), "Auto and Trilingual, so should show all three languages."); }
public void UpdateContentLanguageClasses_TrilingualBook_AddsBloomTrilingualClassToTranslationGroup() { var contents = @"<div class='bloom-page bloom-bilingual'> <div class='bloom-translationGroup'> <textarea lang='en'></textarea> </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0]; TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, _collectionSettings.Object, "xyz", "222", "333"); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'bloom-bilingual')]", 0); //should remove that one AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'bloom-trilingual')]", 1); }
public void ShouldNormallyShowEditable_SituationsWhereVernacularShouldBeShown() { Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "V" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "N1", "V" }, "", "", _collectionSettings.Object), "The data-default-languages calls for the vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new string[] {}, "", "", _collectionSettings.Object), "The data-default-languages is empty, so should default to 'auto', which always includes vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "" }, "", "", _collectionSettings.Object), "The data-default-languages is empty, so should default to 'auto', which always includes vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "auto" }, "", "", _collectionSettings.Object), "The data-default-languages is auto, which always includes vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "AUTO" }, "", "", _collectionSettings.Object), "The data-default-languages is AUTO, which always includes vernacular "); }
public void PrepareElementsOnPage_HasTextAreaInsideTranslationGroup_MakesVernacularAndNational() { var contents = @"<div class='bloom-page bloom-translationGroup'> <textarea lang='en'>This is some English</textarea> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea", 4); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='en']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='fr']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='es']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='xyz']", 1); }
public void UpdateContentLanguageClasses_TranslationGroupHasPlaceHolder_PlaceholderCopiedToNewChildren() { var contents = @"<div class='bloom-page bloom-trilingual'> <div class='bloom-translationGroup' data-placeholder='copy me' > </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 3); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz' and @data-placeholder='copy me']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr' and @data-placeholder='copy me']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es' and @data-placeholder='copy me']", 1); }
public void UpdateContentLanguageClasses_MonoLingualBook_AddsBloomMonolingualClassToTranslationGroup() { var contents = @"<html><body><div class='bloom-page bloom-bilingual'> <div class='bloom-translationGroup'> <textarea lang='en'></textarea> </div> </div></body></html>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null); var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0]; TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, bookData, "xyz", null, null); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'bloom-bilingual')]", 0); //should remove that one AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'bloom-monolingual')]", 1); }
public void UpdateContentLanguageClasses_NewPage_AddsContentLanguageClasses() { var contents = @"<div class='bloom-page'> <div class='bloom-translationGroup'> <textarea lang='en'></textarea> <textarea lang='222'></textarea> <textarea lang='333'></textarea> </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[@class='bloom-page']")[0]; TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, "xyz", _collectionSettings.Object.Language2Iso639Code, _collectionSettings.Object.Language3Iso639Code, "222", "333"); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='222' and contains(@class, 'bloom-content2')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'bloom-content3')]", 1); }
public void PrepareElementsOnPage_HasNonEditableDiv_LeavesAlone() { var contents = @"<div class='bloom-page'> <table class='bloom-translationGroup'> <!-- table is used for vertical alignment of the div on some pages --> <td> <div lang='en'>This is some English</div> </td> </table> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[@class='bloom-page']")[0], _collectionSettings.Object); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//td/div", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//td/div[@lang='en']", 1); }
public void UpdateContentLanguageClasses_FrontMatterPage_AddsNationalLanguageClasses() { var contents = @"<div class='bloom-page bloom-frontMatter'> <div class='bloom-translationGroup'> <textarea lang='en'></textarea> <textarea lang='fr'></textarea> <textarea lang='es'></textarea> </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0]; TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, _collectionSettings.Object, "xyz", "222", "333"); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='fr' and contains(@class, 'bloom-contentNational1')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='es' and contains(@class, 'bloom-contentNational2')]", 1); }
public void PrepareElementsOnPage_HasEmptyTranslationGroup_MakesVernacularAndNational() { var contents = @"<html><body><div class='bloom-page bloom-translationGroup normal-style'> </div></body></html>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null); TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], bookData); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 2); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'normal-style') and contains(@class, 'bloom-editable')]", 2); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'normal-style') and contains(@class, 'bloom-translationGroup')]", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 0); }
public void ShouldNormallyShowEditable_SituationsWhereVernacularShouldBeShown() { var bookData = new BookData(new HtmlDom("<html><body></body></html>"), _collectionSettings, null); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "V" }, "", "", bookData), "The data-default-languages calls for the vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "N1", "V" }, "", "", bookData), "The data-default-languages calls for the vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new string[] {}, "", "", bookData), "The data-default-languages is empty, so should default to 'auto', which always includes vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "" }, "", "", bookData), "The data-default-languages is empty, so should default to 'auto', which always includes vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "auto" }, "", "", bookData), "The data-default-languages is auto, which always includes vernacular "); Assert.IsTrue(TranslationGroupManager.ShouldNormallyShowEditable("xyz", new[] { "AUTO" }, "", "", bookData), "The data-default-languages is AUTO, which always includes vernacular "); }
public void UpdateContentLanguageClasses_Typical_MetadataPage_TurnsOnCorrectLanguages() { var contents = @"<div class='bloom-page' > <div class='bloom-translationGroup' data-default-languages='N1,N2'> <div class='bloom-editable' lang='xyz'></div> <div class='bloom-editable' lang='fr'></div> <div class='bloom-editable' lang='es'></div> </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0]; TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, _collectionSettings.Object, "xyz", "222", "333"); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'bloom-visibility-code-on')]", 2); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr' and contains(@class, 'bloom-visibility-code-on')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es' and contains(@class, 'bloom-visibility-code-on')]", 1); }
public void UpdateContentLanguageClasses_ExistingPageWith3rdLangRemoved_RemovesContentLanguageClassButLeavesOtherClasses() { var contents = @"<div class='bloom-page'> <div class='bloom-translationGroup'> <textarea lang='en'></textarea> <textarea class='bloom-content2' lang='222'></textarea> <textarea class='foo bloom-content3 bar' lang='333'></textarea> </div> </div>" ; var dom = new XmlDocument(); dom.LoadXml(contents); var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0]; TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, _collectionSettings.Object, "xyz", "222", null); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='222' and contains(@class, 'bloom-content2')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'bloom-content3')]", 0); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'foo')]", 1); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'bar')]", 1); }