public void ShouldAddIntervalToResultsForGoogleAnalytics(int resultIndex, string expectedText, int actualPage) { var searchPage = new SearchResults(); var aggList = new List <LevelAggregationViewModel> { new LevelAggregationViewModel { Checked = false, Count = 36, Value = "1" }, new LevelAggregationViewModel { Checked = true, Count = 500, Value = "2" } }; var searchTerm = "Search Term for user"; var results = from ll in new ApprenticeshipSearchResultItemViewModel[10] select new ApprenticeshipSearchResultItemViewModel { Title = "Test" }; var model = new ApprenticeshipSearchResultViewModel { TotalResults = 10, SearchTerm = searchTerm, Results = results, ActualPage = actualPage, AggregationLevel = aggList }; var html = searchPage.RenderAsHtml(model).ToAngleSharp(); GetAttribute(html, "#apprenticeship-results article a", "attr-ga-result-interval", resultIndex).Should().BeEquivalentTo(expectedText); }
public void ShouldHaveDataForGoogleAnalytic() { var searchPage = new SearchResults(); var aggList = new List <LevelAggregationViewModel> { new LevelAggregationViewModel { Checked = false, Count = 36, Value = "1" }, new LevelAggregationViewModel { Checked = true, Count = 500, Value = "2" } }; var searchTerm = "Search Term for user"; var model = new ApprenticeshipSearchResultViewModel { TotalResults = 1, SearchTerm = searchTerm, Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test" } }, AggregationLevel = aggList }; var html = searchPage.RenderAsHtml(model).ToAngleSharp(); GetAttribute(html, "#ga-search-term", "value").Should().BeEquivalentTo(searchTerm); }
public void WhenLevelAggregationValuesAreSelected() { var searchPage = new SearchResults(); var aggList = new List <LevelAggregationViewModel> { new LevelAggregationViewModel { Checked = false, Count = 36, Value = "1" }, new LevelAggregationViewModel { Checked = true, Count = 500, Value = "2" } }; var model = new ApprenticeshipSearchResultViewModel { TotalResults = 1, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test" } }, AggregationLevel = aggList }; var html = searchPage.RenderAsHtml(model).ToAngleSharp(); GetAttribute(html, ".column-one-third form ul li input", "type").Should().Be("checkbox"); GetAttribute(html, ".column-one-third form ul li input", "checked").Should().BeNull(); GetAttribute(html, ".column-one-third form ul li input", "checked", 2).Should().Be(string.Empty); GetPartial(html, ".column-one-third form ul li label", 2).Should().Be("level 2 (500)"); }
public void ShouldShowSearchFormToSearchAgainWhenNoResults() { var searchPage = new SearchResults(); var aggList = new List <LevelAggregationViewModel> { new LevelAggregationViewModel { Checked = false, Count = 36, Value = "1" }, new LevelAggregationViewModel { Checked = true, Count = 500, Value = "2" } }; var model = new ApprenticeshipSearchResultViewModel { TotalResults = 0, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test" } }, AggregationLevel = aggList }; var html = searchPage.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, "label[for='keywords']").Should().NotBeNullOrEmpty(); GetPartial(html, "label[for='keywords']").Should().StartWith("Try a new search"); }
public void WhenSearchResultReturnsAnStandardShouldNewLabelMessage() { var searchPage = new SearchResults(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 2, SearchTerm = "test", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 2", Level = "3 (equivalent to 2 A level passes)", Id = "3" } }, AggregationLevel = new List <LevelAggregationViewModel>() }; var html = searchPage.RenderAsHtml(model).ToAngleSharp(); // First result GetPartial(html, ".result-title").Should().StartWith("Test title 1"); // Second result GetPartial(html, ".result-title", 2).Should().Be("Test title 2"); }
public void When_SearchResultContainLevel() { var searchPage = new SearchResults(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 2, SearchTerm = "test", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Duration = 72 }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 2", Level = "3 (equivalent to 2 A level passes)" } }, AggregationLevel = new List <LevelAggregationViewModel>() }; var html = searchPage.RenderAsHtml(model).ToAngleSharp(); // First result GetPartial(html, ".result-title").Should().Be("Test title 1"); GetPartial(html, ".length").Should().Be("72 months"); // Second result GetPartial(html, ".result-title", 2).Should().Be("Test title 2"); GetPartial(html, ".level").Should().Be("3 (equivalent to 2 A level passes)"); }
public async Task ShouldSetSearchViewModel() { // Arrange var searchTerm = "Sport"; var viewModel = new ApprenticeshipSearchResultViewModel { SearchTerm = searchTerm }; _mockMappingService.Setup(x => x.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(It.IsAny <ApprenticeshipSearchResponse>())) .Returns(viewModel); _mockMediator.Setup(x => x.Send(It.IsAny <ApprenticeshipSearchQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ApprenticeshipSearchResponse { StatusCode = ApprenticeshipSearchResponse.ResponseCodes.Success }); var urlHelper = new Mock <UrlHelper>(); urlHelper.Setup(x => x.Action(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <RouteValueDictionary>())) .Returns("www.google.co.uk"); _sut.Url = urlHelper.Object; // Act var result = await _sut.SearchResults(new ApprenticeshipSearchQuery { Keywords = searchTerm }) as ViewResult; // Assert var model = result.Model as ApprenticeshipSearchResultViewModel; model.SearchViewModel.Should().NotBeNull(); model.SearchViewModel.SearchTerm.Should().Be(searchTerm); model.SearchViewModel.ApprenticeshipInfoApiBaseUrl.Should().Be(ApprenticeshipApiBaseUrl); }
public void ShouldDetermineEmptyResultsForGoogleAnalytic() { var searchPage = new SearchResults(); var aggList = new List <LevelAggregationViewModel> { new LevelAggregationViewModel { Checked = false, Count = 36, Value = "1" }, new LevelAggregationViewModel { Checked = true, Count = 500, Value = "2" } }; var modelWithResults = new ApprenticeshipSearchResultViewModel { TotalResults = 1, Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test" } }, AggregationLevel = aggList }; var modelWithoutResults = new ApprenticeshipSearchResultViewModel { TotalResults = 1, Results = new ApprenticeshipSearchResultItemViewModel[0], AggregationLevel = aggList }; var htmlWithResults = searchPage.RenderAsHtml(modelWithResults).ToAngleSharp(); var htmlWithoutResults = searchPage.RenderAsHtml(modelWithoutResults).ToAngleSharp(); GetAttribute(htmlWithResults, "#ga-no-result", "value").Should().BeEquivalentTo("False"); GetAttribute(htmlWithoutResults, "#ga-no-result", "value").Should().BeEquivalentTo("True"); }
public void WhenSearchResultIsZero() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 0, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel>(), }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, "p").Should().Contain("Sorry, there is currently no apprenticeship training for 'SearchTerm'"); }
public void WhenSearchResultHasErrors() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 0, SearchTerm = string.Empty, Results = new List <ApprenticeshipSearchResultItemViewModel>(), HasError = true }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, "p").Should().Contain("There was a problem performing a search. Try again later."); }
public void WhenSearchResultDoesntReturnsResultsShouldntShowLabelMessage() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 0, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel() } }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, ".labelmessage").Should().BeEmpty(); }
public void WhenSearchResultReturnsMoreThanOne() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 2, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel() } }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, "p").Should().Be("There are 2 apprenticeships matching your search for 'SearchTerm'."); }
public void WhenSearchResultReturnsAll() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 68, SearchTerm = string.Empty, Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel() } }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, "p").Should().Be("All apprenticeships."); }
public void WhenSearchResultReturnsSomethingShouldShowLabelMessage() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 2, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel() } }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, ".labelmessage").Should().Be("Results labelled New are apprenticeship standards developed by employer groups."); }
public void WhenSearchResultReturnsOneResult() { var detail = new SearchResultMessage(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 1, SearchTerm = "SearchTerm", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel() } }; var html = detail.RenderAsHtml(model).ToAngleSharp(); var result = GetPartial(html, ".results-one"); result.Should().Be("There is 1 apprenticeship matching your search for 'SearchTerm'."); }
public void ShouldReturnSearchResults() { var viewModel = new ApprenticeshipSearchResultViewModel(); _mockMediator.Setup(x => x.Send(It.IsAny <ApprenticeshipSearchQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ApprenticeshipSearchResponse { StatusCode = ApprenticeshipSearchResponse.ResponseCodes.Success }); _mockMappingService.Setup(x => x.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(It.IsAny <ApprenticeshipSearchResponse>())) .Returns(viewModel); var result = _sut.SearchResults(new ApprenticeshipSearchQuery()).Result as ViewResult; _mockMediator.Verify(x => x.Send(It.IsAny <ApprenticeshipSearchQuery>(), It.IsAny <CancellationToken>())); _mockMappingService.Verify( x => x.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(It.IsAny <ApprenticeshipSearchResponse>()), Times.Once); result.Model.Should().Be(viewModel); }
public async Task ShouldRedirectIfSearchResultsPageTooHigh() { var viewModel = new ApprenticeshipSearchResultViewModel(); _mockMappingService.Setup(x => x.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(It.IsAny <ApprenticeshipSearchResponse>())) .Returns(viewModel); _mockMediator.Setup(x => x.Send(It.IsAny <ApprenticeshipSearchQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ApprenticeshipSearchResponse { StatusCode = ApprenticeshipSearchResponse.ResponseCodes.PageNumberOutOfUpperBound }); var urlHelper = new Mock <UrlHelper>(); urlHelper.Setup(x => x.Action(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <RouteValueDictionary>())) .Returns("www.google.co.uk"); _sut.Url = urlHelper.Object; var result = await _sut.SearchResults(new ApprenticeshipSearchQuery()) as RedirectResult; result.Should().NotBeNull(); }
public void WhenSearchResultHasPaginationAndIsTheLastPageShouldShowOnlyBackPageLink() { var detail = new SearchResults(); var model = new ApprenticeshipSearchResultViewModel { TotalResults = 30, SearchTerm = "*", Results = new List <ApprenticeshipSearchResultItemViewModel> { new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" }, new ApprenticeshipSearchResultItemViewModel { Title = "Test title 1", Id = "3" } }, ActualPage = 3, LastPage = 3, HasError = false, AggregationLevel = new List <LevelAggregationViewModel>() }; var html = detail.RenderAsHtml(model).ToAngleSharp(); GetPartial(html, ".page-navigation__btn.prev").Should().Contain("Previous page").And.Contain("2 of 3"); GetPartial(html, ".page-navigation__btn.next").Should().BeEmpty(); }
private static RouteValueDictionary CreateRouteParameters(ApprenticeshipSearchQuery query, ApprenticeshipSearchResultViewModel viewModel) { var rv = new RouteValueDictionary { { "keywords", query?.Keywords }, { "page", viewModel?.LastPage ?? 1 } }; var index = 0; if (viewModel?.AggregationLevel == null || !viewModel.AggregationLevel.Any()) { return(rv); } foreach (var level in viewModel.AggregationLevel.Where(m => m.Checked)) { rv.Add("SelectedLevels[" + index + "]", level.Value); index++; } return(rv); }