Skip to content

Commit

Permalink
add unit helper test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpatrickpatrick committed Jan 24, 2024
1 parent f726ab0 commit 4f7031d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
15 changes: 1 addition & 14 deletions app/helpers/navigation_items_helper.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
module NavigationItemsHelper
# [
# {
# text: "Publications", href: root_path
# },
# ].concat(current_user.govuk_editor? ? [
# { text: 'Add artefact', href: new_artefact_path },
# { text: 'Downtime', href: downtimes_path }
# ]: []).concat([
# { text: 'Reports', href: reports_path },
# { text: 'Search by user', href: user_search_path },
# { text: 'Sign out', href: '/auth/gds/sign_out' }
# ]

def navigation_items(is_editor)

Check failure on line 2 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/IndentationStyle: Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)

Check failure on line 2 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/IndentationWidth: Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
list = [

Check failure on line 3 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/IndentationStyle: Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)

Check failure on line 3 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/IndentationWidth: Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
{ text: "Publications", href: root_path }

Check failure on line 4 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/IndentationStyle: Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)

Check failure on line 4 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is.

Check failure on line 4 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInArrayLiteral: Put a comma after the last item of a multiline array. (https://rubystyle.guide#no-trailing-array-commas)
Expand All @@ -24,6 +11,6 @@ def navigation_items(is_editor)

list << { text: 'Reports', href: reports_path }
list << { text: 'Search by user', href: user_search_path }
list << { text: 'Sign out', href: '/auth/gds/sign_out' }
list << { text: 'Sign out', href: '/auth/gds/sign_out' }
end
end
25 changes: 25 additions & 0 deletions test/unit/helpers/naviation_items_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "test_helper"

class NavigationItemsHelperTest < ActionView::TestCase
context "NavigationItemsHelper" do
should "include editor only links when user is an editor" do
assert_equal [
{ text: "Publications", href: root_path },
{ text: 'Add artefact', href: new_artefact_path },
{ text: 'Downtime', href: downtimes_path },
{ text: 'Reports', href: reports_path },
{ text: 'Search by user', href: user_search_path },
{ text: 'Sign out', href: '/auth/gds/sign_out' }
], navigation_items(true)
end

should "include not include editor only links when user is not an editor" do
assert_equal [
{ text: "Publications", href: root_path },
{ text: 'Reports', href: reports_path },
{ text: 'Search by user', href: user_search_path },
{ text: 'Sign out', href: '/auth/gds/sign_out' }
], navigation_items(false)
end
end
end

0 comments on commit 4f7031d

Please sign in to comment.