diff --git a/.github/actions/build-dotnet-app/action.yml b/.github/actions/build-dotnet-app/action.yml index a2393dfc..e16d0001 100644 --- a/.github/actions/build-dotnet-app/action.yml +++ b/.github/actions/build-dotnet-app/action.yml @@ -17,9 +17,11 @@ runs: uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ inputs.dotnet_version }} + - name: Install dependencies shell: bash run: dotnet restore ${{ inputs.solution_filename }} + - name: Build shell: bash run: dotnet build ${{ inputs.solution_filename }} --configuration Release --no-restore diff --git a/.github/actions/run-accessibility-tests/action.yml b/.github/actions/run-accessibility-tests/action.yml new file mode 100644 index 00000000..c5d0feea --- /dev/null +++ b/.github/actions/run-accessibility-tests/action.yml @@ -0,0 +1,18 @@ +name: Run accessibility tests +description: Runs Pa11y-ci + +inputs: + url: + required: true + type: string + +runs: + using: composite + + steps: + - name: Run Pa11y + shell: bash + run: npm install -g pa11y-ci && pa11y-ci ${{ inputs.url }} --config .pa11yci-ubuntu.json + working-directory: ./tests/Dfe.EarlyYearsQualification.AccessibilityTests/ + + \ No newline at end of file diff --git a/.github/actions/run-app-for-testing/action.yml b/.github/actions/run-app-for-testing/action.yml new file mode 100644 index 00000000..f88e5352 --- /dev/null +++ b/.github/actions/run-app-for-testing/action.yml @@ -0,0 +1,15 @@ +name: Run app for testing +description: Run the app within the action so we can run E2E and Accessibility tests. + +inputs: + url: + required: true + type: string + +runs: + using: composite + + steps: + - name: Run .Net Project + shell: bash + run: dotnet run --urls "${{ inputs.url }}" --project="src/Dfe.EarlyYearsQualification.Web" --UseMockContentful=true & diff --git a/.github/actions/run-e2e-tests/action.yml b/.github/actions/run-e2e-tests/action.yml index 5ffb7614..fa165d07 100644 --- a/.github/actions/run-e2e-tests/action.yml +++ b/.github/actions/run-e2e-tests/action.yml @@ -10,12 +10,21 @@ runs: using: composite steps: - - name: Build and test project + - name: Run Chrome Tests uses: cypress-io/github-action@v6 + if: success() || failure() with: working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/ browser: chrome - #config: baseUrl=${{ inputs.url }} // TODO: Update this once the code check workflow starts running the app locally. For now leave this as the baseUrl in the config file. + config: baseUrl="${{ inputs.url }}" + + - name: Run Firefox Tests + uses: cypress-io/github-action@v6 + if: success() || failure() + with: + working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/ + browser: firefox + config: baseUrl="${{ inputs.url }}" - name: Store screenshots on test failure uses: actions/upload-artifact@v3 diff --git a/.github/workflows/code-pr-check.yml b/.github/workflows/code-pr-check.yml index 04aa877f..324ad5dc 100644 --- a/.github/workflows/code-pr-check.yml +++ b/.github/workflows/code-pr-check.yml @@ -20,6 +20,7 @@ concurrency: env: DOTNET_VERSION: 8 SOLUTION_NAME: 'Dfe.EarlyYearsQualification.sln' + URL: http://localhost:5000 jobs: @@ -45,8 +46,18 @@ jobs: uses: ./.github/actions/run-unit-tests with: solution_filename: ${{ env.SOLUTION_NAME }} + + - name: Run app for testing + uses: ./.github/actions/run-app-for-testing + with: + url: ${{ env.URL }} - name: Run e2e tests uses: ./.github/actions/run-e2e-tests with: - url: "" + url: ${{ env.URL }} + + - name: Run Accessibility tests + uses: ./.github/actions/run-accessibility-tests + with: + url: ${{ env.URL }} diff --git a/src/Dfe.EarlyYearsQualification.Web/Dfe.EarlyYearsQualification.Web.csproj b/src/Dfe.EarlyYearsQualification.Web/Dfe.EarlyYearsQualification.Web.csproj index 862d5ea1..4ffd4a7d 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Dfe.EarlyYearsQualification.Web.csproj +++ b/src/Dfe.EarlyYearsQualification.Web/Dfe.EarlyYearsQualification.Web.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Dfe.EarlyYearsQualification.Web/Extensions/AddMockContentful.cs b/src/Dfe.EarlyYearsQualification.Web/Extensions/AddMockContentful.cs new file mode 100644 index 00000000..b2c1bfa8 --- /dev/null +++ b/src/Dfe.EarlyYearsQualification.Web/Extensions/AddMockContentful.cs @@ -0,0 +1,24 @@ +using Dfe.EarlyYearsQualification.Content.Services; +using Moq; + +namespace Dfe.EarlyYearsQualification.Web.Extensions +{ + public static class IServiceCollectionExtensions + { + public static IServiceCollection AddMockContentful(this IServiceCollection services) + { + + var mockContentfulService = new Mock(); + + mockContentfulService.Setup(x => x.GetLandingPage()).ReturnsAsync(new Content.Entities.LandingPage() + { + Header = "Test Header", + ServiceIntroduction = new Contentful.Core.Models.Document(), + StartButtonText = "Test Start Button Text" + }); + + services.AddSingleton(mockContentfulService.Object); + return services; + } + } +} \ No newline at end of file diff --git a/src/Dfe.EarlyYearsQualification.Web/Program.cs b/src/Dfe.EarlyYearsQualification.Web/Program.cs index 5950d4f8..a2a713b0 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Program.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Program.cs @@ -1,5 +1,6 @@ using Contentful.AspNetCore; using Dfe.EarlyYearsQualification.Content.Services; +using Dfe.EarlyYearsQualification.Web.Extensions; var builder = WebApplication.CreateBuilder(args); @@ -7,16 +8,23 @@ builder.Services.AddControllersWithViews(); builder.Services.AddContentful(builder.Configuration); -builder.Services.AddTransient(); + +if (builder.Configuration.GetValue("UseMockContentful")) +{ + builder.Services.AddMockContentful(); +} else +{ + builder.Services.AddTransient(); +} var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); diff --git a/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.json b/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.json new file mode 100644 index 00000000..99a65786 --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.AccessibilityTests/.pa11yci-ubuntu.json @@ -0,0 +1,7 @@ +{ + "defaults": { + "chromeLaunchConfig": { + "executablePath": "/usr/bin/google-chrome" + } + } +} \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/dummy-spec.cy.js b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/dummy-spec.cy.js index 17715325..cb989d30 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/dummy-spec.cy.js +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/dummy-spec.cy.js @@ -4,12 +4,7 @@ describe("A dummy spec used to test Cypress setup", () => { cy.visit("/"); }) - it("opens on the example site", () => { - cy.url().should("eq", "https://example.cypress.io/"); - }) - - it("opens the utilities page", () => { - cy.get("a[href='/utilities']").first().click(); - cy.url().should("contain", "/utilities"); + it("Checks Crown copyright link text", () => { + cy.get(".govuk-footer__copyright-logo").first().should("contain.text", "Crown copyright") }) }) \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/package-lock.json b/tests/Dfe.EarlyYearsQualification.E2ETests/package-lock.json index 61f82f05..d7014540 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/package-lock.json +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "devDependencies": { - "cypress": "^13.6.3" + "cypress": "^13.6.4" } }, "node_modules/@colors/colors": { @@ -550,9 +550,9 @@ } }, "node_modules/cypress": { - "version": "13.6.3", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.6.3.tgz", - "integrity": "sha512-d/pZvgwjAyZsoyJ3FOsJT5lDsqnxQ/clMqnNc++rkHjbkkiF2h9s0JsZSyyH4QXhVFW3zPFg82jD25roFLOdZA==", + "version": "13.6.4", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.6.4.tgz", + "integrity": "sha512-pYJjCfDYB+hoOoZuhysbbYhEmNW7DEDsqn+ToCLwuVowxUXppIWRr7qk4TVRIU471ksfzyZcH+mkoF0CQUKnpw==", "dev": true, "hasInstallScript": true, "dependencies": { diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/package.json b/tests/Dfe.EarlyYearsQualification.E2ETests/package.json index 6b96cf99..8760ea7d 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/package.json +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/package.json @@ -10,6 +10,6 @@ "author": "", "license": "ISC", "devDependencies": { - "cypress": "^13.6.3" + "cypress": "^13.6.4" } }