Skip to content

Commit

Permalink
Merge pull request #1008 from denny/dev/pager
Browse files Browse the repository at this point in the history
Add translations for more model names, use them in pager info
  • Loading branch information
denny authored Mar 12, 2021
2 parents 4fd6d89 + fa69913 commit f868bec
Show file tree
Hide file tree
Showing 42 changed files with 424 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
<tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @groups.name } %>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<% else %>
<p>
<%= t( 'shinycms.empty_list', items: 'memberships' ) %>
<%= t( 'shinycms.empty_list', items: t( 'shinycms.models.names.shiny_access_membership' ).pluralize ) %>
</p>
<% end %>

Expand Down
5 changes: 5 additions & 0 deletions plugins/ShinyAccess/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ en:
feature_flags:
access: Access Control

models:
names:
shiny_access_group: access group
shiny_access_membership: access group membership

shiny_access:
admin:
menu: Access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@
end

describe 'GET /admin/access/groups' do
it 'displays the list of access groups' do
get shiny_access.groups_path
context 'when there are no groups' do
it "displays the 'no groups found' message" do
get shiny_access.groups_path

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_access.admin.groups.index.title' ).titlecase
pager_info = 'No access groups found'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_access.admin.groups.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end

context 'when there are some groups' do
it 'displays the list of access groups' do
create_list :access_group, 3

get shiny_access.groups_path

pager_info = 'Displaying 3 access groups'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_access.admin.groups.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@
let( :group1 ) { create :access_group }

describe 'GET /admin/access/groups/1/memberships' do
it "displays the 'no items found' message" do
get shiny_access.group_memberships_path( group1 )

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_access.admin.memberships.index.title', name: group1.internal_name ).titlecase
expect( response.body ).to have_css 'p', text: 'No access group memberships found'
end

it 'displays the list of access group memberships' do
item1 = create :access_membership, group: group1
create :access_membership, group: group1

get shiny_access.group_memberships_path( group1 )

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_access.admin.memberships.index.title', name: group1.internal_name ).titlecase
expect( response.body ).to have_css 'td', text: item1.user.username
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
</tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @posts.name } %>
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,56 @@
let( :admin ) { ShinyCMS::User.first }

describe 'GET /admin/blog' do
it 'fetches the list of blog posts with less than one page of posts' do
create :blog_post
create :blog_post
create :blog_post
context 'when there are no posts' do
it "displays the 'no blog posts found' message" do
get shiny_blog.blog_posts_path

get shiny_blog.blog_posts_path
pager_info = 'No blog posts found'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end

it 'fetches the list of blog posts when its empty' do
get shiny_blog.blog_posts_path
context 'when there are less than one page of posts' do
it 'displays the list of blog posts' do
create_list :blog_post, 3

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
get shiny_blog.blog_posts_path

pager_info = 'Displaying 3 blog posts'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end

it 'fetches the list of blog posts with more than one page of posts' do
create_list :blog_post, 12
context 'when there are more than one page of posts' do
it 'fetches the first page' do
create_list :blog_post, 12

get shiny_blog.blog_posts_path
get shiny_blog.blog_posts_path

pager_info = 'Displaying items 1-10 of 12 in total' # FIXME: i18n
pager_info = 'Displaying blog posts 1-10 of 12 in total'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end

it 'fetches the second page of blog posts' do
create_list :blog_post, 12
it 'fetches the second page when requested' do
create_list :blog_post, 12

get shiny_blog.blog_posts_path, params: { page: 2 }
get shiny_blog.blog_posts_path, params: { page: 2 }

pager_info = 'Displaying items 11-12 of 12 in total' # FIXME: i18n
pager_info = 'Displaying blog posts 11-12 of 12 in total'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shiny_blog.admin.blog_posts.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</table>
<% end %>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @comments.name } %>

<script>
function toggle_select_all() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
<tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @consent_versions.name } %>
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
<tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @recipients.name } %>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @messages.name } %>

<% else %>
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<%
name ||= 'Item'
i18n_key = name.underscore.tr '/', '_'

if I18n.exists? "shinycms.models.names.#{i18n_key}"
items = t( "shinycms.models.names.#{i18n_key}" ).pluralize
elsif I18n.exists? 'shinycms.models.names.item'
items = t( 'shinycms.models.names.item' ).pluralize
else
items = 'items'
end
%>

<%== pagy_bootstrap_nav pagy %>

<p class="pager-info">
<%== pagy_info pagy %>
<%== pagy_info pagy, items %>

<%# TODO: FIXME: Oh look, the JavaScript isn't working. How terribly unusual. %#>
<br>
<%== pagy_items_selector_js pagy %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
<tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>
<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @users.name } %>
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
<% end %>
</tbody>
</table>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy } %>

<% else %>
<p>
<%= t( 'shinycms.empty_list', items: 'stats' ) %>
</p>
<% end %>

<%= render partial: 'admin/includes/pager', locals: { pagy: @pagy, name: @visits.name } %>
8 changes: 8 additions & 0 deletions plugins/ShinyCMS/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ en:
# Models

models:
names:
item: item # generic fallback
ahoy_visit: visit
shinycms_comment: comment
shinycms_consent_version: consent version
shinycms_email_recipient: email recipient
shinycms_user: user

anonymous_author:
anonymous: Anonymous

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,48 @@
end

describe 'GET /admin/comments' do
it 'fetches the spam comment moderation page' do
create :comment, spam: true
create :comment, spam: true
comment3 = create :comment, spam: true
context 'when there are no spam comments' do
it "displays the 'no comments found' message" do
get shinycms.comments_path

get shinycms.comments_path
pager_info = 'No comments found'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.comments.index.title' ).titlecase
expect( response.body ).to have_css 'td', text: comment3.title
expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.comments.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end

describe 'GET /admin/comments/search?q=zing' do
it 'fetches the list of matching spam comments' do
comment1 = create :comment, body: 'Zebras are zingy', spam: true
comment2 = create :comment, body: 'Aardvarks are awesome', spam: true
context 'when there are spam comments' do
it 'displays the list of comments' do
create_list :comment, 3, spam: true

get shinycms.comments_path

get shinycms.search_comments_path, params: { q: 'zing' }
pager_info = 'Displaying 3 comments'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.comments.index.title' ).titlecase

expect( response.body ).to have_css 'td', text: comment1.title
expect( response.body ).not_to have_css 'td', text: comment2.title
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end
end

describe 'GET /admin/comments/search?q=zing' do
it 'fetches the list of matching spam comments' do
comment1 = create :comment, body: 'Zebras are zingy', spam: true
comment2 = create :comment, body: 'Aardvarks are awesome', spam: true

get shinycms.search_comments_path, params: { q: 'zing' }

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.comments.index.title' ).titlecase

expect( response.body ).to have_css 'td', text: comment1.title
expect( response.body ).not_to have_css 'td', text: comment2.title
end
end

describe 'PUT /admin/comments' do
it 'reminds you that you need to select spam or not spam, if you do neither' do
put shinycms.comments_path, params: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
end

describe 'GET /admin/consent-versions' do
it 'fetches the list of consent versions' do
version = create :consent_version
it 'displays the list of consent versions' do
create_list :consent_version, 3

get shinycms.consent_versions_path

pager_info = 'Displaying 4 consent versions' # including one from seed data

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.consent_versions.index.title' ).titlecase
expect( response.body ).to have_css 'td', text: version.name
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@
end

describe 'GET /admin/email-recipients' do
it 'fetches the list of email recipients' do
recipient1 = create :email_recipient
create :email_recipient
create :email_recipient
context 'when there are no email recipients' do
it "displays the 'no email recipients found' message" do
get shinycms.email_recipients_path

get shinycms.email_recipients_path
pager_info = 'No email recipients found'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.email_recipients.index.title' ).titlecase
expect( response.body ).to have_css 'td', text: recipient1.name
expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.email_recipients.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end

it 'displays an appropriate message if there are no email recipients yet' do
get shinycms.email_recipients_path
context 'when there are email recipients' do
it 'displays the list of email recipients' do
create_list :email_recipient, 3

none_found = 'No items found' # TODO: i18n
get shinycms.email_recipients_path

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.email_recipients.index.title' ).titlecase
expect( response.body ).to have_css 'p', text: none_found
pager_info = 'Displaying 3 email recipients'

expect( response ).to have_http_status :ok
expect( response.body ).to have_title I18n.t( 'shinycms.admin.email_recipients.index.title' ).titlecase
expect( response.body ).to have_css '.pager-info', text: pager_info
end
end
end

Expand Down
Loading

0 comments on commit f868bec

Please sign in to comment.