fix(cli): filter outage schedule by selected bill
This commit is contained in:
10
README.md
10
README.md
@@ -215,7 +215,7 @@ minute interval with `-i`/`--interval`:
|
||||
./main.sh --interval 5
|
||||
```
|
||||
|
||||
Select one bill for the large countdown with `-b`/`--bill-id`:
|
||||
Select one bill for the countdown and outage schedule with `-b`/`--bill-id`:
|
||||
|
||||
```sh
|
||||
./main.sh --bill-id 7356609804429
|
||||
@@ -223,10 +223,10 @@ Select one bill for the large countdown with `-b`/`--bill-id`:
|
||||
|
||||
The dashboard uses Tehran time to show a large `HH : mm : ss` countdown for the
|
||||
selected bill's ongoing or nearest upcoming outage. The compact schedule below
|
||||
continues to list active current and future events for every bill, including
|
||||
emergency outages. If the selected bill has no qualifying outage, the countdown
|
||||
area says so while the full schedule remains visible. Without `--bill-id`, the
|
||||
countdown retains the original behavior and selects across all bills.
|
||||
is also limited to that bill's active current and future events, including
|
||||
emergency outages. If the selected bill has no qualifying outage, the dashboard
|
||||
shows `ALL CLEAR`. Without `--bill-id`, the countdown and schedule include all
|
||||
bills.
|
||||
|
||||
The terminal output uses English-only labels and omits the stored address and
|
||||
reason text. When there are no qualifying events for any bill it prints an `ALL
|
||||
|
||||
5
main.sh
5
main.sh
@@ -68,7 +68,7 @@ repository state. The countdown updates every second.
|
||||
|
||||
Options:
|
||||
-i, --interval MINUTES Refetch state at this interval (default: 10)
|
||||
-b, --bill-id BILL_ID Use only this bill for the large countdown
|
||||
-b, --bill-id BILL_ID Show the countdown and schedule for this bill only
|
||||
-h, --help Show this help
|
||||
|
||||
Environment:
|
||||
@@ -334,6 +334,9 @@ build_schedule() {
|
||||
|
||||
while IFS= read -r record; do
|
||||
record_fields "$record" fields
|
||||
if [[ -n "$countdown_bill_id" && "${fields[0]}" != "$countdown_bill_id" ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ "${fields[2]}" != "active" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -143,8 +143,8 @@ assert_contains "${SCHEDULE[2]}" '"outage_number":"5"' \
|
||||
"later events should remain in the schedule"
|
||||
|
||||
build_schedule "$FIXTURE" "$NOW_EPOCH" "222"
|
||||
assert_equal "3" "${#SCHEDULE[@]}" \
|
||||
"selecting a countdown bill should not filter the schedule"
|
||||
assert_equal "1" "${#SCHEDULE[@]}" \
|
||||
"selecting a bill should filter the schedule"
|
||||
assert_equal "UPCOMING" "${HERO%%$'\t'*}" \
|
||||
"the countdown should ignore another bill's ongoing outage"
|
||||
assert_contains "$HERO" '"bill_id":"222"' \
|
||||
@@ -152,17 +152,21 @@ assert_contains "$HERO" '"bill_id":"222"' \
|
||||
SELECTED_OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH" 80 "222")"
|
||||
assert_contains "$SELECTED_OUTPUT" "COUNTDOWN FOR BILL 222" \
|
||||
"the selected countdown bill should be labeled"
|
||||
assert_contains "$SELECTED_OUTPUT" "OUTAGE SCHEDULE (3)" \
|
||||
"the selected countdown bill should not hide other bills from the list"
|
||||
assert_contains "$SELECTED_OUTPUT" "OUTAGE SCHEDULE (1)" \
|
||||
"the schedule should contain only the selected bill"
|
||||
if [[ "$SELECTED_OUTPUT" == *"Bill 111"* ]]; then
|
||||
printf 'FAIL: selected bill output contains another bill\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
build_schedule "$FIXTURE" "$NOW_EPOCH" "333"
|
||||
assert_equal "" "$HERO" \
|
||||
"a bill without upcoming outages should not borrow another bill's countdown"
|
||||
assert_equal "0" "${#SCHEDULE[@]}" \
|
||||
"a bill without upcoming outages should have an empty schedule"
|
||||
NO_HERO_OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH" 80 "333")"
|
||||
assert_contains "$NO_HERO_OUTPUT" "NO CURRENT OR UPCOMING OUTAGE" \
|
||||
"a selected bill without outages should have a clear countdown status"
|
||||
assert_contains "$NO_HERO_OUTPUT" "OUTAGE SCHEDULE (3)" \
|
||||
"all bills should remain listed when the selected bill has no outage"
|
||||
assert_contains "$NO_HERO_OUTPUT" "ALL CLEAR" \
|
||||
"a selected bill without outages should render the all-clear screen"
|
||||
|
||||
build_schedule "$FIXTURE" "$NOW_EPOCH"
|
||||
OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH")"
|
||||
|
||||
Reference in New Issue
Block a user