github.com/rigado/snapd@v2.42.5-go-mod+incompatible/usersession/userd/ui/zenity_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package ui_test 21 22 import ( 23 "time" 24 25 "testing" 26 27 . "gopkg.in/check.v1" 28 29 "github.com/snapcore/snapd/testutil" 30 "github.com/snapcore/snapd/usersession/userd/ui" 31 ) 32 33 func Test(t *testing.T) { TestingT(t) } 34 35 type zenitySuite struct { 36 mock *testutil.MockCmd 37 } 38 39 var _ = Suite(&zenitySuite{}) 40 41 func (s *zenitySuite) TestYesNoSimpleYes(c *C) { 42 mock := testutil.MockCommand(c, "zenity", "") 43 defer mock.Restore() 44 45 z := &ui.Zenity{} 46 answeredYes := z.YesNo("primary", "secondary", nil) 47 c.Check(answeredYes, Equals, true) 48 c.Check(mock.Calls(), DeepEquals, [][]string{ 49 {"zenity", "--question", "--modal", "--text=<big><b>primary</b></big>\n\nsecondary"}, 50 }) 51 } 52 53 func (s *zenitySuite) TestYesNoSimpleNo(c *C) { 54 mock := testutil.MockCommand(c, "zenity", "false") 55 defer mock.Restore() 56 57 z := &ui.Zenity{} 58 answeredYes := z.YesNo("primary", "secondary", nil) 59 c.Check(answeredYes, Equals, false) 60 c.Check(mock.Calls(), DeepEquals, [][]string{ 61 {"zenity", "--question", "--modal", "--text=<big><b>primary</b></big>\n\nsecondary"}, 62 }) 63 } 64 65 func (s *zenitySuite) TestYesNoLong(c *C) { 66 mock := testutil.MockCommand(c, "zenity", "true") 67 defer mock.Restore() 68 69 z := &ui.Zenity{} 70 _ = z.YesNo("01234567890", "01234567890", nil) 71 c.Check(mock.Calls(), DeepEquals, [][]string{ 72 {"zenity", "--question", "--modal", "--text=<big><b>01234567890</b></big>\n\n01234567890", "--width=500"}, 73 }) 74 } 75 76 func (s *zenitySuite) TestYesNoSimpleFooter(c *C) { 77 mock := testutil.MockCommand(c, "zenity", "") 78 defer mock.Restore() 79 80 z := &ui.Zenity{} 81 answeredYes := z.YesNo("primary", "secondary", &ui.DialogOptions{Footer: "footer"}) 82 c.Check(answeredYes, Equals, true) 83 c.Check(mock.Calls(), DeepEquals, [][]string{ 84 {"zenity", "--question", "--modal", `--text=<big><b>primary</b></big> 85 86 secondary 87 88 <span size="x-small">footer</span>`}, 89 }) 90 } 91 92 func (s *zenitySuite) TestYesNoSimpleTimeout(c *C) { 93 mock := testutil.MockCommand(c, "zenity", "true") 94 defer mock.Restore() 95 96 z := &ui.Zenity{} 97 answeredYes := z.YesNo("primary", "secondary", &ui.DialogOptions{Timeout: 60 * time.Second}) 98 c.Check(answeredYes, Equals, true) 99 c.Check(mock.Calls(), DeepEquals, [][]string{ 100 {"zenity", "--question", "--modal", "--text=<big><b>primary</b></big>\n\nsecondary", "--timeout=60"}, 101 }) 102 }