mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-21 13:38:56 +02:00
f915a20c64
* Working in the new content block editor * Moving blocksEditor content block into its own component * Initial integration with quick development flow * More WIP * Adding drag and drop support with server side help * Some extra work around the styles * Adding image support * Adding video and attachments, and fixing edit * Putting everything behind a feature flag * Adding support for download attachments * Fixing compilation error * Fixing linter errors * Fixing javascript tests * Fixing a typescript error * Moving the move block to an action with undo support * Fixing ci * Fixing post merge errors * Moving to more specific content-blocks api * Apply suggestions from code review Co-authored-by: Doug Lauder <wiggin77@warpmail.net> * Fixing the behavior of certain blocks * Fixing linter error * Fixing javascript linter errors * Adding permission testing for the new move content block api * Adding some unit tests * Improving a bit the tests * Adding more unit tests to the backend * Fixed PR suggestion * Adding h1, h2 and h3 tests * Adding image tests * Adding video tests * Adding attachment tests * Adding quote block tests * Adding divider tests * Adding checkbox tests * Adding list item block tests * Adding text block tests * Reorganizing a bit the code to support deveditor eagain * Fixing dark theme on editor view * Fixing linter errors * Fixing tests and removing unneeded data-testid * Adding root input tests * Fixing some merge problems * Fixing text/text.test.tsx test * Adding more unit tests to the blocks editor * Fix linter error * Adding blocksEditor tests * Fixing linter errors * Adding tests for blockContent * Update webapp/src/components/blocksEditor/blockContent.test.tsx Fix linter warning * Update webapp/src/components/blocksEditor/blockContent.test.tsx Fix linter warning * Update webapp/src/components/blocksEditor/blockContent.test.tsx Fix linter error * Fixing test * Removing unneeded TODO Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
183 lines
4.9 KiB
Go
183 lines
4.9 KiB
Go
package integrationtests
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMoveContentBlock(t *testing.T) {
|
|
th := SetupTestHelperWithToken(t).Start()
|
|
defer th.TearDown()
|
|
|
|
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
|
|
|
cardID1 := utils.NewID(utils.IDTypeBlock)
|
|
cardID2 := utils.NewID(utils.IDTypeBlock)
|
|
contentBlockID1 := utils.NewID(utils.IDTypeBlock)
|
|
contentBlockID2 := utils.NewID(utils.IDTypeBlock)
|
|
contentBlockID3 := utils.NewID(utils.IDTypeBlock)
|
|
contentBlockID4 := utils.NewID(utils.IDTypeBlock)
|
|
contentBlockID5 := utils.NewID(utils.IDTypeBlock)
|
|
contentBlockID6 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
card1 := &model.Block{
|
|
ID: cardID1,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
Fields: map[string]interface{}{
|
|
"contentOrder": []string{contentBlockID1, contentBlockID2, contentBlockID3},
|
|
},
|
|
}
|
|
card2 := &model.Block{
|
|
ID: cardID2,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
Fields: map[string]interface{}{
|
|
"contentOrder": []string{contentBlockID4, contentBlockID5, contentBlockID6},
|
|
},
|
|
}
|
|
|
|
contentBlock1 := &model.Block{
|
|
ID: contentBlockID1,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
ParentID: cardID1,
|
|
}
|
|
contentBlock2 := &model.Block{
|
|
ID: contentBlockID2,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
ParentID: cardID1,
|
|
}
|
|
contentBlock3 := &model.Block{
|
|
ID: contentBlockID3,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
ParentID: cardID1,
|
|
}
|
|
contentBlock4 := &model.Block{
|
|
ID: contentBlockID4,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
ParentID: cardID2,
|
|
}
|
|
contentBlock5 := &model.Block{
|
|
ID: contentBlockID5,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
ParentID: cardID2,
|
|
}
|
|
contentBlock6 := &model.Block{
|
|
ID: contentBlockID6,
|
|
BoardID: board.ID,
|
|
CreateAt: 1,
|
|
UpdateAt: 1,
|
|
Type: model.TypeCard,
|
|
ParentID: cardID2,
|
|
}
|
|
|
|
newBlocks := []*model.Block{
|
|
contentBlock1,
|
|
contentBlock2,
|
|
contentBlock3,
|
|
contentBlock4,
|
|
contentBlock5,
|
|
contentBlock6,
|
|
card1,
|
|
card2,
|
|
}
|
|
createdBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks, false)
|
|
require.NoError(t, resp.Error)
|
|
require.Len(t, newBlocks, 8)
|
|
|
|
contentBlock1.ID = createdBlocks[0].ID
|
|
contentBlock2.ID = createdBlocks[1].ID
|
|
contentBlock3.ID = createdBlocks[2].ID
|
|
contentBlock4.ID = createdBlocks[3].ID
|
|
contentBlock5.ID = createdBlocks[4].ID
|
|
contentBlock6.ID = createdBlocks[5].ID
|
|
card1.ID = createdBlocks[6].ID
|
|
card2.ID = createdBlocks[7].ID
|
|
|
|
ttCases := []struct {
|
|
name string
|
|
srcBlockID string
|
|
dstBlockID string
|
|
where string
|
|
userID string
|
|
errorMessage string
|
|
expectedContentOrder []interface{}
|
|
}{
|
|
{
|
|
name: "not matching parents",
|
|
srcBlockID: contentBlock1.ID,
|
|
dstBlockID: contentBlock4.ID,
|
|
where: "after",
|
|
userID: "user-id",
|
|
errorMessage: fmt.Sprintf("payload: {\"error\":\"not matching parent %s and %s\",\"errorCode\":400}", card1.ID, card2.ID),
|
|
expectedContentOrder: []interface{}{contentBlock1.ID, contentBlock2.ID, contentBlock3.ID},
|
|
},
|
|
{
|
|
name: "valid request with not real change",
|
|
srcBlockID: contentBlock2.ID,
|
|
dstBlockID: contentBlock1.ID,
|
|
where: "after",
|
|
userID: "user-id",
|
|
errorMessage: "",
|
|
expectedContentOrder: []interface{}{contentBlock1.ID, contentBlock2.ID, contentBlock3.ID},
|
|
},
|
|
{
|
|
name: "valid request changing order with before",
|
|
srcBlockID: contentBlock2.ID,
|
|
dstBlockID: contentBlock1.ID,
|
|
where: "before",
|
|
userID: "user-id",
|
|
errorMessage: "",
|
|
expectedContentOrder: []interface{}{contentBlock2.ID, contentBlock1.ID, contentBlock3.ID},
|
|
},
|
|
{
|
|
name: "valid request changing order with after",
|
|
srcBlockID: contentBlock1.ID,
|
|
dstBlockID: contentBlock2.ID,
|
|
where: "after",
|
|
userID: "user-id",
|
|
errorMessage: "",
|
|
expectedContentOrder: []interface{}{contentBlock2.ID, contentBlock1.ID, contentBlock3.ID},
|
|
},
|
|
}
|
|
|
|
for _, tc := range ttCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
_, resp := th.Client.MoveContentBlock(tc.srcBlockID, tc.dstBlockID, tc.where, tc.userID)
|
|
if tc.errorMessage == "" {
|
|
require.NoError(t, resp.Error)
|
|
} else {
|
|
require.EqualError(t, resp.Error, tc.errorMessage)
|
|
}
|
|
|
|
parent, err := th.Server.App().GetBlockByID(card1.ID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, parent.Fields["contentOrder"], tc.expectedContentOrder)
|
|
})
|
|
}
|
|
}
|