diff --git a/Test/public/newNotes.test.ps1 b/Test/public/newNotes.test.ps1 index c20f558..e126be6 100644 --- a/Test/public/newNotes.test.ps1 +++ b/Test/public/newNotes.test.ps1 @@ -14,7 +14,7 @@ function Test_AddNotesToday_Simple{ $header = $header -replace "{title}", $title $header = $header -replace "{date}", $date - New-TestingFolder -Path "./TestNotesRoot/$category" + $categoryPath = New-TestingFolder -Path "./TestNotesRoot/$category" -PassThru # Add note with folder using -Force $path = New-NoteToday $category $title -NoOpen -Force @@ -24,17 +24,12 @@ function Test_AddNotesToday_Simple{ Assert-IsTrue $content.StartsWith($header) # File should be in a folder of its own name - $parentName = $path | Split-Path -Parent | Split-Path -Leaf - $fileNameBase = $path | Split-Path -LeafBase - Assert-AreEqual -Expected $fileNameBase -Presented $parentName - Assert-AreNotEqual -Expected $parentName -Presented $category + $parentPath = $path | Split-Path -parent + Assert-AreEqualPath -Expected $categoryPath -Presented $parentPath - # Parent folder should be child or category folder - $granParent = $path | Split-Path -Parent | Split-Path -Parent | Split-Path -Leaf - Assert-AreEqual -Expected $granParent -Presented $category } -function Test_AddNotesToday_Simple_AvoidChildFolder { +function Test_AddNotesToday_Simple_AddNoteFolder { Reset-InvokeCommandMock @@ -43,26 +38,21 @@ function Test_AddNotesToday_Simple_AvoidChildFolder { $category = "TestClient" $title = "This is the title of the note" - $date = (Get-Date).ToString("yyMMdd") - - $header = "# {category} - {title} ({date})" - $header = $header -replace "{category}", $category - $header = $header -replace "{title}", $title - $header = $header -replace "{date}", $date New-TestingFolder -Path "./TestNotesRoot/$category" - # Add note on the same folder using -AvoidChildFolder - $path = New-NoteToday $category $title -NoOpen -AvoidChildFolder - - $content = Get-Content -Path $path -Raw + # Add folder for the note -AddNoteFolder + $path = New-NoteToday $category $title -NoOpen -AddNoteFolder - Assert-IsTrue $content.StartsWith($header) + # File should be in a folder of its own name + $parentName = $path | Split-Path -Parent | Split-Path -Leaf + $fileNameBase = $path | Split-Path -LeafBase + Assert-AreEqual -Expected $fileNameBase -Presented $parentName + Assert-AreNotEqual -Expected $parentName -Presented $category # Parent folder should be child or category folder - $granParent = $path | Split-Path -Parent | Split-Path -Leaf + $granParent = $path | Split-Path -Parent | Split-Path -Parent | Split-Path -Leaf Assert-AreEqual -Expected $granParent -Presented $category - } function Test_AddNotesToday_WithContent { @@ -85,7 +75,7 @@ function Test_AddNotesToday_WithContent { New-TestingFolder -Path "./TestNotesRoot/$category" # Check Notes content - $path = New-NoteToday $category $title -NoOpen -AvoidChildFolder -Notes $notes + $path = New-NoteToday $category $title -NoOpen -Notes $notes $content = Get-Content -Path $path -Raw diff --git a/public/newNotes.ps1 b/public/newNotes.ps1 index 1c06d66..f3a3a79 100644 --- a/public/newNotes.ps1 +++ b/public/newNotes.ps1 @@ -142,7 +142,7 @@ function New-NoteToday{ [Parameter()][string] $IssueUrl, [Parameter()][string] [ValidateSet("none","meetingmini")] $Template = "none", [Parameter()][switch] $NoOpen, - [Parameter()][switch] $AvoidChildFolder, + [Parameter()][switch] $AddNoteFolder, [Parameter()][switch] $Force, [Parameter()][string] $RootPath ) @@ -174,10 +174,7 @@ function New-NoteToday{ # Create the note base folder - if($AvoidChildFolder){ - # use folder as the parent folder of the note - $fullPath = Join-Path -Path $folder -ChildPath "$fullTitle.md" - } else { + if($AddNoteFolder){ # Create full path for the note file $noteFolder = Join-Path -Path $folder -ChildPath $fullTitle @@ -187,8 +184,11 @@ function New-NoteToday{ } $fullPath =$noteFolder | Join-Path -ChildPath "$fullTitle.md" + } else { + # use folder as the parent folder of the note + $fullPath = Join-Path -Path $folder -ChildPath "$fullTitle.md" } - + # Check if file already exists if (-Not (Test-Path -Path $fullPath)) { @@ -260,8 +260,7 @@ function New-NoteTodayClient{ -Notes $Notes ` -IssueUrl $IssueUrl ` -Template "meetingmini" ` - -NoOpen:$NoOpen ` - -AvoidChildFolder # Add all the notes in the same client folder + -NoOpen:$NoOpen } } Export-ModuleMember -Function New-NoteTodayClient -Alias cnote @@ -300,8 +299,7 @@ function New-NoteTodayMeeting{ -Notes $Notes ` -IssueUrl $IssueUrl ` -Template "meetingmini" ` - -NoOpen:$NoOpen ` - -AvoidChildFolder # Add all the notes in the same client folder + -NoOpen:$NoOpen } } Export-ModuleMember -Function New-NoteTodayMeeting -Alias mnote \ No newline at end of file