Skip to content

Commit

Permalink
Product tree doesnt collapse anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Apr 30, 2024
1 parent 3e5e66e commit 89ceccb
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 215 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SystemTreeTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023-2024 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Nabil Abbar
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The CDP4-COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// <copyright file="SystemRepresentationBodyTestFixture.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMETwebapp.Tests.Components.SystemRepresentation
{
Expand All @@ -34,7 +34,10 @@ namespace COMETwebapp.Tests.Components.SystemRepresentation

using CDP4Dal;
using CDP4Dal.DAL;

using CDP4Dal.Events;

using CDP4Web.Enumerations;

using COMET.Web.Common.Components.Selectors;
using COMET.Web.Common.Model.Configuration;
using COMET.Web.Common.Services.ConfigurationService;
Expand Down Expand Up @@ -123,76 +126,54 @@ public void SetUp()

var enumerationValues = new List<string> { "cube", "sphere", "cylinder" };

this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
var elementDefinition = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Element =
Name = "TestElement",
Owner = this.domain,
ShortName = "TE",
ContainedElement =
{
new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri)
new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Name = "TestElement",
Owner = this.domain,
ShortName = "TE",
ContainedElement =
{
new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Owner = this.domain,
ShortName = "TEU",
ElementDefinition = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Name = "TestElementUsage",
Owner = this.domain,
ShortName = "TEU"
}
}
},
Parameter =
ShortName = "TEU",
ElementDefinition = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Owner = this.domain,
ParameterType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Name = "paramType1",
ShortName = "BPT"
},
ValueSet =
{
new ParameterValueSet()
{
Published = new ValueArray<string>(enumerationValues),
Manual = new ValueArray<string>(enumerationValues)
}
},
Scale = new OrdinalScale
{
Iid = Guid.NewGuid(),
ShortName = "m"
}
}
Name = "TestElementUsage",
Owner = this.domain,
ShortName = "TEU"
}
}
},
TopElement = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri)
Parameter =
{
Name = "TestElement",
Owner = this.domain,
ShortName = "TE",
ContainedElement =
new Parameter(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Owner = this.domain,
ParameterType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Name = "paramType1",
ShortName = "BPT"
},
ValueSet =
{
new ElementUsage(Guid.NewGuid(), this.assembler.Cache, this.uri)
new ParameterValueSet
{
Owner = this.domain,
ShortName = "TEU",
ElementDefinition = new ElementDefinition(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Name = "TestElementUsage",
Owner = this.domain,
ShortName = "TEU"
}
Published = new ValueArray<string>(enumerationValues),
Manual = new ValueArray<string>(enumerationValues)
}
},
Scale = new OrdinalScale
{
Iid = Guid.NewGuid(),
ShortName = "m"
}
},
}
}
};

this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Container = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
EngineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri)
Expand Down Expand Up @@ -230,6 +211,9 @@ public void SetUp()
}
};

this.iteration.Element.Add(elementDefinition);
this.iteration.TopElement = this.iteration.Element[0];

var option1 = new Option(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
ShortName = "OPT_1",
Expand Down Expand Up @@ -260,22 +244,22 @@ public void SetUp()
this.session.Setup(x => x.Credentials).Returns(new Credentials("admin", "pass", this.uri));
this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDirectory);
this.session.Setup(x => x.ActivePerson).Returns(this.person);

this.sessionService.Setup(x => x.GetDomainOfExpertise(this.iteration)).Returns(this.domain);
}

[TearDown]
public void TearDown()
{
this.context.CleanContext();
this.viewModel.Dispose();
this.messageBus.ClearSubscriptions();
}

[Test]
public void VerifyOnInitialized()
{
var renderer = this.context.RenderComponent<SystemRepresentationBody>(parameters =>
{
parameters.Add(p => p.CurrentThing, this.iteration);
});
var renderer = this.context.RenderComponent<SystemRepresentationBody>(parameters => { parameters.Add(p => p.CurrentThing, this.iteration); });

var option1 = new Option(Guid.NewGuid(), this.assembler.Cache, this.uri)
{
Expand All @@ -286,24 +270,19 @@ public void VerifyOnInitialized()
var optionFilterCombo = renderer.FindComponent<OptionSelector>();

Assert.That(optionFilterCombo, Is.Not.Null);

this.viewModel.OptionSelector.SelectedOption = option1;
}

[Test]
public async Task VerifySelectNode()
{
this.context.RenderComponent<SystemRepresentationBody>(parameters =>
{
parameters.Add(p => p.CurrentThing, this.iteration);
});
this.context.RenderComponent<SystemRepresentationBody>(parameters => { parameters.Add(p => p.CurrentThing, this.iteration); });

await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.viewModel.Elements.Clear();
this.viewModel.Elements.Add(this.iteration.Element[0]);

this.viewModel.SelectElement(new SystemNodeViewModel(this.viewModel.Elements.FirstOrDefault()!.Name));
this.viewModel.SelectElement(new SystemNodeViewModel(this.viewModel.Elements.FirstOrDefault()));

Assert.Multiple(() =>
{
Expand All @@ -317,5 +296,50 @@ public async Task VerifySelectNode()
Assert.That(this.viewModel.ElementDefinitionDetailsViewModel.Rows.First().SwitchValue, Is.Not.Null);
});
}

[Test]
public void VerifySessionRefresh()
{
this.viewModel.OptionSelector.SelectedOption = this.iteration.DefaultOption;
this.viewModel.CurrentThing = this.iteration;
this.viewModel.ProductTreeViewModel.RootViewModel.SetThing(this.iteration.Element[0]);

Assert.Multiple(() =>
{
Assert.That(this.viewModel.ProductTreeViewModel.RootViewModel.GetChildren(), Has.Count.EqualTo(1));
Assert.That(this.viewModel.OptionSelector.SelectedOption, Is.EqualTo(this.iteration.DefaultOption));
});

this.messageBus.SendMessage(SessionServiceEvent.SessionRefreshed, this.sessionService.Object.Session);
Assert.That(this.viewModel.ProductTreeViewModel.RootViewModel.GetChildren(), Has.Count.EqualTo(1));

var elementUsage = new ElementUsage
{
Iid = Guid.NewGuid(),
Container = this.iteration.TopElement,
ElementDefinition = this.iteration.Element[0]
};

this.messageBus.SendObjectChangeEvent(elementUsage, EventKind.Added);
this.messageBus.SendMessage(SessionServiceEvent.SessionRefreshed, this.sessionService.Object.Session);
Assert.That(this.viewModel.ProductTreeViewModel.RootViewModel.GetChildren(), Has.Count.EqualTo(2));

elementUsage.Name = "updatedName";
this.messageBus.SendObjectChangeEvent(elementUsage, EventKind.Updated);
this.messageBus.SendMessage(SessionServiceEvent.SessionRefreshed, this.sessionService.Object.Session);

Assert.Multiple(() =>
{
Assert.That(this.viewModel.ProductTreeViewModel.RootViewModel.GetChildren().ElementAt(1).Title, Is.EqualTo("updatedName"));
Assert.That(this.viewModel.ProductTreeViewModel.RootViewModel.GetChildren(), Has.Count.EqualTo(2));
});

this.messageBus.SendObjectChangeEvent(elementUsage, EventKind.Removed);
this.messageBus.SendMessage(SessionServiceEvent.SessionRefreshed, this.sessionService.Object.Session);
Assert.That(this.viewModel.ProductTreeViewModel.RootViewModel.GetChildren(), Has.Count.EqualTo(1));

this.messageBus.SendMessage(new DomainChangedEvent(this.iteration, this.domain));
Assert.That(this.viewModel.CurrentDomain, Is.EqualTo(this.domain));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SystemRepresentationBody.razor.cs" company="RHEA System S.A.">
// Copyright (c) 2023-2024 RHEA System S.A.
// <copyright file="SystemRepresentationBody.razor.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The CDP4-COMET WEB Community Edition is free software; you can redistribute it and/or
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
Expand All @@ -24,13 +24,13 @@

namespace COMETwebapp.Components.SystemRepresentation
{
using Microsoft.AspNetCore.Components;

using COMET.Web.Common.Extensions;
using COMET.Web.Common.Utilities;

using COMETwebapp.Utilities;

using Microsoft.AspNetCore.Components;

using ReactiveUI;

/// <summary>
Expand All @@ -48,6 +48,9 @@ protected override void OnInitialized()

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.OptionSelector.SelectedOption)
.Subscribe(_ => this.UpdateUrl()));

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsLoading)
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
Expand Down
Loading

0 comments on commit 89ceccb

Please sign in to comment.