github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/ui/ui_v7_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("DisplayWarnings", func() {
    39  		It("displays the warnings to ui.Err", func() {
    40  			ui.DisplayWarnings([]string{"warning-1", "warning-2"})
    41  			Expect(ui.Err).To(Say("warning-1\n"))
    42  			Expect(ui.Err).To(Say("warning-2\n"))
    43  		})
    44  
    45  		When("the locale is not set to english", func() {
    46  			BeforeEach(func() {
    47  				fakeConfig.LocaleReturns("fr-FR")
    48  
    49  				var err error
    50  				ui, err = NewUI(fakeConfig)
    51  				Expect(err).NotTo(HaveOccurred())
    52  
    53  				errBuff = NewBuffer()
    54  				ui.Err = errBuff
    55  			})
    56  
    57  			When("there are multiple warnings", func() {
    58  				It("displays translated warnings to ui.Err", func() {
    59  					ui.DisplayWarnings([]string{"un-translateable warning", "FEATURE FLAGS", "Number of instances"})
    60  					Expect(string(errBuff.Contents())).To(Equal("un-translateable warning\nINDICATEURS DE FONCTION\nNombre d'instances\n"))
    61  				})
    62  			})
    63  
    64  			When("there is a single warning ", func() {
    65  				It("displays the translated warning to ui.Err", func() {
    66  					ui.DisplayWarnings([]string{"un-translateable warning"})
    67  					Expect(string(errBuff.Contents())).To(Equal("un-translateable warning\n"))
    68  				})
    69  			})
    70  
    71  			Context("there are no warnings", func() {
    72  				It("does not print out a new line", func() {
    73  					ui.DisplayWarnings(nil)
    74  					Expect(errBuff.Contents()).To(BeEmpty())
    75  				})
    76  			})
    77  		})
    78  	})
    79  })