summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Silvera <noah@super.gd>2021-02-08 14:45:58 -0800
committerNicholas Van Doorn <vandoorn.nick@gmail.com>2021-05-03 15:46:41 -0700
commitfaeb71ec4cfd04e4a9ead2e7af90af9b41f2596b (patch)
tree63076fdef78b17084c36a820f4bffe2a296625c5
parentcc94f6633b24633952e36956cc3fe6267b2373ef (diff)
Add basic UI for Taxjar settings in solidus admin
This commit adds a tab to the taxes section of the solidus admin settings. This provides the foundation for further configuration of taxjar through the solidus admin. The settings should be hidden if an API key has not been provided. This is to conform to the certification guidelines for an official Taxjar extension. Co-authored-by: Nick Van Doorn <nick@super.gd>
-rw-r--r--app/controllers/spree/admin/taxjar_settings_controller.rb8
-rw-r--r--app/overrides/spree/admin/shared/_configuration_menu.rb11
-rw-r--r--app/views/spree/admin/taxjar_settings/show.html.erb12
-rw-r--r--config/routes.rb7
-rw-r--r--spec/features/spree/admin/taxjar_settings_spec.rb45
5 files changed, 83 insertions, 0 deletions
diff --git a/app/controllers/spree/admin/taxjar_settings_controller.rb b/app/controllers/spree/admin/taxjar_settings_controller.rb
new file mode 100644
index 0000000..a3a54b4
--- /dev/null
+++ b/app/controllers/spree/admin/taxjar_settings_controller.rb
@@ -0,0 +1,8 @@
+module Spree
+ module Admin
+ class TaxjarSettingsController < Spree::Admin::BaseController
+ def show
+ end
+ end
+ end
+end
diff --git a/app/overrides/spree/admin/shared/_configuration_menu.rb b/app/overrides/spree/admin/shared/_configuration_menu.rb
new file mode 100644
index 0000000..89d9a60
--- /dev/null
+++ b/app/overrides/spree/admin/shared/_configuration_menu.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+Deface::Override.new(
+ virtual_path: 'spree/admin/shared/_taxes_tabs',
+ name: 'add_taxjar_admin_menu_links',
+ insert_bottom: "[data-hook='admin_settings_taxes_tabs']"
+) do
+ <<-HTML
+ <%= configurations_sidebar_menu_item "TaxJar Settings", admin_taxjar_settings_path %>
+ HTML
+end
diff --git a/app/views/spree/admin/taxjar_settings/show.html.erb b/app/views/spree/admin/taxjar_settings/show.html.erb
new file mode 100644
index 0000000..c66e646
--- /dev/null
+++ b/app/views/spree/admin/taxjar_settings/show.html.erb
@@ -0,0 +1,12 @@
+<%= render 'spree/admin/shared/taxes_tabs' %>
+
+<% content_for :page_title do %>
+ <%= "Taxjar Settings" %>
+<% end %>
+
+<% if ENV["TAXJAR_API_KEY"] %>
+ <table>
+ </table>
+<% else %>
+ <p>You must provide a TaxJar API token to configure the extension. Please see the extension readme for details.</p>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000..36ac61d
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+Spree::Core::Engine.routes.draw do
+ namespace :admin do
+ resource :taxjar_settings, only: [:show]
+ end
+end
diff --git a/spec/features/spree/admin/taxjar_settings_spec.rb b/spec/features/spree/admin/taxjar_settings_spec.rb
new file mode 100644
index 0000000..7e7e106
--- /dev/null
+++ b/spec/features/spree/admin/taxjar_settings_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+RSpec.feature 'Admin TaxJar Settings', js: true do
+ stub_authorization!
+
+ background do
+ create :store, default: true
+ end
+
+ describe "Taxjar settings tab" do
+ before do
+ allow(ENV).to receive(:[]).and_return("")
+ allow(ENV).to receive(:[]).with("TAXJAR_API_KEY").and_return(api_token)
+ end
+
+ context "Taxjar API token is set" do
+ let(:api_token) { "token" }
+
+ it "shows a blank settings page" do
+
+ visit "/admin"
+ click_on "Settings"
+ expect(page).to have_content("Taxes")
+ click_on "Taxes"
+ expect(page).to have_content("TaxJar Settings")
+ click_on "TaxJar Settings"
+ expect(page).not_to have_content "You must provide a TaxJar API token"
+ end
+ end
+
+ context "Taxjar API token isn't set" do
+ let(:api_token) { nil }
+
+ it "shows a descriptive error message" do
+ visit "/admin"
+ click_on "Settings"
+ expect(page).to have_content("Taxes")
+ click_on "Taxes"
+ expect(page).to have_content("TaxJar Settings")
+ click_on "TaxJar Settings"
+ expect(page).to have_content "You must provide a TaxJar API token"
+ end
+ end
+ end
+end