tests/Add-SkylineScriptEditorWebPart.Tests.ps1
Describe "Add-SkylineScriptEditorWebPart" { BeforeAll { } Context "upload a new webpart to the webpart gallery" { It "should upload a new webpart" { Add-SkylineScriptEditorWebPart -Title "TestScriptEditorWebPart1" -Content "<script>window.alert('hello tests')</script>" -Group "Tests" } It "should have uploaded the new webpart named TestScriptEditorWebPart1.webpart" { Get-PnPFile -Url "_catalogs/wp/TestScriptEditorWebPart1.webpart" -AsString -ErrorAction SilentlyContinue | Should Not BeNullOrEmpty } It "should have content property set to encoded javascript alert" { [XML]$WebPartXml = Get-PnPFile -Url "_catalogs/wp/TestScriptEditorWebPart1.webpart" -AsString -ErrorAction SilentlyContinue $ContentProperty = $WebPartXml.webParts.webPart.data.properties.property | Where-Object {$_.name -eq "Content"} $ContentProperty.InnerXml | Should Be "<script>window.alert('hello tests')</script>" } It "should have set the web part group to 'Tests'" { $WebPartItem = Get-PnPFile -Url "_catalogs/wp/TestScriptEditorWebPart1.webpart" -AsListItem -ErrorAction SilentlyContinue $WebPartItem["Group"] | Should Be "Tests" } } AfterAll { Remove-PnPFile -SiteRelativeUrl "_catalogs/wp/TestScriptEditorWebPart1.webpart" -Force } } |