Skip to content

Commit

Permalink
Fix non working days behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Aug 15, 2024
1 parent 9e62fed commit 8f4219c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="spot-input"
[attr.data-value]="value"
[id]="id"
[(ngModel)]="value"
[ngModel]="value"
(ngModelChange)="changeValueFromInputDebounced($event)"
(click)="onInputClick($event)"
(focus)="opened = true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export class OpModalSingleDatePickerComponent implements ControlValueAccessor, O
},
this.flatpickrTarget.nativeElement as HTMLElement,
);
this.cdRef.detectChanges();
}

writeWorkingValue(value:string):void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class OpNonWorkingDaysListComponent implements OnInit, AfterViewInit {
.forEach((el) => {
this.nonWorkingDays.push({ ...el });
});
this.cdRef.detectChanges();
}

ngAfterViewInit():void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ import { findAllFocusableElementsWithin } from 'core-app/shared/helpers/focus-he
import { SpotDropModalTeleportationService } from './drop-modal-teleportation.service';
import { filter, take } from 'rxjs/operators';
import { debounce } from 'lodash';
import {
autoUpdate,
computePosition,
flip,
limitShift,
Placement,
shift,
} from '@floating-ui/dom';
import { autoUpdate, computePosition, flip, limitShift, Placement, shift } from '@floating-ui/dom';

@Component({
selector: 'spot-drop-modal',
Expand Down Expand Up @@ -180,6 +173,8 @@ export class SpotDropModalComponent implements OnDestroy {
// Index 1 because the element at index 0 is the trigger button to open the modal
(findAllFocusableElementsWithin(document.querySelector('.spot-drop-modal-portal')!)[1])?.focus();
}

this.cdRef.detectChanges();
});
});
}
Expand Down
18 changes: 10 additions & 8 deletions spec/features/admin/working_days_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
CHART

let(:dialog) { Components::ConfirmationDialog.new }
let(:datepicker) { Components::Datepicker.new }
let(:datepicker) { Components::DatepickerModal.new }

current_user { admin }

Expand Down Expand Up @@ -187,7 +187,8 @@ def working_days_setting
end

it "can add non-working days" do
click_on "Non-working day"
# Initial loading can sometimes take a while
datepicker.open_modal!

# Check if a date is correctly highlighted after selecting it in different time zones
datepicker.select_day 5
Expand All @@ -197,14 +198,15 @@ def working_days_setting
within_test_selector("op-datepicker-modal") do
click_on "Cancel"
end
click_on "Non-working day"

datepicker.open_modal!

within_test_selector("op-datepicker-modal") do
fill_in "name", with: "My holiday"
end

date1 = NonWorkingDay.maximum(:date).next_week(:monday).next_occurring(:monday)
datepicker.set_date date1
datepicker.set_date_input(date1)

within_test_selector("op-datepicker-modal") do
click_on "Add"
Expand All @@ -220,7 +222,7 @@ def working_days_setting
end

date2 = NonWorkingDay.maximum(:date).next_week(:monday).next_occurring(:tuesday)
datepicker.set_date date2
datepicker.set_date_input(date2)

within_test_selector("op-datepicker-modal") do
click_on "Add"
Expand All @@ -238,12 +240,12 @@ def working_days_setting
expect(nwd2.date).to eq date2

# Check if date and name are entered then close the datepicker
click_on "Non-working day"

datepicker.open_modal!
within_test_selector("op-datepicker-modal") do
click_on "Add"
end
expect(page).to have_css(".flatpickr-calendar")

expect(page).to have_css(".flatpickr-calendar", wait: 5)
datepicker.expect_visible

within_test_selector("op-datepicker-modal") do
Expand Down
3 changes: 1 addition & 2 deletions spec/support/components/datepicker/datepicker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def expect_month(month)
expect(field.value.to_i).to eq(month - 1)
end

##
# Expect the selected day
# Expect the selected day in the input
def expect_day(value)
expect(flatpickr_container).to have_css(".flatpickr-day.selected", text: value)
end
Expand Down
21 changes: 21 additions & 0 deletions spec/support/components/datepicker/datepicker_modal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Components
class DatepickerModal < Datepicker
def open_modal!
retry_block do
click_on "Non-working day", wait: 10
unless page.has_css?(".flatpickr-calendar")
click_on "Cancel"
raise "Flatpickr should render a calendar"
end
end
end

def set_date_input(date)
retry_block do
set_date(date)
input = find_field("date")
raise "Expected date to equal #{date}, but got #{input.value}" unless input.value == date.iso8601
end
end
end
end

0 comments on commit 8f4219c

Please sign in to comment.