Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-4241: The name of the Space member is not displayed #1741

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions core/block/editor/participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (p *participant) Init(ctx *smartblock.InitContext) (err error) {
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyLayout, pbtypes.Int64(int64(model.ObjectType_participant)))
ctx.State.SetDetailAndBundledRelation(bundle.RelationKeyLayoutAlign, pbtypes.Int64(int64(model.Block_AlignCenter)))

records, err := p.objectStore.QueryByIds([]string{p.Id()})
if err != nil {
return err
}
if len(records) > 0 {
ctx.State.SetDetails(records[0].Details)
}
template.InitTemplate(ctx.State,
template.WithEmpty,
template.WithTitle,
Expand All @@ -63,15 +70,6 @@ func (p *participant) Init(ctx *smartblock.InitContext) (err error) {
template.WithAddedFeaturedRelation(bundle.RelationKeyType),
template.WithAddedFeaturedRelation(bundle.RelationKeyBacklinks),
)

records, err := p.objectStore.QueryByIds([]string{p.Id()})
if err != nil {
return err
}
if len(records) > 0 {
ctx.State.SetDetails(records[0].Details)
}

return nil
}

Expand Down
64 changes: 64 additions & 0 deletions core/block/editor/participant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package editor
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/anyproto/anytype-heart/core/block/editor/basic"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock/smarttest"
"github.com/anyproto/anytype-heart/core/block/editor/state"
"github.com/anyproto/anytype-heart/core/block/migration"
"github.com/anyproto/anytype-heart/core/domain"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
Expand Down Expand Up @@ -111,6 +113,68 @@ func TestParticipant_ModifyIdentityDetails(t *testing.T) {
}
}

func TestParticipant_Init(t *testing.T) {
t.Run("title block not empty, because name detail is in store", func(t *testing.T) {
// given
sb := smarttest.New("root")
store := newStoreFixture(t)
store.AddObjects(t, []objectstore.TestObject{{
bundle.RelationKeySpaceId: pbtypes.String("spaceId"),
bundle.RelationKeyId: pbtypes.String("root"),
bundle.RelationKeyName: pbtypes.String("test"),
}})

basicComponent := basic.NewBasic(sb, store, nil, nil, nil)
p := &participant{
SmartBlock: sb,
DetailsUpdatable: basicComponent,
objectStore: store,
}

initCtx := &smartblock.InitContext{
IsNewObject: true,
}

// when
err := p.Init(initCtx)
assert.NoError(t, err)
migration.RunMigrations(p, initCtx)
err = p.Apply(initCtx.State)
assert.NoError(t, err)

// then
assert.NotNil(t, p.NewState().Get(state.TitleBlockID))
assert.Equal(t, "test", p.NewState().Get(state.TitleBlockID).Model().GetText().GetText())
})
t.Run("title block is empty", func(t *testing.T) {
// given
sb := smarttest.New("root")
store := newStoreFixture(t)

basicComponent := basic.NewBasic(sb, store, nil, nil, nil)
p := &participant{
SmartBlock: sb,
DetailsUpdatable: basicComponent,
objectStore: store,
}

initCtx := &smartblock.InitContext{
IsNewObject: true,
}

// when
err := p.Init(initCtx)
assert.NoError(t, err)
migration.RunMigrations(p, initCtx)
err = p.Apply(initCtx.State)
assert.NoError(t, err)

// then
assert.NotNil(t, p.NewState().Get(state.TitleBlockID))
assert.Equal(t, "", p.NewState().Get(state.TitleBlockID).Model().GetText().GetText())
})
}

func newStoreFixture(t *testing.T) *spaceindex.StoreFixture {
store := spaceindex.NewStoreFixture(t)

Expand Down
Loading