kif-framework / KIF

Keep It Functional - An iOS Functional Testing Framework
Other
6.2k stars 912 forks source link

datePicker the year is not right #1145

Open PhoenixLeeSin opened 4 years ago

PhoenixLeeSin commented 4 years ago

the demo in KIF

- (void)testSelectingDateTime
{
    [[viewTester dateTimeSelector] tap];
    NSArray *dateTime = @[ @"Jun 17", @"6", @"43", @"AM" ];
    [viewTester selectDatePickerValue:dateTime];
    [[[viewTester dateTimeSelector] usingValue:@"Jun 17, 06:43 AM"] waitForView];
}

and code in viewcontroller

- (void)dateTimePickerChanged:(id)sender {
    NSDateFormatter  *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MMM d, hh:mm aa"];
    NSString *string = [NSString stringWithFormat:@"%@",
                        [dateFormatter stringFromDate:dateTimePicker.date]];
    self.dateTimeSelectionTextField.text = string;
}

the result shows ' 2007-Jun 17, 06:43 AM '

justinseanmartin commented 4 years ago

This is expected behavior:

image

If you manually launch the "Test Host" app and open the Picker page, you can scroll up in the "month & day" component of the Date/Time picker back to 2019, 2018, etc... The default for selectDatePickerValue: implies withSearchOrder:KIFPickerSearchForwardFromStart. This means that it will choose the first matching value that the DatePicker contains in its set of elements (were you to scroll back far enough). This is the reason that KIFPickerSearchForwardFromCurrentValue and KIFPickerSearchBackwardFromCurrentValue are useful, though require some knowledge of the state of the UI (which is definitely not ideal).

There isn't anything in the UI that distinguishes choosing "Jan 1" of 2020, 2019, or 2007. If the ViewController sets a dateTimePicker.minimumDate = [NSDate dateWithTimeIntervalSinceNow:0];. I believe this reproduces the error that you encountered in #1142.

There is probably some way to fix this such that it can ensure that the date component being selected is less than maximumDate and more than minimumDate. I don't have much time to dig into this issue, but it seems like you're on the right track here.

If you've got ideas of a way to fix this, I'm definitely open to suggestions.

PhoenixLeeSin commented 4 years ago

@justinseanmartin Thanks for your suggestions and replies, but the setup time does not meet our business needs, I am thinking of a solution

PhoenixLeeSin commented 4 years ago

@justinseanmartin i am not sure it is right or not ,i see u secletor about - (void)selectDatePickerValue:(NSArray *)datePickerColumnValues withSearchOrder:(KIFPickerSearchOrder)searchOrder; and in my code : let dateTime_1 = ["Jun 18","12","55","PM"] tester().selectDatePickerValue(dateTime_1) _ = tester().waitForView(withAccessibilityLabel: "XFPickerView.datePicker") as! UIDatePicker viewTester().selectDatePickerValue(dateTime_1, with: KIFPickerSearchOrder.forwardFromCurrentValue) and all goes well ....