pane_view_internal_test.go RawHistoryFolder
1package component
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 "github.com/stretchr/testify/mock"
8
9 "github.com/bnema/dumber/internal/ui/layout"
10 "github.com/bnema/dumber/internal/ui/layout/mocks"
11)
12
13func TestPaneView_HideLoadingSkeleton_HidesWhenPresent(t *testing.T) {
14 mockFactory := mocks.NewMockWidgetFactory(t)
15 mockContainer := mocks.NewMockBoxWidget(t)
16 mockContent := mocks.NewMockBoxWidget(t)
17 mockSpinner := mocks.NewMockSpinnerWidget(t)
18 mockLogo := mocks.NewMockImageWidget(t)
19 mockVersion := mocks.NewMockLabelWidget(t)
20
21 mockFactory.EXPECT().NewBox(layout.OrientationVertical, 0).Return(mockContainer).Once()
22 mockContainer.EXPECT().SetHexpand(true).Once()
23 mockContainer.EXPECT().SetVexpand(true).Once()
24 mockContainer.EXPECT().SetHalign(mock.Anything).Once()
25 mockContainer.EXPECT().SetValign(mock.Anything).Once()
26 mockContainer.EXPECT().SetCanFocus(false).Once()
27 mockContainer.EXPECT().SetCanTarget(false).Once()
28 mockContainer.EXPECT().AddCssClass("loading-skeleton").Once()
29
30 mockFactory.EXPECT().NewBox(layout.OrientationVertical, 6).Return(mockContent).Once()
31 mockContent.EXPECT().SetHalign(mock.Anything).Once()
32 mockContent.EXPECT().SetValign(mock.Anything).Once()
33 mockContent.EXPECT().SetCanFocus(false).Once()
34 mockContent.EXPECT().SetCanTarget(false).Once()
35 mockContent.EXPECT().AddCssClass("loading-skeleton-content").Once()
36
37 mockFactory.EXPECT().NewImage().Return(mockLogo).Once()
38 mockLogo.EXPECT().SetHalign(mock.Anything).Once()
39 mockLogo.EXPECT().SetValign(mock.Anything).Once()
40 mockLogo.EXPECT().SetCanFocus(false).Once()
41 mockLogo.EXPECT().SetCanTarget(false).Once()
42 mockLogo.EXPECT().SetSizeRequest(mock.Anything, mock.Anything).Once()
43 mockLogo.EXPECT().SetPixelSize(mock.Anything).Once()
44 mockLogo.EXPECT().AddCssClass("loading-skeleton-logo").Once()
45 mockLogo.EXPECT().SetFromPaintable(mock.Anything).Maybe()
46
47 mockFactory.EXPECT().NewSpinner().Return(mockSpinner).Once()
48 mockSpinner.EXPECT().SetHalign(mock.Anything).Once()
49 mockSpinner.EXPECT().SetValign(mock.Anything).Once()
50 mockSpinner.EXPECT().SetCanFocus(false).Once()
51 mockSpinner.EXPECT().SetCanTarget(false).Once()
52 mockSpinner.EXPECT().SetSizeRequest(mock.Anything, mock.Anything).Once()
53 mockSpinner.EXPECT().AddCssClass("loading-skeleton-spinner").Once()
54
55 mockFactory.EXPECT().NewLabel(mock.Anything).Return(mockVersion).Once()
56 mockVersion.EXPECT().SetHalign(mock.Anything).Once()
57 mockVersion.EXPECT().SetValign(mock.Anything).Once()
58 mockVersion.EXPECT().SetCanFocus(false).Once()
59 mockVersion.EXPECT().SetCanTarget(false).Once()
60 mockVersion.EXPECT().SetMaxWidthChars(mock.Anything).Once()
61 mockVersion.EXPECT().SetEllipsize(mock.Anything).Once()
62 mockVersion.EXPECT().AddCssClass("loading-skeleton-version").Once()
63
64 mockContent.EXPECT().Append(mockLogo).Once()
65 mockContent.EXPECT().Append(mockSpinner).Once()
66 mockContent.EXPECT().Append(mockVersion).Once()
67 mockContainer.EXPECT().Append(mockContent).Once()
68
69 mockContainer.EXPECT().SetVisible(true).Once()
70 mockSpinner.EXPECT().Start().Once()
71 ls := NewLoadingSkeleton(mockFactory)
72
73 pv := &PaneView{loading: ls}
74
75 mockContainer.EXPECT().SetVisible(false).Once()
76 mockSpinner.EXPECT().Stop().Once()
77 pv.HideLoadingSkeleton()
78}
79
80func TestPaneView_HideLoadingSkeleton_NoOpWhenNil(t *testing.T) {
81 pv := &PaneView{}
82 pv.HideLoadingSkeleton()
83}
84
85func TestPaneView_AttachWebViewWidget_RevealedThenUnrevealedReplacementRestartsSkeleton(t *testing.T) {
86 overlay := mocks.NewMockOverlayWidget(t)
87 revealedWidget := mocks.NewMockWidget(t)
88 unrevealedWidget := mocks.NewMockWidget(t)
89 loadingContainer := mocks.NewMockBoxWidget(t)
90 spinner := mocks.NewMockSpinnerWidget(t)
91
92 overlay.EXPECT().GetAllocatedWidth().Return(0).Times(4)
93 overlay.EXPECT().GetAllocatedHeight().Return(0).Times(4)
94 for _, widget := range []*mocks.MockWidget{revealedWidget, unrevealedWidget} {
95 widget.EXPECT().GetAllocatedWidth().Return(0).Twice()
96 widget.EXPECT().GetAllocatedHeight().Return(0).Twice()
97 widget.EXPECT().GetParent().Return(nil).Once()
98 widget.EXPECT().IsVisible().Return(true).Once()
99 }
100 overlay.EXPECT().SetChild(revealedWidget).Once()
101 loadingContainer.EXPECT().SetVisible(false).Once()
102 spinner.EXPECT().Stop().Once()
103 overlay.EXPECT().SetChild(nil).Once()
104 overlay.EXPECT().SetChild(unrevealedWidget).Once()
105 loadingContainer.EXPECT().SetVisible(true).Once()
106 spinner.EXPECT().Start().Once()
107
108 pv := &PaneView{
109 overlay: overlay,
110 loading: &LoadingSkeleton{container: loadingContainer, spinner: spinner},
111 }
112
113 pv.AttachWebViewWidget(revealedWidget, true)
114 pv.AttachWebViewWidget(unrevealedWidget, false)
115
116 assert.Same(t, unrevealedWidget, pv.WebViewWidget())
117}