github.com/rigado/snapd@v2.42.5-go-mod+incompatible/usersession/userd/ui/kdialog_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 . "gopkg.in/check.v1" 26 27 "github.com/snapcore/snapd/testutil" 28 "github.com/snapcore/snapd/usersession/userd/ui" 29 ) 30 31 type kdialogSuite struct { 32 mock *testutil.MockCmd 33 } 34 35 var _ = Suite(&kdialogSuite{}) 36 37 func (s *kdialogSuite) TestYesNoSimpleYes(c *C) { 38 mock := testutil.MockCommand(c, "kdialog", "") 39 defer mock.Restore() 40 41 z := &ui.KDialog{} 42 answeredYes := z.YesNo("primary", "secondary", nil) 43 c.Check(answeredYes, Equals, true) 44 c.Check(mock.Calls(), DeepEquals, [][]string{ 45 {"kdialog", "--yesno=<p><big><b>primary</b></big></p><p>secondary</p>"}, 46 }) 47 } 48 49 func (s *kdialogSuite) TestYesNoSimpleNo(c *C) { 50 mock := testutil.MockCommand(c, "kdialog", "false") 51 defer mock.Restore() 52 53 z := &ui.KDialog{} 54 answeredYes := z.YesNo("primary", "secondary", nil) 55 c.Check(answeredYes, Equals, false) 56 c.Check(mock.Calls(), DeepEquals, [][]string{ 57 {"kdialog", "--yesno=<p><big><b>primary</b></big></p><p>secondary</p>"}, 58 }) 59 } 60 61 func (s *kdialogSuite) TestYesNoSimpleFooter(c *C) { 62 mock := testutil.MockCommand(c, "kdialog", "") 63 defer mock.Restore() 64 65 z := &ui.KDialog{} 66 answeredYes := z.YesNo("primary", "secondary", &ui.DialogOptions{Footer: "footer"}) 67 c.Check(answeredYes, Equals, true) 68 c.Check(mock.Calls(), DeepEquals, [][]string{ 69 {"kdialog", "--yesno=<p><big><b>primary</b></big></p><p>secondary</p><p><small>footer</small></p>"}, 70 }) 71 } 72 73 func (s *kdialogSuite) TestYesNoSimpleTimeout(c *C) { 74 mock := testutil.MockCommand(c, "kdialog", "sleep 9999999") 75 defer mock.Restore() 76 77 z := &ui.KDialog{} 78 answeredYes := z.YesNo("primary", "secondary", &ui.DialogOptions{Timeout: 1 * time.Second}) 79 // this got auto-canceled after 1sec 80 c.Check(answeredYes, Equals, false) 81 c.Check(mock.Calls(), DeepEquals, [][]string{ 82 {"kdialog", "--yesno=<p><big><b>primary</b></big></p><p>secondary</p>"}, 83 }) 84 }