Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tests for New-BTContextMenuItem + re-arrange
  • Loading branch information
Windos committed Feb 4, 2019
1 parent 69f2446 commit 0f2f4d7
Showing 1 changed file with 92 additions and 73 deletions.
165 changes: 92 additions & 73 deletions Tests/BurntToast.Tests.ps1
@@ -1,221 +1,240 @@
Import-Module "$PSScriptRoot/../BurntToast/BurntToast.psd1" -Force

Describe 'New-BTAction' {
Describe 'New-BTAppId' {
Context 'running without arguments' {
Start-Transcript tmp.log
try {
New-BTAction -WhatIf
New-BTAppId -DryFire -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsCustom] with 0 Inputs, 0 Buttons, and 0 ContextMenuItems".'
$Expected = 'What if: Performing the operation "New-BTAppId" on target "creating: ''HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'' with property ''ShowInActionCenter'' set to ''1'' (DWORD)".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'snooze and dismiss modal' {
Context 'running with custom AppId' {
Start-Transcript tmp.log
try {
New-BTAction -SnoozeAndDismiss -WhatIf
New-BTAppId -AppId 'Script Checker' -DryFire -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsSnoozeAndDismiss] with 0 Inputs, 0 Buttons, and 0 ContextMenuItems".'
$Expected = 'What if: Performing the operation "New-BTAppId" on target "creating: ''HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\Script Checker'' with property ''ShowInActionCenter'' set to ''1'' (DWORD)".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'single clickable button' {
}

Describe 'New-BTAudio' {
Context 'built in audio source' {
Start-Transcript tmp.log
try {
New-BTAction -Buttons (New-BTButton -Content 'Google' -Arguments 'https://google.com') -WhatIf
New-BTAudio -Source ms-winsoundevent:Notification.SMS -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsCustom] with 0 Inputs, 1 Buttons, and 0 ContextMenuItems".'
$Expected = 'What if: Performing the operation "New-BTAudio" on target "returning: [ToastAudio]:Src=ms-winsoundevent:Notification.SMS:Loop=False:Silent=False".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'mixed content: button & context menu' {
$Button = New-BTButton -Content 'Google' -Arguments 'https://google.com'
$ContextMenuItem = New-BTContextMenuItem -Content 'Bing' -Arguments 'https://bing.com'

Context 'custom audio source' {
Start-Transcript tmp.log
try {
New-BTAction -Buttons $Button -ContextMenuItems $ContextMenuItem -WhatIf
New-BTAudio -Path 'C:\Windows\media\tada.wav' -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsCustom] with 0 Inputs, 1 Buttons, and 1 ContextMenuItems".'
$Expected = 'What if: Performing the operation "New-BTAudio" on target "returning: [ToastAudio]:Src=file:///C:/Windows/media/tada.wav:Loop=False:Silent=False".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'Silent switch' {
Start-Transcript tmp.log
try {
New-BTAudio -Silent -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAudio" on target "returning: [ToastAudio]:Src=:Loop=False:Silent=True".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
}

Describe 'New-BTAppId' {
Context 'running without arguments' {
Describe 'New-BTButton' {
Context 'system defined dismiss button' {
Start-Transcript tmp.log
try {
New-BTAppId -DryFire -WhatIf
New-BTButton -Dismiss -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAppId" on target "creating: ''HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'' with property ''ShowInActionCenter'' set to ''1'' (DWORD)".'
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButtonDismiss]:CustomContent=:ImageUri=".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'running with custom AppId' {
Context 'system defined snooze button' {
Start-Transcript tmp.log
try {
New-BTAppId -AppId 'Script Checker' -DryFire -WhatIf
New-BTButton -Snooze -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAppId" on target "creating: ''HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\Script Checker'' with property ''ShowInActionCenter'' set to ''1'' (DWORD)".'
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButtonSnooze]:CustomContent=:ImageUri=:SelectionBoxId=".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
}

Describe 'New-BTAudio' {
Context 'built in audio source' {
Context 'custom button with text' {
Start-Transcript tmp.log
try {
New-BTAudio -Source ms-winsoundevent:Notification.SMS -WhatIf
New-BTButton -Content 'Blog' -Arguments 'https://king.geek.nz' -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAudio" on target "returning: [ToastAudio]:Src=ms-winsoundevent:Notification.SMS:Loop=False:Silent=False".'
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButton]:Content=Blog:Arguments=https://king.geek.nz:ActivationType=Protocol:ImageUri=:TextBoxId=".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'custom audio source' {
Context 'custom button with image' {
Start-Transcript tmp.log
try {
New-BTAudio -Path 'C:\Windows\media\tada.wav' -WhatIf
$Picture = '$PSScriptRoot\Media\BurntToast.png'
New-BTButton -Content 'View Picture' -Arguments $Picture -ImageUri $Picture -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAudio" on target "returning: [ToastAudio]:Src=file:///C:/Windows/media/tada.wav:Loop=False:Silent=False".'
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButton]:Content=View Picture:Arguments=$PSScriptRoot\Media\BurntToast.png:ActivationType=Protocol:ImageUri=$PSScriptRoot\Media\BurntToast.png:TextBoxId=".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'Silent switch' {
}

Describe 'New-BTContextMenuItem' {
Context 'loaded with standard arguments' {
Start-Transcript tmp.log
try {
New-BTAudio -Silent -WhatIf
New-BTContextMenuItem -Content 'Google' -Arguments 'https://google.com' -ActivationType Protocol -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTAudio" on target "returning: [ToastAudio]:Src=:Loop=False:Silent=True".'
$Expected = 'What if: Performing the operation "New-BTContextMenuItem" on target "returning: [ToastContextMenuItem]:Content=Google:Arguments=https://google.com:ActivationType=Protocol".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
}

Describe 'New-BTButton' {
Context 'system defined dismiss button' {






Describe 'New-BTAction' {
Context 'running without arguments' {
Start-Transcript tmp.log
try {
New-BTButton -Dismiss -WhatIf
New-BTAction -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButtonDismiss]:CustomContent=:ImageUri=".'
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsCustom] with 0 Inputs, 0 Buttons, and 0 ContextMenuItems".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'system defined snooze button' {
Context 'snooze and dismiss modal' {
Start-Transcript tmp.log
try {
New-BTButton -Snooze -WhatIf
New-BTAction -SnoozeAndDismiss -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButtonSnooze]:CustomContent=:ImageUri=:SelectionBoxId=".'
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsSnoozeAndDismiss] with 0 Inputs, 0 Buttons, and 0 ContextMenuItems".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'custom button with text' {
Context 'single clickable button' {
Start-Transcript tmp.log
try {
New-BTButton -Content 'Blog' -Arguments 'https://king.geek.nz' -WhatIf
New-BTAction -Buttons (New-BTButton -Content 'Google' -Arguments 'https://google.com') -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButton]:Content=Blog:Arguments=https://king.geek.nz:ActivationType=Protocol:ImageUri=:TextBoxId=".'
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsCustom] with 0 Inputs, 1 Buttons, and 0 ContextMenuItems".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
Context 'custom button with image' {
Context 'mixed content: button & context menu' {
$Button = New-BTButton -Content 'Google' -Arguments 'https://google.com'
$ContextMenuItem = New-BTContextMenuItem -Content 'Bing' -Arguments 'https://bing.com'

Start-Transcript tmp.log
try {
$Picture = '$PSScriptRoot\Media\BurntToast.png'
New-BTButton -Content 'View Picture' -Arguments $Picture -ImageUri $Picture -WhatIf
New-BTAction -Buttons $Button -ContextMenuItems $ContextMenuItem -WhatIf
}
finally {
Stop-Transcript
$Log = (Get-Content tmp.log).Where({ $_ -match "What if: " })
Remove-Item tmp.log
}
It 'has consitent WhatIf response' {
$Expected = 'What if: Performing the operation "New-BTButton" on target "returning: [ToastButton]:Content=View Picture:Arguments=$PSScriptRoot\Media\BurntToast.png:ActivationType=Protocol:ImageUri=$PSScriptRoot\Media\BurntToast.png:TextBoxId=".'
$Expected = 'What if: Performing the operation "New-BTAction" on target "returning: [ToastActionsCustom] with 0 Inputs, 1 Buttons, and 1 ContextMenuItems".'
$Log -join [System.Environment]::NewLine | should Be $Expected
}
}
}






Describe 'New-BTBinding' {
Context 'loaded with children' {
$Text1 = New-BTText -Content 'This is a test'
Expand Down Expand Up @@ -285,23 +304,23 @@ Describe 'New-BTContent' {
}


Describe 'New-BurntToastNotification' {
Context 'running without arguments' {
It 'runs without errors' {
{ New-BurntToastNotification } | should Not Throw
}

It 'does not return anything' {
New-BurntToastNotification | should BeNullOrEmpty
}
}
Context 'running with arguments (Image)' {
It 'runs without errors' {
{ New-BurntToastNotification -AppLogo 'https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast-Logo.png' } | should Not Throw
}

It 'does not return anything' {
New-BurntToastNotification -AppLogo 'https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast-Logo.png' | should BeNullOrEmpty
}
}
}
# Describe 'New-BurntToastNotification' {
# Context 'running without arguments' {
# It 'runs without errors' {
# { New-BurntToastNotification } | should Not Throw
# }
#
# It 'does not return anything' {
# New-BurntToastNotification | should BeNullOrEmpty
# }
# }
# Context 'running with arguments (Image)' {
# It 'runs without errors' {
# { New-BurntToastNotification -AppLogo 'https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast-Logo.png' } | should Not Throw
# }
#
# It 'does not return anything' {
# New-BurntToastNotification -AppLogo 'https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast-Logo.png' | should BeNullOrEmpty
# }
# }
# }

0 comments on commit 0f2f4d7

Please sign in to comment.