Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions Test/public/newNotes.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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 {
Expand All @@ -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

Expand Down
18 changes: 8 additions & 10 deletions public/newNotes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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

Expand All @@ -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)) {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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