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