mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.8 KiB
128 lines
3.8 KiB
8 months ago
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
package project
|
||
|
|
||
|
import (
|
||
7 months ago
|
"fmt"
|
||
|
"strings"
|
||
8 months ago
|
"testing"
|
||
|
|
||
|
"code.gitea.io/gitea/models/db"
|
||
|
"code.gitea.io/gitea/models/unittest"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
6 months ago
|
func TestGetDefaultColumn(t *testing.T) {
|
||
8 months ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
|
|
||
|
projectWithoutDefault, err := GetProjectByID(db.DefaultContext, 5)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
6 months ago
|
// check if default column was added
|
||
|
column, err := projectWithoutDefault.GetDefaultColumn(db.DefaultContext)
|
||
8 months ago
|
assert.NoError(t, err)
|
||
6 months ago
|
assert.Equal(t, int64(5), column.ProjectID)
|
||
|
assert.Equal(t, "Uncategorized", column.Title)
|
||
8 months ago
|
|
||
|
projectWithMultipleDefaults, err := GetProjectByID(db.DefaultContext, 6)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
// check if multiple defaults were removed
|
||
6 months ago
|
column, err = projectWithMultipleDefaults.GetDefaultColumn(db.DefaultContext)
|
||
8 months ago
|
assert.NoError(t, err)
|
||
6 months ago
|
assert.Equal(t, int64(6), column.ProjectID)
|
||
|
assert.Equal(t, int64(9), column.ID)
|
||
8 months ago
|
|
||
6 months ago
|
// set 8 as default column
|
||
|
assert.NoError(t, SetDefaultColumn(db.DefaultContext, column.ProjectID, 8))
|
||
8 months ago
|
|
||
6 months ago
|
// then 9 will become a non-default column
|
||
|
column, err = GetColumn(db.DefaultContext, 9)
|
||
8 months ago
|
assert.NoError(t, err)
|
||
6 months ago
|
assert.Equal(t, int64(6), column.ProjectID)
|
||
|
assert.False(t, column.Default)
|
||
8 months ago
|
}
|
||
7 months ago
|
|
||
|
func Test_moveIssuesToAnotherColumn(t *testing.T) {
|
||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
|
|
||
6 months ago
|
column1 := unittest.AssertExistsAndLoadBean(t, &Column{ID: 1, ProjectID: 1})
|
||
7 months ago
|
|
||
|
issues, err := column1.GetIssues(db.DefaultContext)
|
||
|
assert.NoError(t, err)
|
||
|
assert.Len(t, issues, 1)
|
||
|
assert.EqualValues(t, 1, issues[0].ID)
|
||
|
|
||
6 months ago
|
column2 := unittest.AssertExistsAndLoadBean(t, &Column{ID: 2, ProjectID: 1})
|
||
7 months ago
|
issues, err = column2.GetIssues(db.DefaultContext)
|
||
|
assert.NoError(t, err)
|
||
|
assert.Len(t, issues, 1)
|
||
|
assert.EqualValues(t, 3, issues[0].ID)
|
||
|
|
||
|
err = column1.moveIssuesToAnotherColumn(db.DefaultContext, column2)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
issues, err = column1.GetIssues(db.DefaultContext)
|
||
|
assert.NoError(t, err)
|
||
|
assert.Len(t, issues, 0)
|
||
|
|
||
|
issues, err = column2.GetIssues(db.DefaultContext)
|
||
|
assert.NoError(t, err)
|
||
|
assert.Len(t, issues, 2)
|
||
|
assert.EqualValues(t, 3, issues[0].ID)
|
||
|
assert.EqualValues(t, 0, issues[0].Sorting)
|
||
|
assert.EqualValues(t, 1, issues[1].ID)
|
||
|
assert.EqualValues(t, 1, issues[1].Sorting)
|
||
|
}
|
||
|
|
||
|
func Test_MoveColumnsOnProject(t *testing.T) {
|
||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
|
|
||
|
project1 := unittest.AssertExistsAndLoadBean(t, &Project{ID: 1})
|
||
6 months ago
|
columns, err := project1.GetColumns(db.DefaultContext)
|
||
7 months ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, columns, 3)
|
||
|
assert.EqualValues(t, 0, columns[0].Sorting) // even if there is no default sorting, the code should also work
|
||
|
assert.EqualValues(t, 0, columns[1].Sorting)
|
||
|
assert.EqualValues(t, 0, columns[2].Sorting)
|
||
|
|
||
|
err = MoveColumnsOnProject(db.DefaultContext, project1, map[int64]int64{
|
||
|
0: columns[1].ID,
|
||
|
1: columns[2].ID,
|
||
|
2: columns[0].ID,
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
|
|
||
6 months ago
|
columnsAfter, err := project1.GetColumns(db.DefaultContext)
|
||
7 months ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, columnsAfter, 3)
|
||
|
assert.EqualValues(t, columns[1].ID, columnsAfter[0].ID)
|
||
|
assert.EqualValues(t, columns[2].ID, columnsAfter[1].ID)
|
||
|
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)
|
||
|
}
|
||
|
|
||
6 months ago
|
func Test_NewColumn(t *testing.T) {
|
||
7 months ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
|
|
||
|
project1 := unittest.AssertExistsAndLoadBean(t, &Project{ID: 1})
|
||
6 months ago
|
columns, err := project1.GetColumns(db.DefaultContext)
|
||
7 months ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, columns, 3)
|
||
|
|
||
|
for i := 0; i < maxProjectColumns-3; i++ {
|
||
6 months ago
|
err := NewColumn(db.DefaultContext, &Column{
|
||
|
Title: fmt.Sprintf("column-%d", i+4),
|
||
7 months ago
|
ProjectID: project1.ID,
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
|
}
|
||
6 months ago
|
err = NewColumn(db.DefaultContext, &Column{
|
||
|
Title: "column-21",
|
||
7 months ago
|
ProjectID: project1.ID,
|
||
|
})
|
||
|
assert.Error(t, err)
|
||
|
assert.True(t, strings.Contains(err.Error(), "maximum number of columns reached"))
|
||
|
}
|