|
1 | 1 | require 'rails_helper'
|
2 | 2 |
|
3 | 3 | describe SortableBy::TableHelper, type: :helper do
|
4 |
| - describe '#sortable_table_header' do |
5 |
| - it 'generates an html table header' |
| 4 | + it 'returns a table header with rows' do |
| 5 | + result = helper.sortable_table_header(:users_path) |
| 6 | + expect(result).to include('<thead class="tb-table-header"><tr></tr></thead>') |
| 7 | + expect(result).to include('</thead>') |
6 | 8 | end
|
| 9 | + |
| 10 | + it 'has some headers' do |
| 11 | + result = helper.sortable_table_header(:users_path, model: User) do |t| |
| 12 | + view.concat(t.header(:first_name)) |
| 13 | + view.concat(t.header(:email)) |
| 14 | + end |
| 15 | + expect(result).to include('<th>First name</th>') |
| 16 | + expect(result).to include('<th>Email</th>') |
| 17 | + end |
| 18 | + |
| 19 | + it 'generates links' do |
| 20 | + result = helper.sortable_table_header(:users_path, model: User) do |t| |
| 21 | + view.concat(t.sortable(:first_name)) |
| 22 | + view.concat(t.sortable(:email)) |
| 23 | + end |
| 24 | + expect(result).to include('<a href="/users?dir=asc&sort=first_name">First name</a>') |
| 25 | + expect(result).to include('<a href="/users?dir=asc&sort=email">Email</a>') |
| 26 | + end |
| 27 | + |
| 28 | + it 'sets the active class' do |
| 29 | + helper.params[:sort] = 'first_name' |
| 30 | + helper.params[:dir] = 'desc' |
| 31 | + result = helper.sortable_table_header(:users_path, model: User) do |t| |
| 32 | + view.concat(t.sortable(:first_name)) |
| 33 | + end |
| 34 | + expect(result).to include('<th class="sortable sortable-active sortable-desc">') |
| 35 | + end |
| 36 | + |
7 | 37 | end
|
0 commit comments