Skip to content

Commit

Permalink
test: Write system test for happy path of creating a new schema entry
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrubisch committed Nov 26, 2024
1 parent ba830e3 commit deacacc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,5 @@ gem "pagy", "> 8"
gem "csv"

gem "avo-meta", github: "avo-hq/avo-meta", branch: "main"

gem "store_model"
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT

GIT
remote: https://github.com/avo-hq/avo-meta.git
revision: 874345836c3e686c2d716a0ae542caaad3aa8cab
revision: 9411e7a21a3f15b4c3e8a77c1b8df15f879be93d
branch: main
specs:
avo-meta (0.1.0)
Expand Down Expand Up @@ -762,6 +762,7 @@ DEPENDENCIES
spring-commands-rspec
sprockets-rails
standard
store_model
test-prof
tzinfo-data
web-console (>= 3.3.0)
Expand Down
11 changes: 10 additions & 1 deletion db/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

factory :project do
name { Faker::App.name }
status { ['closed', :rejected, :failed, 'loading', :running, :waiting].sample }
status { ["closed", :rejected, :failed, "loading", :running, :waiting].sample }
stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled", "Drafting"].sample }
budget { Faker::Number.decimal(l_digits: 4) }
country { Faker::Address.country_code }
Expand Down Expand Up @@ -148,4 +148,13 @@
name { Faker::Company.name }
size { ["small", "medium", "large"].sample }
end

factory :meta_schema, class: "Avo::Meta::Schema" do
resource_name { "User" }
schema_entries {
[
Avo::Meta::SchemaEntry.new(name: "shoe_size", type: "integer", as: "number")

Check failure on line 156 in db/factories.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Corrected] Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is. Raw Output: db/factories.rb:156:11: C: [Corrected] Layout/FirstArrayElementIndentation: Use 2 spaces for indentation in an array, relative to the start of the line where the left square bracket is. Avo::Meta::SchemaEntry.new(name: "shoe_size", type: "integer", as: "number") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]
}
end
end
46 changes: 46 additions & 0 deletions spec/system/avo/meta/user_meta_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "rails_helper"

RSpec.describe "UserMeta", type: :system do
let!(:user) { create :user }
let!(:schema) { create :meta_schema }

it "allows to add new entries to the user meta schema" do
visit "/admin/resources/meta_schemas"

click_on "User"
end

it "allows to add new entries to the user meta schema, which can instantly be used" do
visit "/admin/resources/meta_schemas"

within "#avo_meta_schemas_list" do
find("td", text: "User").click
end

click_on "Edit"

click_on "Add a new property"

fill_in "Name", with: "nickname"
select "string", from: find('select[name*="[schema_entries_attributes]["][name*="][type]"]')[:id]
select "text", from: find('select[name*="[schema_entries_attributes]["][name*="][as]"]')[:id]

save

expect(page).to have_text("Meta schema was successfully updated")

# assert that the new attribute is actually present and editable
visit avo.resources_user_path(User.last)

expect(page).to have_text("Meta")
expect(page).to have_text("NICKNAME")

click_on "Edit"

fill_in "user_meta_nickname", with: "Ace Ventura"

save

expect(page).to have_text("Ace Ventura")
end
end

0 comments on commit deacacc

Please sign in to comment.