github.com/ethanhsieh/snapd@v0.0.0-20210615102523-3db9b8e4edc5/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 37 var _ = Suite(&zenitySuite{}) 38 39 func (s *zenitySuite) TestYesNoSimpleYes(c *C) { 40 mock := testutil.MockCommand(c, "zenity", "") 41 defer mock.Restore() 42 43 z := &ui.Zenity{} 44 answeredYes := z.YesNo("primary", "secondary", nil) 45 c.Check(answeredYes, Equals, true) 46 c.Check(mock.Calls(), DeepEquals, [][]string{ 47 {"zenity", "--question", "--modal", "--text=<big><b>primary</b></big>\n\nsecondary"}, 48 }) 49 } 50 51 func (s *zenitySuite) TestYesNoSimpleNo(c *C) { 52 mock := testutil.MockCommand(c, "zenity", "false") 53 defer mock.Restore() 54 55 z := &ui.Zenity{} 56 answeredYes := z.YesNo("primary", "secondary", nil) 57 c.Check(answeredYes, Equals, false) 58 c.Check(mock.Calls(), DeepEquals, [][]string{ 59 {"zenity", "--question", "--modal", "--text=<big><b>primary</b></big>\n\nsecondary"}, 60 }) 61 } 62 63 func (s *zenitySuite) TestYesNoLong(c *C) { 64 mock := testutil.MockCommand(c, "zenity", "true") 65 defer mock.Restore() 66 67 z := &ui.Zenity{} 68 _ = z.YesNo("01234567890", "01234567890", nil) 69 c.Check(mock.Calls(), DeepEquals, [][]string{ 70 {"zenity", "--question", "--modal", "--text=<big><b>01234567890</b></big>\n\n01234567890", "--width=500"}, 71 }) 72 } 73 74 func (s *zenitySuite) TestYesNoSimpleFooter(c *C) { 75 mock := testutil.MockCommand(c, "zenity", "") 76 defer mock.Restore() 77 78 z := &ui.Zenity{} 79 answeredYes := z.YesNo("primary", "secondary", &ui.DialogOptions{Footer: "footer"}) 80 c.Check(answeredYes, Equals, true) 81 c.Check(mock.Calls(), DeepEquals, [][]string{ 82 {"zenity", "--question", "--modal", `--text=<big><b>primary</b></big> 83 84 secondary 85 86 <span size="x-small">footer</span>`}, 87 }) 88 } 89 90 func (s *zenitySuite) TestYesNoSimpleTimeout(c *C) { 91 mock := testutil.MockCommand(c, "zenity", "true") 92 defer mock.Restore() 93 94 z := &ui.Zenity{} 95 answeredYes := z.YesNo("primary", "secondary", &ui.DialogOptions{Timeout: 60 * time.Second}) 96 c.Check(answeredYes, Equals, true) 97 c.Check(mock.Calls(), DeepEquals, [][]string{ 98 {"zenity", "--question", "--modal", "--text=<big><b>primary</b></big>\n\nsecondary", "--timeout=60"}, 99 }) 100 }