From e4818cd4584183be25a814806411c306b2360321 Mon Sep 17 00:00:00 2001 From: jaimeatrhea Date: Thu, 21 Sep 2023 11:32:21 +0200 Subject: [PATCH] Add some more tests --- .../BookEditor/InputEditorTestFixture.cs | 18 +-- .../SessionServiceTestFixture.cs | 14 +++ .../Services/ValidationServiceTestFixture.cs | 114 ++++++++++++++++++ .../BookEditor/EditorPopup.razor.cs | 26 +--- .../Components/BookEditor/InputEditor.razor | 4 +- .../BookEditor/InputEditor.razor.cs | 2 +- COMET.Web.Common/wwwroot/css/styles.css | 5 +- .../DomDataServiceTestFixture.cs | 74 ++++++++++++ .../BookEditor/BookEditorColumn.razor.cs | 6 +- .../Interoperability/DomDataService.cs | 2 +- .../BookEditor/BookEditorBodyViewModel.cs | 14 +-- COMETwebapp/wwwroot/Scripts/DomData.js | 16 ++- 12 files changed, 242 insertions(+), 53 deletions(-) create mode 100644 COMET.Web.Common.Tests/Services/ValidationServiceTestFixture.cs create mode 100644 COMETwebapp.Tests/Services/Interoperability/DomDataServiceTestFixture.cs diff --git a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs index bc922220..fab129e2 100644 --- a/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/BookEditor/InputEditorTestFixture.cs @@ -31,16 +31,9 @@ namespace COMET.Web.Common.Tests.Components.BookEditor using COMET.Web.Common.Components.BookEditor; using COMET.Web.Common.Test.Helpers; - using COMET.Web.Common.ViewModels.Components.BookEditor; using DevExpress.Blazor; - - using DynamicData; - - using Microsoft.AspNetCore.Components; - - using Moq; - + using NUnit.Framework; using TestContext = Bunit.TestContext; @@ -89,9 +82,8 @@ public void Setup() [Test] public void VerifyComponent() { - var dxtabs = this.component.FindComponent(); - - dxtabs.Instance.ActiveTabIndex = 0; + var basicTab = this.component.Find(".basic-tab"); + basicTab.Click(); var textboxes = this.component.FindComponents(); var combobox = this.component.FindComponent>(); @@ -106,7 +98,9 @@ public void VerifyComponent() Assert.That(combobox.Instance.Value, Is.EqualTo(this.activeDomains.First())); }); - dxtabs.Instance.ActiveTabIndex = 1; + var categoryTab = this.component.Find(".category-tab"); + categoryTab.Click(); + this.component.Render(); var listbox = this.component.FindComponent>(); diff --git a/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs index d5c6e10b..6ad7cdca 100644 --- a/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Services/SessionManagement/SessionServiceTestFixture.cs @@ -291,5 +291,19 @@ public void VerifyUpdateThings() thingsToUpdate.Add(clone); Assert.DoesNotThrow(() => this.sessionService.UpdateThings(this.iteration, thingsToUpdate)); } + + [Test] + public void VerifyDeleteThings() + { + this.sessionService.IsSessionOpen = true; + + var element = new ElementDefinition + { + Name = "Battery", + Owner = this.sessionService.GetDomainOfExpertise(this.iteration) + }; + + Assert.DoesNotThrow(() => this.sessionService.DeleteThing(this.iteration, element.Clone(false))); + } } } diff --git a/COMET.Web.Common.Tests/Services/ValidationServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/ValidationServiceTestFixture.cs new file mode 100644 index 00000000..129d6d60 --- /dev/null +++ b/COMET.Web.Common.Tests/Services/ValidationServiceTestFixture.cs @@ -0,0 +1,114 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.Services +{ + using COMET.Web.Common.Services; + + using NUnit.Framework; + + [TestFixture] + public class ValidationServiceTestFixture + { + [Test] + public void VerifyValidateProperty() + { + Assert.Multiple(() => + { + Assert.That(ValidationService.ValidateProperty("SelectedSource", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("SelectedSource", "valid source"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ShortName", "invalid ShortName"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ShortName", "validShortName"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("RDLShortName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("RDLShortName", "validRDL"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("RDLName", " invalidRDLName"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("RDLName", "validRDLName"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("NativeName", "1nativeName1"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("NativeName", "nativeName"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("FileRevisionName", " invalid FileRevisionName"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("FileRevisionName", "FileRevisionName"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Name", "invalidName)"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Name", "validName"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("EmailAddress", "invalidemail.com"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("EmailAddress", "valid@example.com"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("TelephoneNumber", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("TelephoneNumber", "000 000 000"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("UserPreference", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("UserPreference", "userPref"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("LanguageCode", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("LanguageCode", "language code"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Content", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Content", "content"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Password", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Password", "password"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ForwardRelationshipName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ForwardRelationshipName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("InverseRelationshipName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("InverseRelationshipName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Exponent", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Exponent", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Symbol", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Symbol", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ScaleValueDefinition", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ScaleValueDefinition", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ScaleReferenceQuantityValue", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ScaleReferenceQuantityValue", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Factor", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Factor", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Modulus", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Modulus", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Extension", "invalidExtension"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Extension", "valid1"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("FileTypeName", "invented"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("FileTypeName", "audio/1"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Value", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Value", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ModelSetupShortName", "invalid!"), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ModelSetupShortName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("PersonShortName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("PersonShortName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("PersonGivenName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("PersonGivenName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("PersonSurname", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("PersonSurname", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("RequirementShortName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("RequirementShortName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ModelSetupName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ModelSetupName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ConversionFactor", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("ConversionFactor", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Description", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Description", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Title", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("Title", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionShortName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionShortName", "valid"), Is.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionName", ""), Is.Not.Null.Or.Empty); + Assert.That(ValidationService.ValidateProperty("EnumerationValueDefinitionName", "valid"), Is.Null.Or.Empty); + + }); + } + } +} + diff --git a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs index 3f21c934..46434852 100644 --- a/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/EditorPopup.razor.cs @@ -71,43 +71,29 @@ private async Task OnConfirmClick() if (this.ViewModel.Item is INamedThing namedThing) { var error = ValidationService.ValidateProperty(nameof(namedThing.Name), namedThing.Name); - - if (!string.IsNullOrEmpty(error)) - { - validationErrors.Add(error); - } + validationErrors.Add(error); } if (this.ViewModel.Item is IShortNamedThing shortNamedThing) { var error = ValidationService.ValidateProperty(nameof(shortNamedThing.ShortName), shortNamedThing.ShortName); - - if (!string.IsNullOrEmpty(error)) - { - validationErrors.Add(error); - } + validationErrors.Add(error); } if (this.ViewModel.Item is IOwnedThing ownedThing) { var error = ownedThing.Owner == null ? "The thing must be owned by a DoE" : string.Empty; - - if (!string.IsNullOrEmpty(error)) - { - validationErrors.Add(error); - } + validationErrors.Add(error); } if (this.ViewModel.Item is TextualNote textualNote) { var error = string.IsNullOrEmpty(textualNote.Content)? "The textual note must contain a content" : string.Empty; - - if (!string.IsNullOrEmpty(error)) - { - validationErrors.Add(error); - } + validationErrors.Add(error); } + validationErrors = validationErrors.Where(x => !string.IsNullOrEmpty(x)).ToList(); + this.ViewModel.ValidationErrors.Edit(inner => { inner.Clear(); diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor b/COMET.Web.Common/Components/BookEditor/InputEditor.razor index d010ebf6..1d83734f 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor @@ -29,7 +29,7 @@
- +
@if (this.Item is INamedThing namedThing) { @@ -71,7 +71,7 @@ }
- +
@if (this.Item is ICategorizableThing categorizableThing) { diff --git a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs index 94713e68..0f6c2ac5 100644 --- a/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs +++ b/COMET.Web.Common/Components/BookEditor/InputEditor.razor.cs @@ -56,7 +56,7 @@ public partial class InputEditor /// /// Handler for when the selected categories changed /// - /// + /// the changed categories private void OnCategoryChange(IEnumerable categories) { if (this.Item is ICategorizableThing categorizableThing) diff --git a/COMET.Web.Common/wwwroot/css/styles.css b/COMET.Web.Common/wwwroot/css/styles.css index 640dd0f8..a730d676 100644 --- a/COMET.Web.Common/wwwroot/css/styles.css +++ b/COMET.Web.Common/wwwroot/css/styles.css @@ -212,10 +212,6 @@ margin: 4%; } -.editor-row { - display: flex; -} - .content-scale { margin-top: auto; margin-bottom: auto; @@ -514,6 +510,7 @@ } .editor-row { + display: flex; align-items: center; justify-content: space-between; } diff --git a/COMETwebapp.Tests/Services/Interoperability/DomDataServiceTestFixture.cs b/COMETwebapp.Tests/Services/Interoperability/DomDataServiceTestFixture.cs new file mode 100644 index 00000000..52447e05 --- /dev/null +++ b/COMETwebapp.Tests/Services/Interoperability/DomDataServiceTestFixture.cs @@ -0,0 +1,74 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2023 RHEA System S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the RHEA 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 . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMETwebapp.Tests.Services.Interoperability +{ + using CDP4Common.ReportingData; + + using COMETwebapp.Components.BookEditor; + using COMETwebapp.Services.Interoperability; + + using Microsoft.JSInterop; + + using Moq; + + using NUnit.Framework; + + [TestFixture] + public class DomDataServiceTestFixture + { + private Mock service; + + [SetUp] + public void Setup() + { + this.service = new Mock(); + + this.service.Setup(x => x.GetElementSizeAndPosition(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(new float[] { 1, 2, 3, 4 }); + } + + [Test] + public async Task VerifyMethods() + { + var dotnet = DotNetObjectReference.Create(new BookEditorColumn()); + + Assert.Multiple(() => + { + Assert.That(() => this.service.Object.LoadDotNetHelper(dotnet), Throws.Nothing); + Assert.That(async () => await this.service.Object.GetElementSizeAndPosition(0, "node", true), Throws.Nothing); + }); + + var sizeAndPosition = await this.service.Object.GetElementSizeAndPosition(0, "node", true); + + Assert.Multiple(() => + { + Assert.That(sizeAndPosition, Is.EquivalentTo(new float[] { 1, 2, 3, 4 })); + Assert.That(() => this.service.Object.SubscribeToResizeEvent("resize"), Throws.Nothing); + }); + } + } +} + + diff --git a/COMETwebapp/Components/BookEditor/BookEditorColumn.razor.cs b/COMETwebapp/Components/BookEditor/BookEditorColumn.razor.cs index 6cdac23e..974ab1c0 100644 --- a/COMETwebapp/Components/BookEditor/BookEditorColumn.razor.cs +++ b/COMETwebapp/Components/BookEditor/BookEditorColumn.razor.cs @@ -111,17 +111,17 @@ public partial class BookEditorColumn /// /// The data of size and position of the first item in the list /// - private float[] firstItemSizeAndPosition = {}; + private float[] firstItemSizeAndPosition = Array.Empty(); /// /// The data of size and position of the last item in the list /// - private float[] lastItemSizeAndPosition = {}; + private float[] lastItemSizeAndPosition = Array.Empty(); /// /// The data of size and position of the selected item /// - private float[] selectedItemSizeAndPosition = {}; + private float[] selectedItemSizeAndPosition = Array.Empty(); /// /// Gets or sets the class used to selected the nodes diff --git a/COMETwebapp/Services/Interoperability/DomDataService.cs b/COMETwebapp/Services/Interoperability/DomDataService.cs index bec8f988..5a9507d8 100644 --- a/COMETwebapp/Services/Interoperability/DomDataService.cs +++ b/COMETwebapp/Services/Interoperability/DomDataService.cs @@ -25,7 +25,7 @@ namespace COMETwebapp.Services.Interoperability { using COMETwebapp.Components.BookEditor; - using COMETwebapp.Components.ModelEditor; + using Microsoft.JSInterop; /// diff --git a/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs b/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs index d7a6ad30..54fb0ddc 100644 --- a/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs +++ b/COMETwebapp/ViewModels/Components/BookEditor/BookEditorBodyViewModel.cs @@ -236,7 +236,7 @@ protected override async Task OnIterationChanged() /// Validates that the thing is a valid thing for the operations in this ViewModel /// /// the thing to validate - private void ValidateThing(Thing thing) + private static void ValidateThing(Thing thing) { if (thing is not Book && thing is not Section && thing is not Page && thing is not Note) { @@ -250,7 +250,7 @@ private void ValidateThing(Thing thing) /// the thing public void SetThingToCreate(Thing thing) { - this.ValidateThing(thing); + ValidateThing(thing); this.ThingToCreate = thing; @@ -290,7 +290,7 @@ public async Task OnCreateThing() throw new InvalidOperationException("The thing to create can't be null"); } - this.ValidateThing(this.ThingToCreate); + ValidateThing(this.ThingToCreate); Thing thingContainer; @@ -326,7 +326,7 @@ public async Task OnCreateThing() /// the thing public void SetThingToEdit(Thing thing) { - this.ValidateThing(thing); + ValidateThing(thing); this.ThingToEdit = thing; @@ -366,7 +366,7 @@ public async Task OnEditThing() throw new InvalidOperationException("The thing to edit can't be null"); } - this.ValidateThing(this.ThingToEdit); + ValidateThing(this.ThingToEdit); var thingContainer = this.ThingToEdit.Container; var thingContainerClone = thingContainer.Clone(false); @@ -383,7 +383,7 @@ public async Task OnEditThing() /// the thing public void SetThingToDelete(Thing thingToDelete) { - this.ValidateThing(thingToDelete); + ValidateThing(thingToDelete); this.ThingToDelete = thingToDelete; @@ -401,7 +401,7 @@ public async Task OnDeleteThing() throw new InvalidOperationException("The thing to delete can't be null"); } - this.ValidateThing(this.ThingToDelete); + ValidateThing(this.ThingToDelete); var thingContainer = this.ThingToDelete.Container; var thingContainerClone = thingContainer.Clone(false); diff --git a/COMETwebapp/wwwroot/Scripts/DomData.js b/COMETwebapp/wwwroot/Scripts/DomData.js index 80c7ce2b..ed431487 100644 --- a/COMETwebapp/wwwroot/Scripts/DomData.js +++ b/COMETwebapp/wwwroot/Scripts/DomData.js @@ -6,10 +6,16 @@ function setDotNetHelper(helper) { dotNetHelper = helper; } +/** + * Gets an element size and position relative to its parent + * @param {int} index + * @param {string} cssSelector + * @param {bool} useScroll + */ function GetElementSizeAndPosition(index, cssSelector, useScroll) { - var elements = document.getElementsByClassName(cssSelector); - var element = elements[index]; + let elements = document.getElementsByClassName(cssSelector); + let element = elements[index]; if (element != null) { @@ -17,7 +23,7 @@ function GetElementSizeAndPosition(index, cssSelector, useScroll) { if (useScroll) { - var offsetTop = element.getBoundingClientRect().top - element.offsetParent.getBoundingClientRect().top; + let offsetTop = element.getBoundingClientRect().top - element.offsetParent.getBoundingClientRect().top; return [element.offsetLeft, offsetTop, element.offsetWidth, element.offsetHeight]; } @@ -32,6 +38,10 @@ function GetElementSizeAndPosition(index, cssSelector, useScroll) return [0, 0, 0, 0]; } +/** + * Subscribes to the resize event of the window and use a callback method to alert + * @param {string} callbackMethodName + */ function SubscribeToResizeEvent(callbackMethodName) { window.addEventListener("resize", () =>