-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fce64f4
commit 042d104
Showing
3 changed files
with
455 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package segments | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/jandedobbeleer/oh-my-posh/src/mock" | ||
|
||
"github.com/stretchr/testify/assert" | ||
mock2 "github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestUmbracoSegment(t *testing.T) { | ||
cases := []struct { | ||
Case string | ||
ExpectedEnabled bool | ||
ExpectedString string | ||
Template string | ||
HasUmbracoFolder bool | ||
HasCsproj bool | ||
HasWebConfig bool | ||
}{ | ||
{ | ||
Case: "No Umbraco folder found", | ||
HasUmbracoFolder: false, | ||
ExpectedEnabled: false, // Segment should not be enabled | ||
}, | ||
{ | ||
Case: "Umbraco Folder but NO web.config or .csproj", | ||
HasUmbracoFolder: true, | ||
HasCsproj: false, | ||
HasWebConfig: false, | ||
ExpectedEnabled: false, // Segment should not be enabled | ||
}, | ||
{ | ||
Case: "Umbraco Folder and web.config but NO .csproj", | ||
HasUmbracoFolder: true, | ||
HasCsproj: false, | ||
HasWebConfig: true, | ||
ExpectedEnabled: true, // Segment should be enabled and visible | ||
ExpectedString: "8.15.0", // We are using the default template (by not specifying one) and expect just the version to be displayed | ||
}, | ||
{ | ||
Case: "Umbraco Folder and .csproj but NO web.config", | ||
HasUmbracoFolder: true, | ||
HasCsproj: true, | ||
HasWebConfig: false, | ||
ExpectedEnabled: true, // Segment should be enabled and visible | ||
ExpectedString: "12.1.2", // We are using the default template (by not specifying one) and expect just the version to be displayed | ||
}, | ||
{ | ||
Case: "Umbraco Folder and .csproj with custom template", | ||
ExpectedEnabled: true, | ||
Template: "Version:{{ .Version }} ModernUmbraco:{{ .IsModernUmbraco }} LegacyUmbraco:{{ .IsLegacyUmbraco }}", | ||
ExpectedString: "Version:12.1.2 ModernUmbraco:true LegacyUmbraco:false", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
// Prepare/arrange the test | ||
env := new(mock.MockedEnvironment) | ||
var sampleCSProj, sampleWebConfig string | ||
|
||
if tc.HasCsproj { | ||
content, _ := os.ReadFile("../test/umbraco/MyProject.csproj") | ||
sampleCSProj = string(content) | ||
} | ||
if tc.HasWebConfig { | ||
content, _ := os.ReadFile("../test/umbraco/web.config") | ||
sampleWebConfig = string(content) | ||
} | ||
|
||
const umbracoProjectDirectory = "/workspace/MyProject" | ||
env.On("Pwd").Return(umbracoProjectDirectory) | ||
env.On("FileContent", filepath.Join(umbracoProjectDirectory, "MyProject.csproj")).Return(sampleCSProj) | ||
env.On("FileContent", filepath.Join(umbracoProjectDirectory, "web.config")).Return(sampleWebConfig) | ||
env.On("Debug", mock2.Anything) | ||
env.On("Trace", mock2.Anything, mock2.Anything) | ||
|
||
// TODO: HOW do I mock the folder/file structure so that Umbraco segmenet can test looping through parent folders | ||
// ******* Any help or pointers please Jan ******* | ||
|
||
// Setup the Umbraco segment with the mocked environment & properties | ||
umb := &Umbraco{ | ||
env: env, | ||
} | ||
|
||
// Assert the test results | ||
// Check if the segment should be enabled and | ||
// the rendered string matches what we expect when specifying a template for the segment | ||
assert.Equal(t, tc.ExpectedEnabled, umb.Enabled(), tc.Case) | ||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, umb), tc.Case) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="uMarketingSuite" Version="1.23.0" /> | ||
<PackageReference Include="Umbraco.TheStarterKit" Version="11.0.0" /> | ||
<PackageReference Include="Umbraco.Cms" Version="12.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- Opt-in to app-local ICU to ensure consistent globalization APIs across different platforms --> | ||
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9"/> | ||
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.9" Condition="$(RuntimeIdentifier.StartsWith('linux')) or $(RuntimeIdentifier.StartsWith('win')) or ('$(RuntimeIdentifier)' == '' and !$([MSBuild]::IsOSPlatform('osx')))"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\uMarketingSuite.StarterKit\uMarketingSuite.StarterKit.csproj" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<!-- Razor files are needed for the backoffice to work correctly --> | ||
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto --> | ||
<RazorCompileOnBuild>false</RazorCompileOnBuild> | ||
<RazorCompileOnPublish>false</RazorCompileOnPublish> | ||
</PropertyGroup> | ||
|
||
</Project> |
Oops, something went wrong.