Skip to content

Commit

Permalink
path_selector to support initial directory w/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Sep 13, 2023
1 parent 4c5905b commit d72a1e0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ function makeTable(element) {
function getPathSelectorOptions(element) {
options = {};

options.filesPath = element.dataset['filesPath'];
options.homeDirectory = element.dataset['homeDirectory'];
options.tableId = element.dataset['tableId'];
options.breadcrumbId = element.dataset['breadcrumbId'];
options.selectButtonId = element.dataset['selectButtonId'];
options.inputFieldId = element.dataset['inputFieldId'];
options.modalId = element.id;
options.filesPath = element.dataset['filesPath'];
options.initialDirectory = element.dataset['initialDirectory'];
options.tableId = element.dataset['tableId'];
options.breadcrumbId = element.dataset['breadcrumbId'];
options.selectButtonId = element.dataset['selectButtonId'];
options.inputFieldId = element.dataset['inputFieldId'];
options.modalId = element.id;

return options;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ export class PathSelectorTable {
_table = null;

// input data that should be passed into the constructor
tableId = undefined;
filesPath = undefined;
breadcrumbId = undefined;
homeDirectory = undefined;
selectButtonId = undefined;
inputFieldId = undefined;
modalId = undefined;
tableId = undefined;
filesPath = undefined;
breadcrumbId = undefined;
initialDirectory = undefined;
selectButtonId = undefined;
inputFieldId = undefined;
modalId = undefined;

constructor(options) {
this.tableId = options.tableId;
this.filesPath = options.filesPath;
this.breadcrumbId = options.breadcrumbId;
this.homeDirectory = options.homeDirectory;
this.selectButtonId = options.selectButtonId;
this.inputFieldId = options.inputFieldId;
this.modalId = options.modalId;
this.tableId = options.tableId;
this.filesPath = options.filesPath;
this.breadcrumbId = options.breadcrumbId;
this.initialDirectory = options.initialDirectory;
this.selectButtonId = options.selectButtonId;
this.inputFieldId = options.inputFieldId;
this.modalId = options.modalId;

this.initDataTable();
this.reloadTable(this.initialUrl());
Expand Down Expand Up @@ -139,7 +139,7 @@ export class PathSelectorTable {
getLastVisited() {
const lastVisited = localStorage.getItem(this.storageKey());
if(lastVisited === null) {
return this.homeDirectory;
return this.initialDirectory;
} else {
return lastVisited;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<%
show_hidden = false
show_files = false

inital_directory = attrib.opts[:directory] || CurrentUser.home

if attrib.opts[:options].is_a?(Array)
show_hidden = attrib.opts[:options].include? 'hidden'
show_files = attrib.opts[:options].include? 'files'
Expand All @@ -26,15 +29,15 @@
aria-labelledby="modal-path-selector" aria-hidden="true"
data-path-selector-show-files="<%= show_files %>"
data-path-selector-show-hidden="<%= show_hidden %>"
data-home-directory="<%= Dir.home %>"
data-initial-directory="<%= inital_directory %>"
data-files-path="<%= files_path %>"
data-table-id="<%= table_id %>"
data-breadcrumb-id="<%= breadcrumb_id %>"
data-select-button-id="<%= button_id %>"
data-input-field-id="<%= input_field_id %>"
>

<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal-path-selector-title">Select Your Working Directory</h5>
Expand Down
43 changes: 43 additions & 0 deletions apps/dashboard/test/system/batch_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -845,4 +845,47 @@ def stub_git(dir)
assert_equal 'pzs1124', find_value('auto_accounts')
end
end

test 'path_selector works' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
SysRouter.stubs(:base_path).returns(Pathname.new(dir))
stub_scontrol
stub_sacctmgr
stub_git("#{dir}/app")

form = <<~HEREDOC
---
cluster:
- owens
form:
- path
attributes:
path:
widget: 'path_selector'
directory: "#{Rails.root}"
HEREDOC

Pathname.new("#{dir}/app/").join('form.yml').write(form)
base_id = 'batch_connect_session_context_path'

visit new_batch_connect_session_context_url('sys/app')
click_on('Select Path')
sleep 1

# assert that all the rows in the table are real. It should be showing the files in Rails.root
find("##{base_id}_path_selector_table").all('tbody tr') do |table_row|
table_datas = table_row.all('td')
row_text = table_datas[1].find('span').text
real_file = Pathname.new(Rails.root).join(row_text)
assert(real_file.exist?)
end

find('span', text: 'test').click
find("##{base_id}_path_selector_button").click

text_field = find("##{base_id}")
assert_equal("#{Rails.root}/test", text_field.value)
end
end
end

0 comments on commit d72a1e0

Please sign in to comment.