Skip to content

Commit

Permalink
(GH-125) Make Header ID optional
Browse files Browse the repository at this point in the history
Previously the Id parameter to New-BTHeader was mandatory however as it can be
a generated unique string it doesn't have to be.  This commit modifies the
Id parameter so it is no longer mandatory and uses a GUID style string as the
autogenerated Id if none is passed.  GUIDs are used instead of, say, the title
because they are guaranteed to be unique whereas using the title or date/time
could cause notification Id collisions.

This commit also adds a test to ensure that the function can be called without
the -Id parameter and that it is actually generated, not left as null or an
empty string.
  • Loading branch information
glennsarti committed Oct 8, 2020
1 parent 52115dc commit 06f9119
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions BurntToast/Public/New-BTHeader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Microsoft.Toolkit.Uwp.Notifications.ToastHeader
.EXAMPLE
New-BTHeader -Id 'primary header' -Title 'First Category'
New-BTHeader -Title 'First Category'
This command creates a Toast Header object, which will be displayed with the text "First Category."
Expand All @@ -37,8 +37,8 @@
# Unique string that identifies a header. If a new Id is provided, the system will treat the header as a new header even if it has the same display text as a previous header.
#
# It is possible to update a header's display text by re-using the Id but changing the title.
[Parameter(Mandatory)]
[string] $Id,
[Parameter()]
[string] $Id = 'ID' + (New-Guid).ToString().Replace('-','').ToUpper(),

# The header string that is displayed to the user.
[Parameter(Mandatory)]
Expand Down
17 changes: 17 additions & 0 deletions Tests/New-BTHeader.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ Describe 'New-BTHeader' {
$Log | Should -Be $Expected
}
}

Context 'loaded without Id' {
Start-Transcript tmp.log
try {
New-BTHeader -Title 'First Category' -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'generates an Id' {
$Expected = 'Id=[a-zA-Z\d]+:Title'
$Log | Should -Match $Expected
}
}

Context 'clickable header text' {
Start-Transcript tmp.log
try {
Expand Down

0 comments on commit 06f9119

Please sign in to comment.