Skip to content

Commit 3eb7164

Browse files
add link detection to disclaimer test
1 parent bc68564 commit 3eb7164

File tree

5 files changed

+132
-3
lines changed

5 files changed

+132
-3
lines changed

JitsiMeetOutlook/AppointmentRibbonGroup.controls.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text;
77
using JitsiMeetOutlook.Entities;
88
using Microsoft.Office.Interop.Word;
9+
using System.Collections.Generic;
910

1011
namespace JitsiMeetOutlook
1112
{
@@ -167,7 +168,22 @@ public async System.Threading.Tasks.Task appendNewMeetingText()
167168
endSel.InsertAfter("\n");
168169
endSel.MoveDown(Word.WdUnits.wdLine);
169170

170-
endSel.InsertAfter(Globals.ThisAddIn.getElementTranslation("appointmentItem", "textBodyDisclaimer"));
171+
IEnumerable<KeyValuePair<bool, string>> disclaimer = Utils.SplitToTextAndHyperlinks(Globals.ThisAddIn.getElementTranslation("appointmentItem", "textBodyDisclaimer"));
172+
foreach (var textblock in disclaimer)
173+
{
174+
if (textblock.Key)
175+
{
176+
// Textblock is a link
177+
wordDocument.Hyperlinks.Add(endSel.Range, "tel:" + textblock.Value, ref missing, ref missing, textblock.Value, ref missing);
178+
endSel.EndKey(Word.WdUnits.wdLine);
179+
}
180+
else
181+
{
182+
// Textblock is no link
183+
endSel.InsertAfter(textblock.Value);
184+
endSel.EndKey(Word.WdUnits.wdLine);
185+
}
186+
}
171187
endSel.EndKey(Word.WdUnits.wdLine);
172188
endSel.InsertAfter("\n");
173189
endSel.MoveDown(Word.WdUnits.wdLine);

JitsiMeetOutlook/Utils.cs

+25
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,30 @@ public static void RunInThread(Action function)
6161
MessageBox.Show("An Error occured within JitsiOutlook: " + ex.Message);
6262
}
6363
}
64+
65+
public static List<KeyValuePair<bool, string>> SplitToTextAndHyperlinks(string text)
66+
{
67+
var list = new List<KeyValuePair<bool, string>>();
68+
MatchCollection matches = Regex.Matches(text, "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+");
69+
if (matches.Count == 0)
70+
{
71+
list.Add(new KeyValuePair<bool, string>(false, text));
72+
}
73+
var lastindex = 0;
74+
var index = 0;
75+
foreach (Match match in matches)
76+
{
77+
list.Add(new KeyValuePair<bool, string>(false, text.Substring(lastindex, match.Index - lastindex)));
78+
list.Add(new KeyValuePair<bool, string>(true, match.Value));
79+
lastindex = match.Index + match.Length;
80+
if (index == matches.Count - 1)
81+
{
82+
list.Add(new KeyValuePair<bool, string>(false, text.Substring(lastindex, text.Length - lastindex)));
83+
}
84+
index++;
85+
}
86+
87+
return list;
88+
}
6489
}
6590
}

JitsiMeetOutlookTests/JitsiMeetOutlookTests.csproj

+49
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<WarningLevel>4</WarningLevel>
3939
</PropertyGroup>
4040
<ItemGroup>
41+
<Reference Include="FluentAssertions, Version=6.7.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
42+
<HintPath>..\packages\FluentAssertions.6.7.0\lib\net47\FluentAssertions.dll</HintPath>
43+
</Reference>
4144
<Reference Include="Microsoft.Office.Tools.Common.v4.0.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
4245
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
4346
<HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
@@ -46,6 +49,52 @@
4649
<HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
4750
</Reference>
4851
<Reference Include="System" />
52+
<Reference Include="System.ComponentModel.Composition" />
53+
<Reference Include="System.Configuration" />
54+
<Reference Include="System.Data" />
55+
<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
56+
<HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
57+
<Private>True</Private>
58+
<Private>True</Private>
59+
</Reference>
60+
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
61+
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
62+
<Private>True</Private>
63+
<Private>True</Private>
64+
</Reference>
65+
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
66+
<HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
67+
<Private>True</Private>
68+
<Private>True</Private>
69+
</Reference>
70+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
71+
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
72+
</Reference>
73+
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
74+
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
75+
<Private>True</Private>
76+
<Private>True</Private>
77+
</Reference>
78+
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
79+
<HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
80+
<Private>True</Private>
81+
<Private>True</Private>
82+
</Reference>
83+
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
84+
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
85+
<Private>True</Private>
86+
<Private>True</Private>
87+
</Reference>
88+
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
89+
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
90+
<Private>True</Private>
91+
<Private>True</Private>
92+
</Reference>
93+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
94+
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
95+
</Reference>
96+
<Reference Include="System.Xml" />
97+
<Reference Include="System.Xml.Linq" />
4998
</ItemGroup>
5099
<Choose>
51100
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">

JitsiMeetOutlookTests/TextUtilsTests.cs

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using FluentAssertions;
89

910
namespace JitsiMeetOutlook.Tests
1011
{
@@ -57,9 +58,37 @@ public void GetUrlTest2()
5758
}
5859

5960
[TestMethod()]
60-
public void SettingIsActiveTest()
61+
public void SplitToTextAndHyperlinks()
6162
{
62-
Assert.Fail();
63+
var text = "test https://meet.jit.si/UnderlyingDescentsPledgeOverseas with links https://cool.link everywhere https://example.com interesting end";
64+
List<KeyValuePair<bool, string>> split = Utils.SplitToTextAndHyperlinks(text);
65+
split.Should().NotBeEmpty().And.HaveCount(7);
66+
67+
split.Should().Equal(new List<KeyValuePair<bool, string>>()
68+
{
69+
new KeyValuePair<bool, string>( false, "test " ),
70+
new KeyValuePair<bool, string>( true, "https://meet.jit.si/UnderlyingDescentsPledgeOverseas" ),
71+
new KeyValuePair<bool, string>( false, " with links " ),
72+
new KeyValuePair<bool, string>( true, "https://cool.link" ),
73+
new KeyValuePair<bool, string>( false, " everywhere " ),
74+
new KeyValuePair<bool, string>( true, "https://example.com" ),
75+
new KeyValuePair<bool, string>( false, " interesting end" )
76+
77+
});
78+
79+
}
80+
81+
[TestMethod()]
82+
public void SplitToTextAndHyperlinksEmpty()
83+
{
84+
var text = "test with no links everywhere interesting end";
85+
List<KeyValuePair<bool, string>> split = Utils.SplitToTextAndHyperlinks(text);
86+
split.Should().Equal(new List<KeyValuePair<bool, string>>()
87+
{
88+
new KeyValuePair<bool, string>( false, "test with no links everywhere interesting end")
89+
90+
});
91+
6392
}
6493
}
6594
}

JitsiMeetOutlookTests/packages.config

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="FluentAssertions" version="6.7.0" targetFramework="net472" />
34
<package id="MSTest.TestAdapter" version="2.2.7" targetFramework="net472" />
45
<package id="MSTest.TestFramework" version="2.2.7" targetFramework="net472" />
6+
<package id="System.IO" version="4.3.0" targetFramework="net472" />
7+
<package id="System.Net.Http" version="4.3.4" targetFramework="net472" />
8+
<package id="System.Runtime" version="4.3.0" targetFramework="net472" />
9+
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net472" />
10+
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net472" />
11+
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net472" />
12+
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net472" />
13+
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net472" />
14+
<package id="System.Threading.Tasks.Extensions" version="4.5.0" targetFramework="net472" />
515
</packages>

0 commit comments

Comments
 (0)