-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved markdown output (#271)
* feat: improved markdown output * fix: not used
- Loading branch information
1 parent
a292ee7
commit 90eba3b
Showing
8 changed files
with
364 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{{- $project := "" -}} | ||
{{- if eq .Project nil }} | ||
{{- $project = "No Project" -}} | ||
{{- else -}} | ||
{{- $project = concat "**" .Project.Name "**" -}} | ||
{{- if ne .Task nil -}} | ||
{{- $project = concat $project ": " .Task.Name -}} | ||
{{- else if ne .Project.ClientName "" -}} | ||
{{- $project = concat $project " - " .Project.ClientName -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- $bil := "No" -}} | ||
{{- if .Billable -}}{{ $bil = "Yes" }}{{- end -}} | ||
|
||
{{- $tags := "" -}} | ||
{{- with .Tags -}} | ||
{{- range $index, $element := . -}} | ||
{{- if ne $index 0 }}{{ $tags = concat $tags ", " }}{{ end -}} | ||
{{- $tags = concat $tags $element.Name -}} | ||
{{- end -}} | ||
{{- else -}} | ||
{{- $tags = "No Tags" -}} | ||
{{- end -}} | ||
|
||
{{- $pad := maxLength .Description $project $tags $bil -}} | ||
|
||
## _Time Entry_: {{ .ID }} | ||
|
||
_Time and date_ | ||
**{{ dsf .TimeInterval.Duration }}** | {{ if eq .TimeInterval.End nil -}} | ||
Start Time: _{{ formatTimeWS .TimeInterval.Start }}_ 🗓 Today | ||
{{- else -}} | ||
{{ formatTimeWS .TimeInterval.Start }} - {{ formatTimeWS .TimeInterval.End }} 🗓 | ||
{{- .TimeInterval.Start.Format " 01/02/2006" }} | ||
{{- end }} | ||
|
||
| | {{ pad "" $pad }} | | ||
|---------------|-{{ repeatString "-" $pad }}-| | ||
| _Description_ | {{ pad .Description $pad }} | | ||
| _Project_ | {{ pad $project $pad }} | | ||
| _Tags_ | {{ pad $tags $pad }} | | ||
| _Billable_ | {{ pad $bil $pad }} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
package timeentry_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/lucassabreu/clockify-cli/api/dto" | ||
timeentry "github.com/lucassabreu/clockify-cli/pkg/output/time-entry" | ||
"github.com/lucassabreu/clockify-cli/pkg/timehlp" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTimeEntriesMarkdownPrint(t *testing.T) { | ||
t65Min1SecAgo, _ := timehlp.ConvertToTime("-65m1s") | ||
start, _ := time.Parse(timehlp.FullTimeFormat, "2024-06-15 10:00:01") | ||
end := start.Add(2*time.Minute + 1*time.Second) | ||
|
||
tts := []struct { | ||
name string | ||
tes []dto.TimeEntry | ||
output string | ||
}{ | ||
{ | ||
name: "open without tags or project", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: false, | ||
Description: "Open and without project", | ||
TimeInterval: dto.NewTimeInterval(t65Min1SecAgo, nil), | ||
}}, | ||
output: heredoc.Docf(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**1:05:01** | Start Time: _%s_ 🗓 Today | ||
| | | | ||
|---------------|--------------------------| | ||
| _Description_ | Open and without project | | ||
| _Project_ | No Project | | ||
| _Tags_ | No Tags | | ||
| _Billable_ | No | | ||
`, t65Min1SecAgo.UTC().Format(timehlp.SimplerOnlyTimeFormat)), | ||
}, | ||
{ | ||
name: "closed without tags or project", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: false, | ||
Description: "Closed and without project", | ||
TimeInterval: dto.NewTimeInterval( | ||
start, | ||
&end, | ||
), | ||
}}, | ||
output: heredoc.Doc(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**0:02:01** | 10:00 - 10:02 🗓 06/15/2024 | ||
| | | | ||
|---------------|----------------------------| | ||
| _Description_ | Closed and without project | | ||
| _Project_ | No Project | | ||
| _Tags_ | No Tags | | ||
| _Billable_ | No | | ||
`), | ||
}, | ||
{ | ||
name: "Closed with project", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: false, | ||
Description: "With project", | ||
Project: &dto.Project{ | ||
Name: "Project Name", | ||
}, | ||
TimeInterval: dto.NewTimeInterval( | ||
start, | ||
&end, | ||
), | ||
}}, | ||
output: heredoc.Doc(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**0:02:01** | 10:00 - 10:02 🗓 06/15/2024 | ||
| | | | ||
|---------------|------------------| | ||
| _Description_ | With project | | ||
| _Project_ | **Project Name** | | ||
| _Tags_ | No Tags | | ||
| _Billable_ | No | | ||
`), | ||
}, | ||
{ | ||
name: "Closed with project with client", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: true, | ||
Description: "With project", | ||
Project: &dto.Project{ | ||
Name: "Project Name", | ||
ClientName: "Client Name", | ||
}, | ||
TimeInterval: dto.NewTimeInterval( | ||
start, | ||
&end, | ||
), | ||
}}, | ||
output: heredoc.Doc(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**0:02:01** | 10:00 - 10:02 🗓 06/15/2024 | ||
| | | | ||
|---------------|--------------------------------| | ||
| _Description_ | With project | | ||
| _Project_ | **Project Name** - Client Name | | ||
| _Tags_ | No Tags | | ||
| _Billable_ | Yes | | ||
`), | ||
}, | ||
{ | ||
name: "Closed with project, client and task", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: true, | ||
Description: "With project", | ||
Project: &dto.Project{ | ||
Name: "Project Name", | ||
ClientName: "Client Name", | ||
}, | ||
Task: &dto.Task{ | ||
Name: "Task Name", | ||
}, | ||
TimeInterval: dto.NewTimeInterval( | ||
start, | ||
&end, | ||
), | ||
}}, | ||
output: heredoc.Doc(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**0:02:01** | 10:00 - 10:02 🗓 06/15/2024 | ||
| | | | ||
|---------------|-----------------------------| | ||
| _Description_ | With project | | ||
| _Project_ | **Project Name**: Task Name | | ||
| _Tags_ | No Tags | | ||
| _Billable_ | Yes | | ||
`), | ||
}, | ||
{ | ||
name: "Closed with project, client, task and a tag", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: true, | ||
Description: "With project", | ||
Project: &dto.Project{ | ||
Name: "Project Name", | ||
ClientName: "Client Name", | ||
}, | ||
Task: &dto.Task{ | ||
Name: "Task Name", | ||
}, | ||
Tags: []dto.Tag{ | ||
{Name: "Stand-up Meeting"}, | ||
}, | ||
TimeInterval: dto.NewTimeInterval( | ||
start, | ||
&end, | ||
), | ||
}}, | ||
output: heredoc.Doc(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**0:02:01** | 10:00 - 10:02 🗓 06/15/2024 | ||
| | | | ||
|---------------|-----------------------------| | ||
| _Description_ | With project | | ||
| _Project_ | **Project Name**: Task Name | | ||
| _Tags_ | Stand-up Meeting | | ||
| _Billable_ | Yes | | ||
`), | ||
}, | ||
{ | ||
name: "Closed with project, client, task and tags", | ||
tes: []dto.TimeEntry{{ | ||
WorkspaceID: "w1", | ||
ID: "te1", | ||
Billable: true, | ||
Description: "With project", | ||
Project: &dto.Project{ | ||
Name: "Project Name", | ||
ClientName: "Client Name", | ||
}, | ||
Task: &dto.Task{ | ||
Name: "Task Name", | ||
}, | ||
Tags: []dto.Tag{ | ||
{Name: "A Tag with long name"}, | ||
{Name: "Normal tag"}, | ||
}, | ||
TimeInterval: dto.NewTimeInterval( | ||
start, | ||
&end, | ||
), | ||
}}, | ||
output: heredoc.Doc(` | ||
## _Time Entry_: te1 | ||
_Time and date_ | ||
**0:02:01** | 10:00 - 10:02 🗓 06/15/2024 | ||
| | | | ||
|---------------|----------------------------------| | ||
| _Description_ | With project | | ||
| _Project_ | **Project Name**: Task Name | | ||
| _Tags_ | A Tag with long name, Normal tag | | ||
| _Billable_ | Yes | | ||
`), | ||
}, | ||
} | ||
|
||
for _, tt := range tts { | ||
t.Run(tt.name, func(t *testing.T) { | ||
buffer := &strings.Builder{} | ||
err := timeentry.TimeEntriesMarkdownPrint(tt.tes, buffer) | ||
|
||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
assert.Equal(t, tt.output+"\n", buffer.String()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.