Esempio n. 1
0
// TestTodoSuggest tests the `suggest` subcommand
func TestTodoSuggest(t *testing.T) {
	ui, db, user, c := newMockTodoCommand(t)

	// load a task into the db
	tsk := newTestTask(t, db, user)
	tsk.Name = "SUGGESTED"
	if err := db.Save(tsk); err != nil {
		t.Fatal(err)
	}

	tagName := "random tag"
	tag.Task(tsk, tagName)
	ui.InputReader = bytes.NewBufferString("y\n") // yes, start the task

	t.Log("running: `elos todo suggest`")
	code := c.Run([]string{"suggest"})
	t.Log("command 'start' terminated")

	errput := ui.ErrorWriter.String()
	output := ui.OutputWriter.String()
	t.Logf("Error output:\n %s", errput)
	t.Logf("Output:\n %s", output)

	// verify there were no errors
	if errput != "" {
		t.Fatalf("Expected no error output, got: %s", errput)
	}

	// verify success
	if code != success {
		t.Fatalf("Expected successful exit code along with empty error output.")
	}

	// verify output
	if !strings.Contains(output, "SUGGESTED") {
		t.Fatal("Expected output to containe 'SUGGESTED', the name of the only task")
	}

	if !strings.Contains(output, tagName) {
		t.Fatal("Expected output to contain the task's tag's name")
	}

	if !strings.Contains(strings.ToLower(output), "start") {
		t.Fatal("Should ask if we want to start the task")
	}

	t.Log("Reloading the task")
	if err := db.PopulateByID(tsk); err != nil {
		t.Fatal(err)
	}
	t.Logf("Task loaded:\n%+v", tsk)

	if !task.InProgress(tsk) {
		t.Fatal("The task should be in progress now, cause we indicated we wanted to start it")
	}
}
Esempio n. 2
0
// TestTodoListTag test the `list -t` subcommand
func TestTodoListTag(t *testing.T) {
	// TODO(nclandolfi): fix flaky test
	t.Skip()
	ui, db, user, c := newMockTodoCommand(t)

	task1 := newTestTask(t, db, user)
	task2 := newTestTask(t, db, user)
	task1.Name = "task1"
	if err := db.Save(task1); err != nil {
		t.Fatal(err)
	}
	task2.Name = "task2"
	if err := db.Save(task2); err != nil {
		t.Fatal(err)
	}

	tagName := "TAGNAME"
	tag.Task(task1, tagName)
	ui.InputReader = bytes.NewBufferString("TAGNAME\n") // select first and only tag

	t.Log("running: `elos todo list -t`")
	code := c.Run([]string{"list", "-t"})
	t.Log("command 'list -t' terminated")

	errput := ui.ErrorWriter.String()
	output := ui.OutputWriter.String()
	t.Logf("Error output:\n %s", errput)
	t.Logf("Output:\n %s", output)

	// verify there were no errors
	if errput != "" {
		t.Fatalf("Expected no error output, got: %s", errput)
	}

	// verify success
	if code != success {
		t.Fatalf("Expected successful exit code along with empty error output.")
	}

	// verify some of the output
	if !strings.Contains(output, "0)") {
		t.Fatalf("Output should have contained a 0) for listing tasks")
	}

	if !strings.Contains(output, "task1") {
		t.Fatalf("Output should have contained 'task1' the name of the first task")
	}
}
Esempio n. 3
0
File: todo.go Progetto: elos/elos
// runTag runs the 'tag' subcommand, which uses elos'
// tagging system to tag a particular task
func (c *TodoCommand) runTag() int {
	tsk, index := c.promptSelectTask()
	if index < 0 {
		return failure
	}

	c.UI.Output("Which tag to add?")
	tg := c.promptSelectTag()
	if tg == "" {
		return failure
	}

	tag.Task(tsk, tg)

	if err := c.DB.Save(tsk); err != nil {
		c.errorf("saving task")
		return failure
	}

	c.UI.Output(fmt.Sprintf("Added '%s' to task", tg))

	return success
}
Esempio n. 4
0
// TestTodoTag tests the `elos todo tag -r` subcommand with the
// "r" flag
func TestTodoTagRemove(t *testing.T) {
	ui, db, user, c := newMockTodoCommand(t)

	// load a task into the db
	task := newTestTask(t, db, user)
	task.Name = "Take out the trash"
	if err := db.Save(task); err != nil {
		t.Fatal(err)
	}

	tg := "tag name"

	// now it's tagged
	tag.Task(task, tg)

	if err := db.Save(task); err != nil {
		t.Fatal(err)
	}

	// load input
	input := strings.Join([]string{
		"0", // selecting the task to remove the tag from
		"0", // selecting the tag
	}, "\n")
	ui.InputReader = bytes.NewBufferString(input)

	t.Log("running: `elos todo tag -r`")
	code := c.Run([]string{"tag", "-r"})
	t.Log("command 'tag -r' terminated")

	errput := ui.ErrorWriter.String()
	output := ui.OutputWriter.String()
	t.Logf("Error output:\n %s", errput)
	t.Logf("Output:\n %s", output)

	// verify there were no errors
	if errput != "" {
		t.Fatalf("Expected no error output, got: %s", errput)
	}

	// verify success
	if code != success {
		t.Fatalf("Expected successful exit code along with empty error output.")
	}

	// verify some of the output
	if !strings.Contains(output, "0)") {
		t.Fatalf("Output should have contained a 0) for listing tasks")
	}

	if !strings.Contains(output, "Which number?") {
		t.Fatalf("Output should have asked for a task number")
	}

	if !strings.Contains(output, tg) {
		t.Fatalf("Output should have included the tag's name")
	}

	t.Log("Checking that the task is no longer tagged")

	tsk := &models.Task{
		Id: task.Id,
	}
	if err := db.PopulateByID(tsk); err != nil {
		t.Fatal(err)
	}

	t.Logf("Here's the task:\n%+v", tsk)
	t.Logf("Here's the tag:\n%+v", tg)

	if len(tsk.Tags) != 0 {
		t.Fatal("Expected the task to have no tag")
	}
}