From 3df7f005f52f8ab4181aaa3613082a1fe5596a27 Mon Sep 17 00:00:00 2001 From: octopusinvitro Date: Tue, 27 Sep 2016 14:30:40 +0100 Subject: [PATCH] fixup! Use tidy-html5 to validate the term-table page --- t/web/term_table/bahamas.rb | 43 +++++++++++++++++++++++++++++++++ t/web/term_table/phillipines.rb | 38 ----------------------------- views/term_table.erb | 8 +++--- 3 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 t/web/term_table/bahamas.rb delete mode 100644 t/web/term_table/phillipines.rb diff --git a/t/web/term_table/bahamas.rb b/t/web/term_table/bahamas.rb new file mode 100644 index 000000000..dfca4f41f --- /dev/null +++ b/t/web/term_table/bahamas.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true +require 'test_helper' +require_relative '../../../app' + +describe 'Bahamas' do + subject { Nokogiri::HTML(last_response.body) } + let(:hubert) { subject.css('#mem-4a7bfd46-3b03-46ec-957f-3ef526b04bbe') } + let(:damian) { subject.css('#mem-58709524-7f66-44fd-8315-9712c4655768') } + let(:philip) { subject.css('#mem-dcd1a356-a7e6-409b-8028-27fea2691105') } + + before do + stub_popolo('4da60b8', 'Bahamas/House_of_Assembly') + get '/bahamas/house-of-assembly/term-table/2012.html' + end + + describe 'alt attribute on avatars' do + it 'has the person name in a normal image' do + img = hubert.css('img.person-card__image')[0] + img.attr('alt').must_equal 'Member headshot for Hubert Chipman' + end + + it 'has the person name in a normal image when JS is disabled' do + img = hubert.css('img.person-card__image')[1] + img.attr('alt').must_equal 'Member headshot for Hubert Chipman' + end + + it 'has the person name in a placeholder image' do + img = damian.css('img.person-card__image') + img.attr('alt').text.must_equal 'Placeholder image for Damian Gomez' + end + + it 'doesnt break for names with double quotes' do + img = philip.css('img.person-card__image')[0] + img.attr('alt').must_equal 'Member headshot for Philip "Brave" Davis' + end + end + + describe 'HTML validation' do + it 'has no errors in the term-table page' do + last_response_must_be_valid + end + end +end diff --git a/t/web/term_table/phillipines.rb b/t/web/term_table/phillipines.rb deleted file mode 100644 index c5a3aec24..000000000 --- a/t/web/term_table/phillipines.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true -require 'test_helper' -require_relative '../../../app' - -describe 'Phillipines' do - subject { Nokogiri::HTML(last_response.body) } - let(:dina) { subject.css('#mem-c5c42ac6-4942-4c32-baf7-3dae194f83bf') } - let(:dimaporo) { subject.css('#mem-236420bc-a15a-4727-a98a-75f870c5641f') } - let(:tiangco) { subject.css('#mem-8fd6197f-f9fa-47a8-974f-50c54f08bbdd') } - - before do - stub_popolo('ba933fa', 'Philippines/House') - get '/philippines/house/term-table/16.html' - end - - describe 'alt attribute on avatars' do - it 'has the person name in a normal image' do - img = dina.css('img.person-card__image') - img.attr('alt').text.must_equal 'Member headshot for Abad, Henedina R.' - end - - it 'has the person name in a placeholder image' do - img = dimaporo.css('img.person-card__image') - img.attr('alt').text.must_equal 'Placeholder image for Dimaporo, Abdullah D.' - end - - it 'doesnt break for names with double quotes' do - img = tiangco.css('img.person-card__image') - img.attr('alt').text.must_equal 'Member headshot for Tiangco, Tobias "Toby" M.' - end - end - - describe 'HTML validation' do - it 'has no errors in the term-table page' do - last_response_must_be_valid - end - end -end diff --git a/views/term_table.erb b/views/term_table.erb index 4fc2f3150..01a6039fb 100644 --- a/views/term_table.erb +++ b/views/term_table.erb @@ -141,12 +141,12 @@ data-src="<%= person.proxy_image %>" style="display: none" class="person-card__image" - alt="Member headshot for <%= h person.name %>"> + alt="Member headshot for <%= escape_html(person.name) %>"> + alt="Member headshot for <%= escape_html(person.name) %>"> <% else %> Placeholder image for <%= h person.name %> + alt="Placeholder image for <%= escape_html(person.name) %>"> <% end %>

<%= person.name %>

@@ -198,7 +198,7 @@
<% if @page.data_sources %> -

Main Source<% if @page.data_sources.size > 1 %>s<% end %>: <%= @page.data_sources.map { |url| %Q(#{url}) }.join(", ") %>

+

Main Source<% if @page.data_sources.size > 1 %>s<% end %>: <%= @page.data_sources.map { |url| %Q(#{url}) }.join(", ") %>

<% end %>

Anything wrong? If you've spotted an error, or the data is incomplete, here's how to get that fixed.