diff --git a/apps/pagy_standalone_app.ru b/apps/pagy_standalone_app.ru index 0bc27cdb9..bfe3cbb26 100644 --- a/apps/pagy_standalone_app.ru +++ b/apps/pagy_standalone_app.ru @@ -40,7 +40,7 @@ Pagy::VARS[:trim] = false # opt-in trim # sinatra application require 'sinatra/base' -class PagyApp < Sinatra::Base +class PagyStandaloneApp < Sinatra::Base configure do enable :inline_templates end @@ -81,7 +81,7 @@ class MockCollection < Array end end -run PagyApp +run PagyStandaloneApp __END__ diff --git a/pagy-on-docker/docker-compose.yml b/pagy-on-docker/docker-compose.yml index dc8bb7760..a1f6bc531 100644 --- a/pagy-on-docker/docker-compose.yml +++ b/pagy-on-docker/docker-compose.yml @@ -38,7 +38,7 @@ services: # - "1234:1234" # RubyMine debugger - "4567:4567" # default sinatra e2e/app.rb - "8080:8080" # should you run the rackup apps/base_app.ru - command: rerun "test/e2e/app.rb -o 0.0.0.0" + command: rerun -- rackup -o 0.0.0.0 -p 4567 test/e2e/pagy_app.ru stdin_open: true tty: true diff --git a/pagy-on-docker/pagy-cypress-uid1000.dockerfile b/pagy-on-docker/pagy-cypress-uid1000.dockerfile index 00a293c8e..059397b3d 100644 --- a/pagy-on-docker/pagy-cypress-uid1000.dockerfile +++ b/pagy-on-docker/pagy-cypress-uid1000.dockerfile @@ -5,7 +5,7 @@ FROM cypress/included:7.3.0 RUN apt-get update && apt-get install -y libcanberra-gtk* \ && rm -rf /opt/firefox /usr/bin/firefox \ && ln -s /root/.cache /home/node/.cache \ - && npm install --save-dev @cypress/snapshot + && npm install --save-dev @cypress/snapshot html-validate cypress-html-validate # make sure cypress looks in the right place ENV CYPRESS_CACHE_FOLDER=/home/node/.cache/Cypress diff --git a/pagy-on-docker/pagy-cypress.dockerfile b/pagy-on-docker/pagy-cypress.dockerfile index 089bb8788..22e41ed89 100644 --- a/pagy-on-docker/pagy-cypress.dockerfile +++ b/pagy-on-docker/pagy-cypress.dockerfile @@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y libcanberra-gtk* \ && install -d -m 0755 -o $user -g $user /home/$user \ && rm -rf /opt/firefox /usr/bin/firefox \ && ln -s /root/.cache /home/$user/.cache \ - && npm install --save-dev @cypress/snapshot + && npm install --save-dev @cypress/snapshot html-validate cypress-html-validate # make sure cypress looks in the right place ENV CYPRESS_CACHE_FOLDER=/home/$user/.cache/Cypress diff --git a/test/e2e/cypress/integration/validate-html.spec.js b/test/e2e/cypress/integration/validate-html.spec.js new file mode 100644 index 000000000..0f14469ef --- /dev/null +++ b/test/e2e/cypress/integration/validate-html.spec.js @@ -0,0 +1,15 @@ +/// + +describe('Validate the HTML of all the styles helpers', () => { + const pages = [1, 25, 50] + for(let s = 0; s < styles.length; s++) { + let style = styles[s]; + for (let p = 0; p < pages.length; p++) { + let page = pages[p]; + it('test valid HTML for ' + style + ' page: ' + page, () => { + cy.visit(style + '?page=' + page); + cy.htmlvalidate(); + }); + } + } +}) diff --git a/test/e2e/cypress/plugins/index.js b/test/e2e/cypress/plugins/index.js index 54b2b0a76..b5102442c 100644 --- a/test/e2e/cypress/plugins/index.js +++ b/test/e2e/cypress/plugins/index.js @@ -21,8 +21,18 @@ // `config` is the resolved Cypress config // } +const htmlvalidate = require('cypress-html-validate/dist/plugin'); module.exports = (on, config) => { + const htmlConfig = { + rules: { + // a few frameworks use ul or div for pagination, and aria-role="navigation" will trigger it + 'prefer-native-element': 'off', + // not needed in test environment + 'require-sri': 'off' + } + } + htmlvalidate.install(on, htmlConfig); /* on('before:browser:launch', (browser = {}, launchOptions) => { // `args` is an array of all the arguments that will diff --git a/test/e2e/cypress/support/commands.js b/test/e2e/cypress/support/commands.js index 4178a97d0..726e5e228 100644 --- a/test/e2e/cypress/support/commands.js +++ b/test/e2e/cypress/support/commands.js @@ -25,6 +25,7 @@ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) require('@cypress/snapshot').register(); +import 'cypress-html-validate/dist/commands'; global.styles = ['/bootstrap', '/bulma', '/foundation', '/materialize', '/navs', '/semantic', '/uikit']; diff --git a/test/e2e/app.rb b/test/e2e/pagy_app.ru similarity index 67% rename from test/e2e/app.rb rename to test/e2e/pagy_app.ru index d7c883b68..d24a3362d 100644 --- a/test/e2e/app.rb +++ b/test/e2e/pagy_app.ru @@ -3,10 +3,10 @@ # Self-contained sinatra app to test the pagy helpers in the browser # USAGE: -# test/e2e/app.rb -o 0.0.0.0 +# rackup -o 0.0.0.0 -p 4567 test/e2e/pagy_app.ru # DEV USAGE: -# rerun "test/e2e/app.rb -o 0.0.0.0" +# rerun -- rackup -o 0.0.0.0 -p 4567 test/e2e/pagy_app.ru # Available at http://0.0.0.0:4567 @@ -28,55 +28,59 @@ require_relative '../mock_helpers/collection' # sinatra setup -require 'sinatra' +require 'sinatra/base' # sinatra application -enable :inline_templates +class PagyApp < Sinatra::Base + enable :inline_templates -include Pagy::Backend # rubocop:disable Style/MixinUsage + include Pagy::Backend -helpers do - include Pagy::Frontend + helpers do + include Pagy::Frontend - def site_map - html = +%(
) - query_string = "?#{Rack::Utils.build_nested_query(params)}" unless params.empty? - [:home, *STYLES].each do |name| - html << %(#{name} ) + def site_map + html = +%(
) + query_string = "?#{Rack::Utils.build_nested_query(params)}" unless params.empty? + [:home, *STYLES].each do |name| + html << %(#{name} ) + end + html << %(
) end - html << %(
) - end -end + end -get '/pagy.js' do - content_type 'application/javascript' - send_file Pagy.root.join('javascripts', 'pagy.js') -end + get '/pagy.js' do + content_type 'application/javascript' + send_file Pagy.root.join('javascripts', 'pagy.js') + end -%w[/ /home].each do |route| - get(route) { erb :home } -end + %w[/ /home].each do |route| + get(route) { erb :home } + end -# one route/action per style -STYLES.each do |name| - get "/#{name}" do - collection = MockCollection.new - @pagy, @records = pagy(collection) - name_fragment = name == 'navs' ? '' : "#{name}_" - erb :helpers, locals: {name: name, name_fragment: name_fragment} + # one route/action per style + STYLES.each do |name| + get "/#{name}" do + collection = MockCollection.new + @pagy, @records = pagy(collection) + name_fragment = name == 'navs' ? '' : "#{name}_" + erb :helpers, locals: {name: name, name_fragment: name_fragment} + end end end +run PagyApp __END__ @@ layout - + - - + @@ -91,7 +95,7 @@ def site_map @@ home
-

Pagy e2e app

+

Pagy e2e app

This app runs on Sinatra/Puma and is used for testing locally and in GitHub Actions CI with cypress, or just inspect the different helpers in the same page.

@@ -104,7 +108,7 @@ def site_map @@ helpers -

<%= name %>

+

<%= name %>


@records