github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/ui/ui_v6_test.go (about) 1 // +build !V7 2 3 package ui_test 4 5 import ( 6 "code.cloudfoundry.org/cli/util/configv3" 7 . "code.cloudfoundry.org/cli/util/ui" 8 "code.cloudfoundry.org/cli/util/ui/uifakes" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 ) 13 14 var _ = Describe("UI", func() { 15 var ( 16 ui *UI 17 fakeConfig *uifakes.FakeConfig 18 out *Buffer 19 errBuff *Buffer 20 ) 21 22 BeforeEach(func() { 23 fakeConfig = new(uifakes.FakeConfig) 24 fakeConfig.ColorEnabledReturns(configv3.ColorEnabled) 25 26 var err error 27 ui, err = NewUI(fakeConfig) 28 Expect(err).NotTo(HaveOccurred()) 29 30 out = NewBuffer() 31 ui.Out = out 32 ui.OutForInteration = out 33 errBuff = NewBuffer() 34 ui.Err = errBuff 35 }) 36 37 // Covers the happy paths, additional cases are tested in TranslateText 38 Describe("DisplayWarning", func() { 39 It("displays the warning to ui.Err", func() { 40 ui.DisplayWarning( 41 "template with {{.SomeMapValue}}", 42 map[string]interface{}{ 43 "SomeMapValue": "map-value", 44 }) 45 Expect(ui.Err).To(Say("template with map-value\n\n")) 46 }) 47 48 When("the locale is not set to english", func() { 49 BeforeEach(func() { 50 fakeConfig.LocaleReturns("fr-FR") 51 52 var err error 53 ui, err = NewUI(fakeConfig) 54 Expect(err).NotTo(HaveOccurred()) 55 56 ui.Err = NewBuffer() 57 }) 58 59 It("displays the translated warning to ui.Err", func() { 60 ui.DisplayWarning( 61 "'{{.VersionShort}}' and '{{.VersionLong}}' are also accepted.", 62 map[string]interface{}{ 63 "VersionShort": "some-value", 64 "VersionLong": "some-other-value", 65 }) 66 Expect(ui.Err).To(Say("'some-value' et 'some-other-value' sont également acceptés.\n")) 67 }) 68 }) 69 }) 70 71 // Covers the happy paths, additional cases are tested in TranslateText 72 Describe("DisplayWarnings", func() { 73 It("displays the warnings to ui.Err", func() { 74 ui.DisplayWarnings([]string{"warning-1", "warning-2"}) 75 Expect(ui.Err).To(Say("warning-1\n")) 76 Expect(ui.Err).To(Say("warning-2\n")) 77 Expect(ui.Err).To(Say("\n")) 78 }) 79 80 When("the locale is not set to english", func() { 81 BeforeEach(func() { 82 fakeConfig.LocaleReturns("fr-FR") 83 84 var err error 85 ui, err = NewUI(fakeConfig) 86 Expect(err).NotTo(HaveOccurred()) 87 88 ui.Err = NewBuffer() 89 }) 90 91 It("displays the translated warnings to ui.Err", func() { 92 ui.DisplayWarnings([]string{"Also delete any mapped routes", "FEATURE FLAGS"}) 93 Expect(ui.Err).To(Say("Supprimer aussi les routes mappées\n")) 94 Expect(ui.Err).To(Say("INDICATEURS DE FONCTION\n")) 95 Expect(ui.Err).To(Say("\n")) 96 }) 97 }) 98 99 Context("does not display newline when warnings are empty", func() { 100 It("does not print out a new line", func() { 101 ui.DisplayWarnings(nil) 102 Expect(errBuff.Contents()).To(BeEmpty()) 103 }) 104 }) 105 }) 106 })