github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/protocol/posthook/continue_render_test.go (about)

     1  // Copyright (c) 2021 Terminus, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package posthook
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  
    22  	"github.com/erda-project/erda-infra/providers/component-protocol/cptype"
    23  )
    24  
    25  func TestHandleContinueRender(t *testing.T) {
    26  	renderingItems := []cptype.RendingItem{{Name: "page"}, {Name: "list"}}
    27  	p := cptype.ComponentProtocol{
    28  		Components: map[string]*cptype.Component{
    29  			"page": {
    30  				Options: &cptype.ComponentOptions{
    31  					ContinueRender: &cptype.ContinueRender{
    32  						OpKey: "loadPageMore",
    33  					},
    34  				},
    35  			},
    36  			"list": {
    37  				Options: &cptype.ComponentOptions{
    38  					ContinueRender: &cptype.ContinueRender{
    39  						OpKey: "loadListDetail",
    40  					},
    41  				},
    42  			},
    43  		},
    44  		Options: nil,
    45  	}
    46  	HandleContinueRender(renderingItems, &p)
    47  	assert.NotNil(t, p.Options)
    48  	assert.True(t, len(p.Options.ParallelContinueRenders) == 2)
    49  	assert.True(t, p.Options.ParallelContinueRenders["page"].OpKey == "loadPageMore")
    50  	assert.True(t, p.Options.ParallelContinueRenders["list"].OpKey == "loadListDetail")
    51  }