コード例 #1
0
        public void DFC1786ForPreSearchFilterButtonsAndLinkTest()
        {
            var index         = new _MVC_Views_PreSearchFilters_Index_cshtml();
            var testDataModel = GeneratePreSEarchFiltersViewModel(false);
            var htmlDom       = index.RenderAsHtml(testDataModel);

            //Should have  a link to the home page
            var backButton = htmlDom.GetElementbyId("filter-home");

            if (testDataModel.Section.PageNumber > 1)
            {
                backButton.InnerText.Should().BeEquivalentTo("Back");
            }
            else
            {
                backButton.Should().BeNull();
            }

            var backForm = htmlDom.GetElementbyId("backForm");

            backForm.Attributes["action"].Value.Should().BeEquivalentTo(testDataModel.Section.PreviousPageUrl);

            var continueButton = htmlDom.GetElementbyId("filter-continue");

            continueButton.InnerText.Should().BeEquivalentTo("Continue");

            var continueForm = htmlDom.GetElementbyId("continueForm");

            continueForm.Attributes["action"].Value.Should().BeEquivalentTo(testDataModel.Section.NextPageUrl);
        }
コード例 #2
0
        public void SelectMessageShouldBeAsDefindedInModel()
        {
            var index         = new _MVC_Views_PreSearchFilters_Index_cshtml();
            var testDataModel = GeneratePreSEarchFiltersViewModel(true);

            testDataModel.Section.SelectMessage = "<div id='qualifications-hint'>Select Message</div>";
            var htmlDom = index.RenderAsHtml(testDataModel);

            htmlDom?.GetElementbyId($"qualifications-hint").OuterHtml.Should().Be(testDataModel.Section.SelectMessage);
        }
コード例 #3
0
        public void SelectMessageShouldNotRenderIfNotDefindeInModel()
        {
            var index         = new _MVC_Views_PreSearchFilters_Index_cshtml();
            var testDataModel = GeneratePreSEarchFiltersViewModel(true);

            testDataModel.Section.SelectMessage = string.Empty;
            var htmlDom = index.RenderAsHtml(testDataModel);

            htmlDom?.GetElementbyId($"qualifications-hint").Should().BeNull();
        }
コード例 #4
0
        public void DFC1786ForPreSearchFilterTextAndControllsDisplayed(bool singleSelectSection)
        {
            var index         = new _MVC_Views_PreSearchFilters_Index_cshtml();
            var testDataModel = GeneratePreSEarchFiltersViewModel(singleSelectSection);
            var htmlDom       = index.RenderAsHtml(testDataModel);

            htmlDom?.DocumentNode?.SelectNodes($"//*[@id='continueForm']/div/h4")?.FirstOrDefault()?.InnerText.Should().BeEquivalentTo($"Step {testDataModel.Section.PageNumber} of {testDataModel.Section.TotalNumberOfPages}");

            /* Think the testing frame work does not render Html.DisplayFor properly the view look fine but this test fails
             * htmlDom.DocumentNode.SelectNodes("//*[@id='continueForm']/div/h4").FirstOrDefault().InnerText.Should().BeEquivalentTo(preSearchFiltersModel.Sections[0].Name);
             * htmlDom.DocumentNode.SelectNodes("//*[@id='continueForm']/div/h4").FirstOrDefault().InnerText.Should().BeEquivalentTo(preSearchFiltersModel.Sections[0].Description);
             */

            //Check that we have all the hidden varibles for the section  on each formso that the model remains intact
            CheckForSectionHiddenValue(htmlDom, "Name", "backForm", testDataModel.Section.Name);
            CheckForSectionHiddenValue(htmlDom, "Name", "continueForm", testDataModel.Section.Name);

            CheckForSectionHiddenValue(htmlDom, "SectionDataType", "backForm", testDataModel.Section.SectionDataType);
            CheckForSectionHiddenValue(htmlDom, "SectionDataType", "continueForm", testDataModel.Section.SectionDataType);

            CheckForSectionHiddenValue(htmlDom, "PageNumber", "backForm", testDataModel.Section.PageNumber.ToString());
            CheckForSectionHiddenValue(htmlDom, "PageNumber", "continueForm", testDataModel.Section.PageNumber.ToString());

            CheckForHiddenValue(htmlDom, "OptionsSelected", "backForm", testDataModel.OptionsSelected);
            CheckForHiddenValue(htmlDom, "OptionsSelected", "continueForm", testDataModel.OptionsSelected);

            //Each of the options is displayed with a checkbox or radio and label for section
            for (int jj = 0; jj < testDataModel.Section.Options.Count; jj++)
            {
                if (testDataModel.Section.SingleSelectOnly)
                {
                    // this section should contains radio buttons
                    var filterOption = htmlDom?.DocumentNode?.SelectNodes($"//*[@id='Section_{jj}']").FirstOrDefault();
                    filterOption?.Attributes["type"].Value.Should().BeEquivalentTo("radio");
                }
                else
                {
                    var filterOption = htmlDom?.DocumentNode?.SelectNodes($"//*[@id='Section_Options_{jj.ToString()}__IsSelected']").FirstOrDefault();

                    // this section should contains check boxes
                    filterOption?.Attributes["type"].Value.Should().BeEquivalentTo("checkbox");

                    //if we have a N/A option needs this class
                    if (testDataModel.Section.Options[jj].ClearOtherOptionsIfSelected)
                    {
                        filterOption?.Attributes["class"].Value.Should().BeEquivalentTo("filter-na govuk-checkboxes__input");
                    }
                }

                //Have a label for the check box with the correct title and description
                htmlDom?.DocumentNode?.SelectNodes($"//*[@id='options1']/label[{(jj + 1).ToString()}]")?.FirstOrDefault()?.InnerText.Should().BeEquivalentTo($"{testDataModel.Section.Options[jj].Name}{testDataModel.Section.Options[jj].Description}");

                CheckForOptionHiddenValue(htmlDom, "OptionKey", "continueForm", jj, testDataModel.Section.Options[jj].OptionKey);
            }
        }
コード例 #5
0
        public void MatchingTotalIsDisplayedOnPagesAfterPageOne(int pageOn)
        {
            var index         = new _MVC_Views_PreSearchFilters_Index_cshtml();
            var testDataModel = GeneratePreSEarchFiltersViewModel(true);

            testDataModel.Section.PageNumber     = pageOn;
            testDataModel.NumberOfMatchesMessage = $" you have 123 career matches";
            var htmlDom = index.RenderAsHtml(testDataModel);

            if (pageOn > 1)
            {
                htmlDom?.DocumentNode?.SelectNodes($"//*[@id='continueForm']/div/h4")?.FirstOrDefault()?.InnerText.Should().Contain(testDataModel.NumberOfMatchesMessage);
            }
            else
            {
                htmlDom?.DocumentNode?.SelectNodes($"//*[@id='continueForm']/div/h4")?.FirstOrDefault()?.InnerText.Should().NotContain(testDataModel.NumberOfMatchesMessage);
            }
        }