forked from deanishe/awgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_feedback_test.go
80 lines (63 loc) · 1.77 KB
/
workflow_feedback_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2019 Dean Jackson <[email protected]>
// MIT Licence applies http://opensource.org/licenses/MIT
package aw
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
)
func TestItemHelpers(t *testing.T) {
t.Parallel()
var (
wf = New()
data []byte
err error
)
it := wf.NewWarningItem("Warn Title", "Warn subtitle")
x := `{"title":"Warn Title","subtitle":"Warn subtitle","valid":false,"icon":{"path":"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns"}}`
if data, err = json.Marshal(it); err != nil {
t.Fatalf("marshal Item: %v", err)
}
js := string(data)
if js != x {
t.Errorf("Bad Warning Item. Expected=%v, Got=%v", x, js)
}
it = wf.NewFileItem("/Volumes")
x = `{"title":"Volumes","subtitle":"/Volumes","autocomplete":"Volumes","arg":"/Volumes","uid":"/Volumes","valid":true,"type":"file","icon":{"path":"/Volumes","type":"fileicon"}}`
if data, err = json.Marshal(it); err != nil {
t.Fatalf("marshal Item: %v", err)
}
js = string(data)
if js != x {
t.Errorf("Bad File Item. Expected=%v, Got=%v", x, js)
}
}
func TestNewFileItem(t *testing.T) {
t.Parallel()
var (
wf = New()
ipPath = filepath.Join(wf.Dir(), "info.plist")
ipShort = strings.Replace(ipPath, os.Getenv("HOME"), "~", -1)
it = wf.NewFileItem(ipPath)
)
if it.title != "info.plist" {
t.Fatalf("Incorrect title: %v", it.title)
}
if *it.subtitle != ipShort {
t.Fatalf("Incorrect subtitle: %v", *it.subtitle)
}
if *it.uid != ipPath {
t.Fatalf("Incorrect UID: %v", *it.uid)
}
if it.file != true {
t.Fatalf("Incorrect file: %v", it.file)
}
if it.icon.Type != "fileicon" {
t.Fatalf("Incorrect type: %v", it.icon.Type)
}
if it.icon.Value != ipPath {
t.Fatalf("Incorrect Value: %v", it.icon.Value)
}
}