UITest DateTimePicker - xcode-ui-testing

I'm trying to UITest a form Built with Eureka forms on my iOS Swift project.
Here's how the picker wheel looks. Its a TimeRow() on Eureka
The problem is my UITest is unable to move the DateField. Its only able to move the hours and minutes field. Here's the UITtest code
func testSetTime() {
app.tables.cells.containing(.staticText, identifier: "Departure Time").element.tap()
// unable to get this to work.
app.datePickers.pickerWheels.element(boundBy: 0).adjust(toPickerWheelValue: "May 14")
// these lines work perfectly.
app.datePickers.pickerWheels.element(boundBy: 1).adjust(toPickerWheelValue: "01")
app.datePickers.pickerWheels.element(boundBy: 2).adjust(toPickerWheelValue: "00")
app.buttons["Done"].firstMatch.tap()
}
The error after running is as follows.
Unable to find current value 'May 17' in possible values 28 Mar, 29 Mar, 30 Mar, 31 Mar, 1 Apr, 2 Apr, 3 Apr, 4 Apr, 5 Apr, 6 Apr, 7 Apr, 8 Apr, 9 Apr, 10 Apr, 11 Apr, 12 Apr, 13 Apr, 14 Apr, 15 Apr, 16 Apr, 17 Apr, 18 Apr, 19 Apr, 20 Apr, 21 Apr, 22 Apr, 23 Apr, 24 Apr, 25 Apr, 26 Apr, 27 Apr, 28 Apr, 29 Apr, 30 Apr, 1 May, 2 May, 3 May, 4 May, 5 May, 6 May, 7 May, 8 May, 9 May, 10 May, 11 May, 12 May, 13 May, 14 May, 15 May, 16 May, 17 May, 18 May, 19 May, 20 May, 21 May, 22 May, 23 May, 24 May, 25 May, 26 May, 27 May, 28 May, 29 May, 30 May, 31 May, 1 Jun, 2 Jun, 3 Jun, 4 Jun, 5 Jun, 6 Jun, 7 Jun, 8 Jun, 9 Jun, 10 Jun, 11 Jun, 12 Jun, 13 Jun, 14 Jun, 15 Jun, 16 Jun, 17 Jun, 18 Jun, 19 Jun, 20 Jun, 21 Jun, 22 Jun, 23 Jun, 24 Jun, 25 Jun, 26 Jun, 27 Jun, 28 Jun, 29 Jun, 30 Jun, 1 Jul, 2 Jul, 3 Jul, 4 Jul, 5 Jul for the picker wheel "Today" PickerWheel

Well, the framework specifies the problem fully you should use 17 May instead of May 17.
app.pickerWheels.firstMatch.adjust(toPickerWheelValue: "17 May")
UPD
I have tried to interact with alike picker in the Calendar app (Xcode 11.4)
Works just fine
class siguiente: XCTestCase {
func testExample() {
// Given
let app = XCTApps.calendar.app
app.launch()
app.buttons["Add"].tap()
app.staticTexts["Starts"].tap()
// When
let dateWheel = app.pickerWheels.firstMatch
app.pickerWheels.firstMatch.adjust(toPickerWheelValue: "May 21")
// Then
XCTAssertEqual(dateWheel.value as? String, "Thu, May 21")
}
}

Related

How to handle multiple updates that result in less and more number of records

When multiple records are updated through the same form for a weekly schedule, the number of scheduled days and times can change. How to handle this?
schedules Table
id, location_id, service_id, user_id, start_date, end_date, (few more)
1 3 2 6 2020-06-23 2020-08-23
schedule_day_times Table (Before Update)
id, schedule_id(fk), day_name(between 1 to 7), start_time, end_time
1 1 2 08:00 am 10:00 am
2 1 2 11:00 am 02:00 pm
3 1 3 08:00 am 11:00 am
4 1 4 09:00 am 11:00 am
5 1 4 12:30 pm 2:00 pm
6 1 4 02:30 pm 4:00 pm
Relationship - schedules table has many schedule_day_times
After Update
id, schedule_id(fk), day_name(between 1 to 7), start_time, end_time
1 1 1 09:00 am 11:00 am
2 1 2 11:00 am 02:00 pm
3 1 4 08:00 am 11:00 am
4 1 4 12:00 pm 02:00 pm
5 1 5 09:30 am 11:00 am
6 1 5 02:30 pm 4:00 pm
7 1 5 05:30 pm 7:00 pm
Updates result in changed day_name, start_time, and end_time as in the above example.
Other Information - Form submit is same for both the tables.
What should be the best approach in this situation?

Get Future Years based on a field on a Table for an Employee

I have a requirement to get the future years based on a field available for employee on the Employee table and the benefits date ,Below are the two tables and the expected output is shown below for the two employess XYZ and ABC.
Tabular Data for Employee
Employee benefit Date table
Expected Output
Case 1 --Say an Employee XYZ has value of 5 and the query is run for 03/31/2020 ,then the query would need to return as below
Input - 03/31/2020
Expected Output in rows
2020
2021
2022
2023
2024
2025+
Case 2
Say an Employee ABC has value of 10 and the query is run for 03/31/2020 ,then the query would need to return as below
Input - 03/31/2020
Expected Output in rows--
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030+
Requesting for logic to derive the years based on employee table second column and all the years above it should be shown as (year)+.
I have tried using case statements for getting years ,but would like to get someassiatcne to this dynamically based on the value field.
Thanks in Advance.
This is one option; See comments within code.
SQL> with
2 -- sample data
3 emp (employee, years) as
4 (select 'XYZ', 5 from dual union all
5 select 'ABC', 10 from dual
6 ),
7 benefit (employee, bdate) as
8 (select 'XYZ', 2021 + level - 1
9 from dual
10 connect by level <= 7
11 union all
12 select 'ABC', 2021 + level - 1
13 from dual
14 connect by level <= 13
15 )
16 select
17 b.employee,
18 case when b.bdate = x.bdate + e.years then to_char(b.bdate - 1) || '+'
19 else to_char(b.bdate)
20 end bdate
21 from benefit b join emp e on e.employee = b.employee
22 join (-- find MIN(bdate) per employee
23 select b1.employee,
24 min(b1.bdate) bdate
25 from benefit b1
26 group by b1.employee
27 ) x on x.employee = b.employee
28 and b.bdate <= (-- limit number of rows displayed
29 select min(b1.bdate) + e.years
30 from benefit b1
31 where b1.employee = b.employee
32 )
33 order by b.employee desc, b.bdate;
EMP BDATE
--- -----------------------------------------
XYZ 2021
XYZ 2022
XYZ 2023
XYZ 2024
XYZ 2025
XYZ 2025+
ABC 2021
ABC 2022
ABC 2023
ABC 2024
ABC 2025
ABC 2026
ABC 2027
ABC 2028
ABC 2029
ABC 2030
ABC 2030+
17 rows selected.
SQL>
Desired output you posted is kind of inconsistent; for XYZ, it says 2026+ which doesn't match ABC's 2030+ (should be 2031+) (or, XYZ should be 2025+ if ABC is correct). Anyway, that's easy to fix.

how to do a query based on a shifting schedule (day/mids/swings)

I need to pull the total number of tickets created per shift together with the running total. I have an existing query which I thought was correct but after checking, it seems that it is pulling the wrong numbers.
SELECT
TO_CHAR(TRUNC(DTTM,'Y'),'YYYY') as "DATE"
,COUNT(CASE WHEN TO_CHAR(DTTM, 'HH24:MI') BETWEEN '14:00' AND '22:00' THEN TKTNUM ELSE NULL END) AS "DAYS"
,COUNT(CASE WHEN TO_CHAR(DTTM, 'HH24:MI') BETWEEN '06:00' AND '14:00' THEN TKTNUM ELSE NULL END) AS "MIDS"
,COUNT(CASE WHEN TO_CHAR(DTTM, 'HH24:MI') NOT BETWEEN '06:00' AND '22:00' THEN TKTNUM ELSE NULL END) AS "SWINGS"
,COUNT(TKTNUM) "TOTAL"
,SUM(COUNT(TKTNUM)) OVER (ORDER BY (TRUNC(E.ESCDTTM,'Y'),'YYYY')) -- c/o Littlefoot and Stew Ashton
FROM TKTCHISTORY
GROUP BY TRUNC(E.ESCDTTM,'Y')
ORDER BY TRUNC(E.ESCDTTM,'Y')
SAMPLE DATA:
TKTNUM TKT_CREATED
INC0001 01/10/2019 1:00
INC0002 01/10/2019 23:00
INC0003 03/10/2019 5:00
INC0004 03/10/2019 9:20
INC0005 05/11/2019 15:00
DESIRED OUTPUT:
DATE DAYS MIDS SWINGS TOTAL
2019-08-01 8 13 1 22 22
2019-08-02 19 5 3 27 49
2019-08-03 23 6 6 35 84
2019-08-04 7 9 13 29 113
2019-08-05 4 17 2 23 136
2019-08-06 10 5 16 31 167
2019-08-07 3 12 11 26 193
"SWINGS" would pull tickets between 00:00 and 06:00 or 22:00 and 24:00 on the same date. For example, a ticket was generated on 02-Nov 01:00... when I pull the report it would be counted on 02-Nov for SWINGS when it should be for the 01-Nov duty.
I've come up with something that would probably help with the logic but am not 100% sure.
WITH Shift_Sched (shiftdate,shiftsched) as
(
SELECT
--sysdate
CASE
WHEN TO_CHAR(TRUNC(sysdate,'MI'),'HH24:MI') BETWEEN '06:00' AND '23:59' THEN TRUNC(sysdate,'DD')
WHEN TO_CHAR(TRUNC(sysdate,'MI'),'HH24:MI') BETWEEN '00:00' AND '05:59' THEN TRUNC(sysdate -1,'DD')
END as "SHIFT DATE",
CASE
WHEN TO_CHAR(TRUNC(sysdate,'MI'),'HH24:MI') BETWEEN '06:00' AND '14:00' THEN 'MIDS'
WHEN TO_CHAR(TRUNC(sysdate,'MI'),'HH24:MI') BETWEEN '14:00' AND '22:00' THEN 'DAYS'
ELSE 'SWINGS'
END as "SHIFT SCHED"
FROM DUAL
)
SELECT shiftdate,shiftsched,COUNT(shiftsched)
FROM shift_sched
GROUP by shiftdate,shiftsched
Any help would be greatly appreciated
If I followed you correctly, you want days from 6 AM to 6 AM the next day. If so, you can substract 6 hours to tkt_created, truncate it to day, and group by that. The rest is just conditional aggregation.
select
trunc(tkt_created - 6/24) "DATE",
sum(case when extract(hour from tkt_created) between 6 and 13 then 1 end) days,
sum(case when extract(hour from tkt_created) between 14 and 21 then 1 end) mids,
sum(case
when extract(hour from tkt_created) between 22 and 23
or extract(hour from tkt_created) between 0 and 5
then 1 end
) swings,
count(*) total
from tktchistory
group by trunc(tkt_created - 6/24)
order by "DATE"
Note: I used standard SQL extract() instead of to_char(), which is Oracle specific; apart from being standard, another advantage is that it returns an integer rather than a string.
This can also be phrased as:
select
trunc(tkt_created - 6/24) "DATE",
sum(case when extract(hour from (tkt_created) between 6 and 13 then 1 end) days,
sum(case when extract(hour from tkt_created) between 14 and 21 then 1 end) mids,
sum(case when extract(hour from (tkt_created - 6/24)) between 16 and 23 then 1 end) swings,
count(*) total
from tktchistory
group by trunc(tkt_created - 6/24)
order by "DATE"

Performance Tuning in Oracle for dynamic date join

I have a scenario where in I have to aggregate data for a dynamic 24 hour period.
For eg: If a user selects the FROM date as Jan 05 2016 8:00 AM and TO date as Jan 10 2016 2:00 AM data in the output should be aggregated from Jan 05 2016 8:00 AM to Jan 06 2016 7:59 AM as 1 day (Jan 05 2016).
Jan 5 2016 - Jan 5 2016 8:00 AM to Jan 6 2016 7:59 AM
Jan 6 2016 - Jan 6 2016 8:00 AM to Jan 7 2016 7:59 AM
Jan 7 2016 - Jan 7 2016 8:00 AM to Jan 8 2016 7:59 AM
Jan 8 2016 - Jan 8 2016 8:00 AM to Jan 9 2016 7:59 AM
Jan 9 2016 - Jan 9 2016 8:00 AM to Jan 10 2016 2:00 AM
To achieve this, I subtracted 8 hours from the date column in the fact table and joined it to the Date Dimension. The query looks like this:
SELECT D.DAY_FMT,SUM(F.MEASURE) from FACT F
INNER JOIN DATES D ON
to_number(to_char((F.DATESTIME - 0.3333333),'YYYYMMDD')) = D.DATEID
WHERE F.DATESTIME between to_timestamp ('05-Jan-16 08.00.00.000000000 AM')
and to_timestamp ('10-Jan-16 02.00.00.000000000 AM')
GROUP BY D.DAY_FMT
Note 1: If the From Time is 06:00 AM then we would be subtracting 0.25 (days) instead of 0.3333333 (days)
Note 2: The Fact table has billions of rows.
Is there any way to improve the performance of the above query?
In Oracle the date and the time are stored together. You don't need to join on equality, and you don't need to wrap the date within any functions. (And why timestamps?) Having all the computations (if any are even needed) on the "right hand side" of conditions means the computations are done just once, the same for every row, instead of separately for each row.
select f.day_fmt, sum(f.measure) as some_col_name
from fact f inner join dates d
on f.datestime >= to_date('05-Jan-16 08:00:00 AM', 'dd-Mon-yy hh:mi:ss AM')
and f.datestime < to_date('10-Jan-16 02:00:00 AM', 'dd-Mon-yy hh:mi:ss AM')
group by day_fmt;
Edit: Based on further clarification from OP - suppose the data is in table "fact" - with columns day_fmt, measure, and datestime. The assignment is to aggregate (sum) measure, grouped by day_fmt and also grouped by 24-hour intervals, starting from a date-time chosen by the user and ending with a date-time chosen by the user. Solution below.
with user_input (sd, ed) as (
select to_date('05-Jan-16 08:00:00 AM', 'dd-Mon-yy hh:mi:ss AM'),
to_date('10-Jan-16 02:00:00 AM', 'dd-Mon-yy hh:mi:ss AM') from dual
),
prep (dt) as (
select (select sd from user_input) + level - 1 from dual
connect by level < (select ed - sd from user_input) + 1
union
select ed from user_input
),
dates (from_date, to_date) as (
select dt, lead(dt) over (order by dt) from prep
)
select f.day_fmt, d.from_datetime, d.to_datetime, sum(f.measure) as some_column_name
from fact f inner join dates d
on f.datestime >= d.from_datetime and f.datestime < d.to_datetime
where to_datetime is not null
group by f.day_fmt, d.from_datetime, f.to_datetime
order by f.day_fmt, d.from_datetime;
By not using function calls wrapped around f.datestime, you can take advantage of an index defined on this column of the "fact" table (an index you already have or one you can create now, to help speed up your queries).

how to convert dates to week numbers

I need to do my reporting on week on week basis but my week number should start from 1st day of month
here is my sample data:
report_date Vol
01 nov 2014 23
03 nov 2014 34
16 nov 2014 56
30 nov 2014 44
Desired output
Week no Vol
1 57
2 56
3 0
4 44
hope its clear
Thanks
Since your desired output include "zero" rows as well, and assuming you'd like this report to work across multiple months as well:
WITH sample_data AS
(SELECT DATE '2014-11-01' AS report_date, 23 AS vol FROM DUAL
UNION ALL SELECT DATE '2014-11-03', 34 FROM DUAL
UNION ALL SELECT DATE '2014-11-16', 56 FROM DUAL
UNION ALL SELECT DATE '2014-11-30', 44 FROM DUAL)
,weeks AS
(SELECT report_month
,TO_CHAR(ROWNUM) AS week_no
FROM (SELECT DISTINCT
TRUNC(report_date,'MM') AS report_month
FROM sample_data)
CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(report_month),'W')))
SELECT TO_CHAR(weeks.report_month,'Month') AS "Month"
,weeks.week_no AS "Week no"
,NVL(sum(sample_data.vol),0) AS "Vol"
FROM weeks
LEFT JOIN sample_data
ON weeks.report_month = TRUNC(report_date,'MM')
AND weeks.week_no = to_char(report_date,'W')
GROUP BY weeks.report_month, weeks.week_no ORDER BY 1,2;
We determine the number of weeks in each month of the source data by using the LAST_DAY function, and we do a hierarchical query (CONNECT BY LEVEL <= n) to generate one row for each week in each month.
The expected output should be:
Month Week no Vol
======== ======= ===
November 1 57
November 2 0
November 3 56
November 4 0
November 5 44
select to_char(report_date, 'W'), sum(vol)
from your_table
group by to_char(report_date, 'W');
W Week of month (1-5) where week 1 starts on the first day of the
month and ends on the seventh.

Resources