Skip to content

Commit

Permalink
handled code rabbit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRanjeetSingh committed Oct 28, 2024
1 parent eb19a0f commit 656a1df
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 141 deletions.
29 changes: 18 additions & 11 deletions Ginger/Ginger/External/Katalon/KatalonConvertedPOMViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.Repository;
using GingerCoreNET.SolutionRepositoryLib.RepositoryObjectsLib.PlatformsLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -29,7 +30,7 @@ public string Name
get => _name;
set
{
_name = value;
_name = value ?? string.Empty;
PropertyChanged?.Invoke(sender: this, new(nameof(Name)));
}
}
Expand All @@ -39,7 +40,7 @@ public string URL
get => _url;
set
{
_url = value;
_url = value ?? string.Empty;
PropertyChanged?.Invoke(sender: this, new(nameof(URL)));
}
}
Expand All @@ -49,7 +50,7 @@ public string TargetApplication
get => _targetApplication;
set
{
_targetApplication = value;
_targetApplication = value ?? string.Empty;
PropertyChanged?.Invoke(sender: this, new(nameof(TargetApplication)));
}
}
Expand All @@ -62,6 +63,8 @@ public string TargetApplication

public KatalonConvertedPOMViewModel(ApplicationPOMModel pom, ePlatformType platform)
{
ArgumentNullException.ThrowIfNull(pom);

POM = pom;
_active = true;
_name = POM.Name;
Expand All @@ -73,23 +76,27 @@ public KatalonConvertedPOMViewModel(ApplicationPOMModel pom, ePlatformType platf
.Solution
.GetSolutionTargetApplications()
.Where(ta => GetApplicationPlatform(ta.Name) == platform)
.Select(ta => ta.Name);
.Select(ta => ta.Name)
.ToList();
}

private ePlatformType GetApplicationPlatform(string application)
{
return
WorkSpace
.Instance
.Solution
.GetApplicationPlatformForTargetApp(application);
ArgumentException.ThrowIfNullOrEmpty(application);

if (WorkSpace.Instance?.Solution == null)
{
throw new InvalidOperationException("Workspace or Solution is not initialized");
}

return WorkSpace.Instance.Solution.GetApplicationPlatformForTargetApp(application);
}

public void CommitChanges()
{
if (URL != null && !string.Equals(URL.Trim(), string.Empty))
if (!string.IsNullOrWhiteSpace(URL))
{
POM.PageURL = URL;
POM.PageURL = URL.Trim();
}

ApplicationPlatform? appPlatform = WorkSpace.Instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
Background="{StaticResource $BackgroundColor_White}">
<Grid.RowDefinitions>
<RowDefinition
Height="auto" />
Height="auto"
MinHeight="30"/>
<RowDefinition
Height="auto" />
Height="auto"
MinHeight="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Expand All @@ -24,19 +26,21 @@
</Grid.ColumnDefinitions>
<Label
Style="{StaticResource @InputFieldLabelStyle}"
Content="Select Katalon Object-Repositoy Folder" />
Content="Select Katalon Object-Repository Folder" />
<TextBox
x:Name="DirectoryTextBox"
Grid.Row="1"
Grid.Column="0"
Style="{StaticResource $TextBoxStyle}"/>
Style="{StaticResource $TextBoxStyle}"
ToolTip="Enter or browse for the Katalon Object Repository folder location" />
<Button
x:Name="DirectoryBrowseButton"
Grid.Row="1"
Grid.Column="1"
Content="Browse"
VerticalAlignment="Center"
Style="{StaticResource $InputButtonStyle}"
Click="DirectoryBrowseButton_Click" />
Click="DirectoryBrowseButton_Click"
ToolTip="Click to browse and select the Katalon Object Repository folder" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Amdocs.Ginger.Common;
using GingerCore.GeneralLib;
using GingerWPF.WizardLib;
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -16,6 +17,11 @@ public partial class SelectObjectRepositoryFolderWizardPage : Page, IWizardPage

public SelectObjectRepositoryFolderWizardPage(ImportKatalonObjectRepositoryWizard wizard)
{
if (wizard == null)
{
throw new ArgumentNullException(nameof(wizard));
}

InitializeComponent();

_wizard = wizard;
Expand All @@ -27,16 +33,16 @@ public void WizardEvent(WizardEventArgs e)
switch (e.EventType)

Check failure on line 33 in Ginger/Ginger/External/Katalon/SelectObjectRepositoryFolderWizardPage.xaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/External/Katalon/SelectObjectRepositoryFolderWizardPage.xaml.cs#L33

Add a 'default' clause to this 'switch' statement.

Check notice on line 33 in Ginger/Ginger/External/Katalon/SelectObjectRepositoryFolderWizardPage.xaml.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/Ginger/External/Katalon/SelectObjectRepositoryFolderWizardPage.xaml.cs#L33

Replace this 'switch' statement with 'if' statements to increase readability.
{
case EventType.LeavingForNextPage:
if (_wizard.SelectedDirectory == null || string.Equals(_wizard.SelectedDirectory.Trim(), string.Empty))
if (string.IsNullOrWhiteSpace(_wizard.SelectedDirectory))
{
e.CancelEvent = true;
Reporter.ToUser(eUserMsgKey.InvalidKatalonObjectRepository, "Folder path is empty");
Reporter.ToUser(eUserMsgKey.InvalidKatalonObjectRepository, "Please select a folder containing Katalon Object Repository files.");
break;
}
if (!Directory.Exists(_wizard.SelectedDirectory))
if (!Directory.Exists(_wizard.SelectedDirectory.Trim()))
{
e.CancelEvent = true;
Reporter.ToUser(eUserMsgKey.InvalidKatalonObjectRepository, "Folder doesn't exist");
Reporter.ToUser(eUserMsgKey.InvalidKatalonObjectRepository, $"The selected folder does not exist.");
break;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,37 @@ namespace Amdocs.Ginger.CoreNET.External.Katalon.Conversion
{
internal static class KatalonElementToElementInfoConverter
{
/// <summary>
/// Converts a collection of Katalon elements to Ginger ElementInfo objects.
/// </summary>
/// <param name="katalonElementList">The list of Katalon elements to convert.</param>
/// <returns>A collection of converted ElementInfo objects.</returns>
/// <exception cref="System.ArgumentNullException">Thrown when katalonElementList is null.</exception>
internal static IEnumerable<ElementInfo> Convert(IEnumerable<KatalonElementEntity> katalonElementList)
{
if (katalonElementList == null)
{
throw new System.ArgumentNullException(nameof(katalonElementList));
}

if (!katalonElementList.Any())
{
return Enumerable.Empty<ElementInfo>();
}

List<ElementInfo> elementInfoList = [];

var katalonWebElementList = katalonElementList
.OfType<KatalonWebElementEntity>()
.ToList();

foreach (KatalonElementEntity katalonElement in katalonElementList)
{
IEnumerable<KatalonWebElementEntity> katalonWebElementList = katalonElementList
.Where(e => e is KatalonWebElementEntity)
.Cast<KatalonWebElementEntity>();

if (katalonElement is KatalonWebElementEntity katalonWebElement)
{
elementInfoList.Add(katalonWebElement.ToElementInfo(katalonWebElementList));
}
}

return elementInfoList;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ internal static bool HasPOMWithName(string name)
}

/// <summary>
/// Get all the Rust files (.rs) in <paramref name="directory"/>.
/// Get all the Rust Source files (.rs) in <paramref name="directory"/>.
/// </summary>
/// <returns>Collection of paths of all the Rust files (.rs).</returns>
private static IEnumerable<string> GetKatalonObjectFilesInDirectory(string directory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private IEnumerable<ElementLocator> GetLocators()
locators.Add(new()
{
Active = true,
LocateBy = eLocateBy.ByID,
LocateBy = eLocateBy.ByName,
LocateValue = nameProperty.Value,
IsAutoLearned = true, //static
});
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="External\Katalon\Conversion\" />
<Folder Include="TestResources\Conversion\" />
<Folder Include="TestResources\Solutions\EmailWebReport\HTMLReportConfigurations\HTMLReportTemplate\" />
<Folder Include="TestResources\Solutions\EmailWebReport\HTMLReportConfigurations\ReportTemplates\" />
Expand Down

0 comments on commit 656a1df

Please sign in to comment.