Skip to content

Commit

Permalink
Merge pull request #91 from yagizhanNY/Refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
emncnozge committed Sep 30, 2024
2 parents c182a10 + c6332c1 commit ac8df65
Show file tree
Hide file tree
Showing 169 changed files with 622 additions and 1,779 deletions.
10 changes: 10 additions & 0 deletions .github/build-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Navigate to the SiemensIXBlazor_NpmJS directory
cd SiemensIXBlazor/SiemensIXBlazor_NpmJS

# Run npm install
npm install

# Run npm build
npm run build
35 changes: 19 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ name: .NET Build

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

env:
PROJECT_PATH: "SiemensIXBlazor/SiemensIXBlazor.csproj"
PROJECT_PATH: "SiemensIXBlazor/SiemensIXBlazor.csproj"

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Build
run: dotnet build --no-restore ${{ env.PROJECT_PATH }} --configuration Release
- name: Test with the dotnet CLI
run: dotnet test
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Make build-npm.sh executable
run: chmod +x .github/build-npm.sh
- name: Run build-npm.sh
run: .github/build-npm.sh
- name: Build
run: dotnet build --no-restore ${{ env.PROJECT_PATH }} --configuration Release
- name: Test with the dotnet CLI
run: dotnet test
57 changes: 31 additions & 26 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,50 @@ name: Publish
on:
push:
tags:
- '*'
- "*"
pull_request:
tags:
- '*'
- "*"

env:
PROJECT_PATH: "SiemensIXBlazor/SiemensIXBlazor.csproj"
PACKAGE_OUTPUT_DIRECTORY: ${{ github.workspace }}/output
NUGET_SOURCE_URL: 'https://api.nuget.org/v3/index.json'
PROJECT_PATH: "SiemensIXBlazor/SiemensIXBlazor.csproj"
PACKAGE_OUTPUT_DIRECTORY: ${{ github.workspace }}/output
NUGET_SOURCE_URL: "https://api.nuget.org/v3/index.json"

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Setup Dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Restore Dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}

- name: Make build-npm.sh executable
run: chmod +x .github/build-npm.sh

- name: Setup Dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Run build-npm.sh
run: .github/build-npm.sh

- name: Restore Dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Build Project
run: dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release

- name: Build Project
run: dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release
- name: Test with the dotnet CLI
run: dotnet test

- name: Test with the dotnet CLI
run: dotnet test
- name: "Get Version"
id: version
uses: battila7/get-version-action@v2

- name: 'Get Version'
id: version
uses: battila7/get-version-action@v2
- name: "Pack Project"
run: dotnet pack ${{ env.PROJECT_PATH }} --no-restore --no-build --configuration Release -p:PackageVersion=${{ steps.version.outputs.version-without-v }} --output ${{ env.PACKAGE_OUTPUT_DIRECTORY }}

- name: 'Pack Project'
run: dotnet pack ${{ env.PROJECT_PATH }} --no-restore --no-build --configuration Release -p:PackageVersion=${{ steps.version.outputs.version-without-v }} --output ${{ env.PACKAGE_OUTPUT_DIRECTORY }}

- name: 'Push Package'
run: dotnet nuget push ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s ${{ env.NUGET_SOURCE_URL }} --skip-duplicate --no-symbols
- name: "Push Package"
run: dotnet nuget push ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s ${{ env.NUGET_SOURCE_URL }} --skip-duplicate --no-symbols
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ Add required `CSS` and `Javascript` packages into the `index.html` file.
</html>
```

> [!CAUTION]
> If you want to use this library with a `Blazor Web App`, you need to set the `render mode` to `InteractiveServer`.
> You can find more information at [here](https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0).
### Theme Switching

**Since v0.3.9**

Add `Theme` component to the page that you want to manipulate the theme.
Expand Down Expand Up @@ -163,6 +168,7 @@ public partial class Index
- [Workflow](#workflow)

## Application

```razor
<Application @ref="_app">
<ApplicationHeader Name="My Application">
Expand Down Expand Up @@ -365,15 +371,21 @@ Add necessary css files into the `index.html` file.

```html
<!-- Include the core CSS, this is needed by the grid -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-grid.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-grid.css"
/>

<!-- Include the theme CSS, only need to import the theme you are going to use -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-theme-alpine.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-theme-alpine.css"
/>

<link rel="stylesheet"
href="_content/Siemens.IX.Blazor/css/siemens-ix/ix-aggrid.css" />
<link
rel="stylesheet"
href="_content/Siemens.IX.Blazor/css/siemens-ix/ix-aggrid.css"
/>
```

```razor
Expand Down Expand Up @@ -720,6 +732,7 @@ chart1.InitialChart(object1);
```

##Content

```razor
<Content>
<ContentHeader Id="myheader" HeaderTitle="My Content Page" />
Expand All @@ -742,9 +755,11 @@ chart1.InitialChart(object1);
```

## Date Dropdown

```razor
<DateDropdown Id="datedropdown1" DateRangeId="last-7" Format="MM/dd/yyyy" DateRangeOptions="_dateRangeOptions" DateRangeChangeEvent="Callback"></DateDropdown>
```

```csharp
readonly DateDropdownOption[] _dateRangeOptions =
{
Expand Down Expand Up @@ -798,7 +813,6 @@ private void Callback(DateDropdownResponse selectedDateDropdown)
<Divider></Divider>
```


## Drawer

```razor
Expand Down Expand Up @@ -895,6 +909,7 @@ private void DrawerButtonClicked()
```

- [ ] AG grid

## Group

```razor
Expand All @@ -906,6 +921,7 @@ private void DrawerButtonClicked()
```

### Group with Context

```razor
<Group Id="group" Header="Main Header" SubHeader="Subheader">
<Dropdown Id="dropdown" IsForGroupContext="true">
Expand Down Expand Up @@ -1093,6 +1109,7 @@ private void CloseModal()
PageSelectedEvent="PaginationPageSelected">
</Pagination>
```

## Pane

```razor
Expand Down Expand Up @@ -1184,17 +1201,17 @@ AddItemEvent="SelectItemAdded" Mode="SelectMode.Single" SelectedIndices="2" Id="

```css
.example {
display: block;
position: relative;
width: 100%;
display: block;
position: relative;
width: 100%;
}

div[data-tab-content] {
display: none;
display: none;
}

div[data-tab-content].show {
display: block;
display: block;
}
```

Expand Down Expand Up @@ -1330,6 +1347,7 @@ tree.TreeModel = treeNodes;
```

## Typography

```razor
<Typography Format="TypographyFormat.Label" TextColor="TypographyColor.Std" TextDecoration="TextDecoration.None">Label, Std, None</Typography>
<Typography Bold="true" Format="TypographyFormat.Code_Lg" TextColor="TypographyColor.Contrast" TextDecoration="TextDecoration.Line_Through">Bold, Code_Lg, Contrast, Line_Through</Typography>
Expand Down
10 changes: 5 additions & 5 deletions SiemensIXBlazor.Tests/AGGrid/AGGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task CreateGrid_ReturnsJSObjectReference_WhenIdIsNotEmpty()
Mock<IJSObjectReference> jsObjectReferenceMock = new();

// Mock of module import for JSRuntime
jsRuntimeMock.Setup(x => x.InvokeAsync<IJSObjectReference>("agGridInterop.createGrid", It.IsAny<object[]>()))
jsRuntimeMock.Setup(x => x.InvokeAsync<IJSObjectReference>("siemensIXInterop.agGridInterop.createGrid", It.IsAny<object[]>()))
.Returns(new ValueTask<IJSObjectReference>(jsObjectReferenceMock.Object));
Services.AddSingleton(jsRuntimeMock.Object);

Expand All @@ -86,7 +86,7 @@ public async Task CreateGrid_ReturnsJSObjectReference_WhenIdIsNotEmpty()

// Assert
Assert.NotNull(result);
jsRuntimeMock.Verify(x => x.InvokeAsync<object>("agGridInterop.createGrid", It.IsAny<object[]>()), Times.Once);
jsRuntimeMock.Verify(x => x.InvokeAsync<object>("siemensIXInterop.agGridInterop.createGrid", It.IsAny<object[]>()), Times.Once);
}

[Fact]
Expand All @@ -97,16 +97,16 @@ public async Task GetSelectedRows_ReturnsObject()
Services.AddSingleton(jsRuntimeMock.Object);
var cut = RenderComponent<AGGrid>(parameters => parameters.Add(p => p.Id, "testId"));
var jsObjectReferenceMock = new Mock<IJSObjectReference>();
jsRuntimeMock.Setup(x => x.InvokeAsync<object>("agGridInterop.getSelectedRows", It.IsAny<object[]>()))
jsRuntimeMock.Setup(x => x.InvokeAsync<object>("siemensIXInterop.agGridInterop.getSelectedRows", It.IsAny<object[]>()))
.ReturnsAsync(new object());


// Act
var result = await cut.Instance.GetSelectedRows(jsObjectReferenceMock.Object);

// Assert
Assert.NotNull(result);
jsRuntimeMock.Verify(x => x.InvokeAsync<object>("agGridInterop.getSelectedRows", It.IsAny<object[]>()), Times.Once);
jsRuntimeMock.Verify(x => x.InvokeAsync<object>("siemensIXInterop.agGridInterop.getSelectedRows", It.IsAny<object[]>()), Times.Once);
}
}
}
41 changes: 41 additions & 0 deletions SiemensIXBlazor.Tests/Helper/EnumParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using SiemensIXBlazor.Enums.PushCard;
using SiemensIXBlazor.Helpers;

namespace SiemensIXBlazor.Tests.Helpers
{
public class EnumParserTests
{
[Theory]
[InlineData(PushCardVariant.alarm, "alarm")]
[InlineData(PushCardVariant.insight, "insight")]
public void EnumToString_ShouldReturnCorrectLowercaseString_ForValidEnum(PushCardVariant variant, string expected)
{
// Act
var result = EnumParser<PushCardVariant>.EnumToString(variant);

// Assert
Assert.Equal(expected, result);
}

[Fact]
public void EnumToString_ShouldReturnEmptyString_ForInvalidEnum()
{
// Arrange
var invalidEnumValue = (PushCardVariant)999;

// Act & Assert
Assert.Throws<ArgumentException>(() => EnumParser<PushCardVariant>.EnumToString(invalidEnumValue));
}

[Fact]
public void EnumToString_ShouldReturnEmptyString_ForNullEnum()
{
// Arrange
PushCardVariant? nullableEnum = null;

// Act & Assert
// You need to handle nullable enums outside the method if using EnumParser
Assert.Throws<InvalidOperationException>(() => EnumParser<PushCardVariant>.EnumToString(nullableEnum!.Value));
}
}
}
4 changes: 4 additions & 0 deletions SiemensIXBlazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Global
{682ADEDC-AE1F-46C9-9F0D-7DE297BAC82D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{682ADEDC-AE1F-46C9-9F0D-7DE297BAC82D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{682ADEDC-AE1F-46C9-9F0D-7DE297BAC82D}.Release|Any CPU.Build.0 = Release|Any CPU
{20CB53D6-C6B3-4FCD-9DF3-A0511DB1FBA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20CB53D6-C6B3-4FCD-9DF3-A0511DB1FBA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20CB53D6-C6B3-4FCD-9DF3-A0511DB1FBA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20CB53D6-C6B3-4FCD-9DF3-A0511DB1FBA1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 3 additions & 3 deletions SiemensIXBlazor/Components/AGGrid/AGGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public partial class AGGrid

dotNetHelper = DotNetObjectReference.Create(this);

return await JSRuntime.InvokeAsync<IJSObjectReference?>("agGridInterop.createGrid", dotNetHelper, Id, JsonConvert.SerializeObject(options));
return await JSRuntime.InvokeAsync<IJSObjectReference?>("siemensIXInterop.agGridInterop.createGrid", dotNetHelper, Id, JsonConvert.SerializeObject(options));
}

public async Task<object?> GetSelectedRows(IJSObjectReference grid)
{
return await JSRuntime.InvokeAsync<object>("agGridInterop.getSelectedRows", grid);
return await JSRuntime.InvokeAsync<object>("siemensIXInterop.agGridInterop.getSelectedRows", grid);

}

[JSInvokable]
Expand Down
Loading

0 comments on commit ac8df65

Please sign in to comment.