예제 #1
0
        public static TextFieldInfo FromTimeEntrySuggestion(
            this TextFieldInfo textFieldInfo,
            TimeEntrySuggestion timeEntrySuggestion)
        {
            var builder = ImmutableList.CreateBuilder <ISpan>();

            builder.Add(new TextSpan(timeEntrySuggestion.Description));

            if (timeEntrySuggestion.HasProject)
            {
                var projectSpan = new ProjectSpan(
                    timeEntrySuggestion.ProjectId.Value,
                    timeEntrySuggestion.ProjectName,
                    timeEntrySuggestion.ProjectColor,
                    timeEntrySuggestion.TaskId,
                    timeEntrySuggestion.TaskName
                    );

                builder.Add(projectSpan);
            }

            builder.Add(new QueryTextSpan());

            return(TextFieldInfo
                   .Empty(timeEntrySuggestion.WorkspaceId)
                   .ReplaceSpans(builder.ToImmutable()));
        }
            public void RemovesTheReportedTagFromTheCurrentTextFieldInfo(int index)
            {
                var workspace = Substitute.For <IDatabaseWorkspace>();

                workspace.Name.Returns("Some workspace");
                var tag = Substitute.For <IDatabaseTag>();

                tag.Name.Returns("Some tag");
                tag.Id.Returns(1);
                tag.Workspace.Returns(workspace);
                tag.WorkspaceId.Returns(3);
                var tag2 = Substitute.For <IDatabaseTag>();

                tag2.Name.Returns("Some tag 2");
                tag2.Id.Returns(2);
                tag2.Workspace.Returns(workspace);
                tag2.WorkspaceId.Returns(3);
                TargetBinding.SetValue(
                    TextFieldInfo
                    .Empty(1)
                    .AddTag(new TagSuggestion(tag))
                    .AddTag(new TagSuggestion(tag2)));

                EventProvider.RaiseTagDeleted(index);

                TargetBinding.TextFieldInfo.Tags.Single().TagId.Should().Be(index == 0 ? 2 : 1);
            }
예제 #3
0
                public void DoesNotExtractTheProjectNameWhenCursorIsMovedBeforeTheAtSymbol(string text, int cursorPosition)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, cursorPosition);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().NotBe(AutocompleteSuggestionType.Projects);
                }
                public async Task WhenTheUserBeginsTypingADescription(string description)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(description, 0);

                    await Provider.Query(textFieldInfo);

                    await Database.TimeEntries.Received().GetAll();
                }
예제 #5
0
            public void DoesNotAddTagIfAlreadyAdded()
            {
                var textFieldInfo =
                    TextFieldInfo.Empty(WorkspaceId)
                    .AddTag(1, "1")
                    .AddTag(1, "1");

                textFieldInfo.Spans.OfType <TagSpan>().Should().HaveCount(1);
            }
예제 #6
0
                public void ExtractTheTagtNameFromTheFirstHashSymbolWithPreceededWithAWhiteSpaceOrAtTheVeryBeginningOfTheText(string text, string expectedTagName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, text.Length);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Tags);
                    parsed.Text.Should().Be(expectedTagName);
                }
                public async Task WhenTheSearchStringIsEmpty()
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor("", 0);

                    var suggestions = await Provider.Query(textFieldInfo);

                    suggestions.Should().HaveCount(2)
                    .And.AllBeOfType <QuerySymbolSuggestion>();
                }
예제 #8
0
                public void ExtractsTheProjectNameWhileTyping(string text, string expectedProjectName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, text.Length);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Projects);
                    parsed.Text.Should().Be(expectedProjectName);
                }
                public async Task WhenTheHashtagSymbolIsTyped(string description)
                {
                    var actualDescription = $"{description} #{description}";
                    var textFieldInfo     = TextFieldInfo.Empty(1).WithTextAndCursor(actualDescription, description.Length + 2);

                    await Provider.Query(textFieldInfo);

                    await Database.Tags.Received().GetAll();
                }
예제 #10
0
                public void DoesNotSuggestAnythingWhenTheTextIsEmpty(string text)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(text, 0);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.None);
                    parsed.Text.Should().Be(String.Empty);
                }
예제 #11
0
                public void ExtractTheProjectNameFromTheFirstAtSymbolPrecedingTheCursor(string text, int cursorPosition, string expectedProjectName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).ReplaceSpans(new QueryTextSpan(text, cursorPosition));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Projects);
                    parsed.Text.Should().Be(expectedProjectName);
                }
예제 #12
0
            protected TextFieldInfo CreateDefaultTextFieldInfo()
            {
                var spans = new ISpan[]
                {
                    new QueryTextSpan(Description, Description.Length),
                    new ProjectSpan(ProjectId, ProjectName, ProjectColor, TaskId, TaskName)
                };

                return(TextFieldInfo.Empty(WorkspaceId).ReplaceSpans(spans.ToImmutableList()));
            }
예제 #13
0
            public void DoesNotAddTagIfAlreadyAdded()
            {
                var tag = createTagSuggestion(1);

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .AddTag(tag)
                                    .AddTag(tag);

                textFieldInfo.Tags.Should().HaveCount(1);
            }
예제 #14
0
            public void RemovesTheTagQueryIfAnyHashtagSymbolIsPresent()
            {
                var newDescription = $"{Description}#something";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .WithTextAndCursor(newDescription, newDescription.Length)
                                    .RemoveTagQueryFromDescriptionIfNeeded();

                textFieldInfo.Text.Should().Be(Description);
            }
                public async Task WhenTheUserHasTypedAnySearchSymbolsButMovedTheCaretToAnIndexThatComesBeforeTheSymbol(
                    string description)
                {
                    var actualDescription = $"{description} @{description}";
                    var textFieldInfo     = TextFieldInfo.Empty(1).WithTextAndCursor(actualDescription, 0);

                    await Provider.Query(textFieldInfo);

                    await Database.TimeEntries.Received().GetAll();
                }
예제 #16
0
                public void DoesNotSuggestAnythingWhenTheTextIsEmpty(string text)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .ReplaceSpans(new QueryTextSpan(text, 0));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.None);
                    parsed.Text.Should().Be(String.Empty);
                }
예제 #17
0
            public void RemovesTheTagQueryIfAnyHashtagSymbolIsPresent()
            {
                var newDescription = $"{Description}#something";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .ReplaceSpans(new QueryTextSpan(newDescription, newDescription.Length))
                                    .RemoveTagQueryIfNeeded();

                textFieldInfo.GetQuerySpan().Text.Should().Be(Description);
            }
예제 #18
0
                public void ExtractTheProjectNameFromTheFirstAtSymbolWithPreceededWithAWhiteSpaceOrAtTheVeryBeginningOfTheText(string text, string expectedProjectName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .ReplaceSpans(new QueryTextSpan(text, text.Length));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Projects);
                    parsed.Text.Should().Be(expectedProjectName);
                }
예제 #19
0
                public void ExtractsTheTagNameWhileTyping(string text, string expectedTagName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .ReplaceSpans(new QueryTextSpan(text, text.Length));

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Tags);
                    parsed.Text.Should().Be(expectedTagName);
                }
                public async Task WhenTheUserBeginsTypingADescription(string description)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(description, 0);

                    await Provider.Query(QueryInfo.ParseFieldInfo(textFieldInfo));

                    InteractorFactory
                    .Received()
                    .GetTimeEntriesAutocompleteSuggestions(Arg.Is <IList <string> >(
                                                               words => words.SequenceEqual(description.SplitToQueryWords())));
                }
예제 #21
0
            public void AlwaysReturnsACursorPositionThatsLessThanOrEqualTheLengthOfTheText(string text, int cursor)
            {
                if (text == null)
                {
                    return;
                }

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId).WithTextAndCursor(text, cursor);

                textFieldInfo.DescriptionCursorPosition.Should().BeLessOrEqualTo(text.Length);
            }
                public async Task WhenTheUserHasAlreadySelectedAProjectAndTypesTheAtSymbol()
                {
                    var description   = $"Testing Mobile Apps @toggl";
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .WithTextAndCursor(description, description.Length)
                                        .WithProjectInfo(WorkspaceId, ProjectId, ProjectName, ProjectColor);

                    await Provider.Query(textFieldInfo);

                    await Database.TimeEntries.Received().GetAll();
                }
예제 #23
0
            public void RemovesTheTagQueryFromTheLastAtSymbolIsPresent()
            {
                var newDescription  = $"{Description}#something";
                var longDescription = $"{newDescription}#else";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .WithTextAndCursor(longDescription, longDescription.Length)
                                    .RemoveTagQueryFromDescriptionIfNeeded();

                textFieldInfo.Text.Should().Be(newDescription);
            }
예제 #24
0
            public void RemovesTheTagQueryFromTheFirstAtSymbolPresent()
            {
                var newDescription  = $"{Description}#something";
                var longDescription = $"{newDescription}#else";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .ReplaceSpans(new QueryTextSpan(longDescription, longDescription.Length))
                                    .RemoveTagQueryIfNeeded();

                textFieldInfo.GetQuerySpan().Text.Should().Be(Description);
            }
예제 #25
0
            public void RemovesTheProjectQueryIfAnyAtSymbolIsPresent()
            {
                var newDescription = $"{Description}@something";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId)
                                    .WithTextAndCursor(newDescription, newDescription.Length)
                                    .WithProjectInfo(WorkspaceId, ProjectId, ProjectName, ProjectColor)
                                    .RemoveProjectQueryFromDescriptionIfNeeded();

                textFieldInfo.Text.Should().Be(Description);
            }
예제 #26
0
            public void RemovesTheProjectQueryIfAnyAtSymbolIsPresent()
            {
                var newDescription = $"{Description}@something";

                var textFieldInfo = TextFieldInfo.Empty(WorkspaceId).ReplaceSpans(
                    new QueryTextSpan(newDescription, newDescription.Length),
                    new ProjectSpan(ProjectId, ProjectName, ProjectColor)
                    ).RemoveProjectQueryIfNeeded();

                textFieldInfo.GetQuerySpan().Text.Should().Be(Description);
            }
예제 #27
0
                public void ExtractsTheTagNameIncludingTheAtSymbolsWhenAProjectIsSelected(string text, string expectedTagName)
                {
                    var textFieldInfo = TextFieldInfo.Empty(1)
                                        .WithTextAndCursor(text, text.Length)
                                        .WithProjectInfo(WorkspaceId, ProjectId, ProjectName, ProjectColor);

                    var parsed = QueryInfo.ParseFieldInfo(textFieldInfo);

                    parsed.SuggestionType.Should().Be(AutocompleteSuggestionType.Tags);
                    parsed.Text.Should().Be(expectedTagName);
                }
                public async Task OnlyDisplaysResultsThatHaveAtLeastOneMatchOnEveryWordTyped()
                {
                    const string description   = "#5 2";
                    var          textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(description, 1);

                    var suggestions = await Provider.Query(textFieldInfo);

                    await Database.Tags.Received().GetAll();

                    suggestions.Single().Should().BeOfType <TagSuggestion>()
                    .Which.Name.Should().Be("52");
                }
                public async Task SearchesTheName()
                {
                    const string description   = "#50";
                    var          textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(description, 1);

                    var suggestions = await Provider.Query(textFieldInfo);

                    await Database.Tags.Received().GetAll();

                    suggestions.Should().HaveCount(1)
                    .And.AllBeOfType <TagSuggestion>();
                }
                public async Task OnlyDisplaysResultsTheHaveHasAtLeastOneMatchOnEveryWordTyped()
                {
                    const string description   = "@10 3";
                    var          textFieldInfo = TextFieldInfo.Empty(1).WithTextAndCursor(description, 1);

                    var suggestions = await Provider.Query(textFieldInfo);

                    await Database.Projects.Received().GetAll();

                    suggestions.Should().HaveCount(1)
                    .And.AllBeOfType <ProjectSuggestion>();
                }