haya_select_helpers 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a348101b6da85afd0df9db80c82d5cd188be662db011e0995a35d45f89f00045
4
+ data.tar.gz: 59c5485f9bbe4a83fbd3aa3651ea6c3ab23e1a558533295d2c8e0554fd2cef8a
5
+ SHA512:
6
+ metadata.gz: 74fdca47f2d4c9e0197c3d989863745558b9d947bc2d7d01c03b6ab80f8efbff58aa613654c8852480cd17bfd3d98135ab737f2818dcb3a457d846234d8544b7
7
+ data.tar.gz: d5792877058bdf08a880a4924e4bdb48fee81b34ea4c07ba242e590de4ad78a3b6ebbd68c4561577a7e9e93008467b7978defa0c63caf914edef66efd9f7ecf2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 kaspernj
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # HayaSelectHelpers
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "haya_select_helpers"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install haya_select_helpers
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/haya_select_helpers .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module HayaSelectHelpers
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module HayaSelectHelpers
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module HayaSelectHelpers
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module HayaSelectHelpers
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module HayaSelectHelpers
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Haya select helpers</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "haya_select_helpers/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ HayaSelectHelpers::Engine.routes.draw do
2
+ end
@@ -0,0 +1,88 @@
1
+ class HayaSelect
2
+ attr_reader :base_selector, :not_opened_current_selected_selector, :opened_current_selected_selector, :options_selector, :scope
3
+
4
+ delegate :all, :expect, :eq, :pretty_html, :wait_for_and_find, :wait_for_expect, :wait_for_no_selector, :wait_for_selector, to: :scope
5
+
6
+ def initialize(id:, scope:)
7
+ @base_selector = ".haya-select[data-id='#{id}']"
8
+ @not_opened_current_selected_selector = "#{base_selector} .haya-select-current-selected[data-opened='false']"
9
+ @opened_current_selected_selector = "#{base_selector} .haya-select-current-selected[data-opened='true']"
10
+ @options_selector = ".haya-select-options-container[data-id='#{id}']"
11
+ @scope = scope
12
+ end
13
+
14
+ def label
15
+ wait_for_and_find("#{base_selector} .haya-select-current-selected .current-option").text
16
+ end
17
+
18
+ def open
19
+ wait_for_and_find("#{base_selector} .haya-select-current-selected[data-opened='false']").click
20
+ wait_for_selector opened_current_selected_selector
21
+ wait_for_selector options_selector
22
+ self
23
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError
24
+ retry
25
+ end
26
+
27
+ def options
28
+ wait_for_selector "#{options_selector} .haya-select-option"
29
+ option_elements = all("#{options_selector} .haya-select-option")
30
+ option_elements.map do |option_element|
31
+ {
32
+ label: option_element.text,
33
+ value: option_element["data-value"]
34
+ }
35
+ end
36
+ end
37
+
38
+ def wait_for_options(expected_options)
39
+ wait_for_expect do
40
+ expect(options).to eq expected_options
41
+ end
42
+ end
43
+
44
+ def search(value)
45
+ wait_for_and_find("#{base_selector} .haya-select-search-text-input").set(value)
46
+ end
47
+
48
+ def select(label)
49
+ open
50
+ select_option(label: label)
51
+ wait_for_selector not_opened_current_selected_selector
52
+ wait_for_no_selector options_selector
53
+ self
54
+ end
55
+
56
+ def select_option(label:)
57
+ wait_for_and_find("#{options_selector} .haya-select-option", exact_text: label).click
58
+ self
59
+ end
60
+
61
+ def value
62
+ wait_for_and_find("#{base_selector} .haya-select-current-selected input[type='hidden']", visible: false)[:value]
63
+ end
64
+
65
+ def wait_for_label(expected_label)
66
+ wait_for_selector "#{base_selector} .haya-select-current-selected .current-option", exact_text: expected_label
67
+ self
68
+ end
69
+
70
+ def wait_for_toggles(expected_toggles)
71
+ wait_for_expect do
72
+ actual_toggles = all(".haya-select-option-presentation").map do |element|
73
+ {
74
+ toggle_icon: element["data-toggle-icon"],
75
+ toggle_value: element["data-toggle-value"],
76
+ value: element["data-value"]
77
+ }
78
+ end
79
+
80
+ expect(actual_toggles).to eq expected_toggles
81
+ end
82
+ end
83
+
84
+ def wait_for_value(expected_value)
85
+ wait_for_selector "#{base_selector} .haya-select-current-selected input[type='hidden'][value='#{expected_value}']", visible: false
86
+ self
87
+ end
88
+ end
@@ -0,0 +1,5 @@
1
+ module HayaSelectHelpers
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace HayaSelectHelpers
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module HayaSelectHelpers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "haya_select"
2
+ require "haya_select_helpers/version"
3
+ require "haya_select_helpers/engine"
4
+
5
+ module HayaSelectHelpers
6
+ def haya_select(id)
7
+ HayaSelect.new(id: id, scope: self)
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :haya_select_helpers do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haya_select_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kaspernj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.3
27
+ description: RSpec helpers for HayaSelect.
28
+ email:
29
+ - k@spernj.org
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/haya_select_helpers_manifest.js
38
+ - app/assets/stylesheets/haya_select_helpers/application.css
39
+ - app/controllers/haya_select_helpers/application_controller.rb
40
+ - app/helpers/haya_select_helpers/application_helper.rb
41
+ - app/jobs/haya_select_helpers/application_job.rb
42
+ - app/mailers/haya_select_helpers/application_mailer.rb
43
+ - app/models/haya_select_helpers/application_record.rb
44
+ - app/views/layouts/haya_select_helpers/application.html.erb
45
+ - config/routes.rb
46
+ - lib/haya_select.rb
47
+ - lib/haya_select_helpers.rb
48
+ - lib/haya_select_helpers/engine.rb
49
+ - lib/haya_select_helpers/version.rb
50
+ - lib/tasks/haya_select_helpers_tasks.rake
51
+ homepage: https://github.com/kaspernj/haya_select_helpers
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/kaspernj/haya_select_helpers
56
+ source_code_uri: https://github.com/kaspernj/haya_select_helpers
57
+ changelog_uri: https://github.com/kaspernj/haya_select_helpers
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.3.7
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: RSpec helpers for HayaSelect.
77
+ test_files: []