Skip to content

Commit 80c8328

Browse files
committed
test(alert): cover shared preference ordering at contract boundary
1 parent 04c3ee8 commit 80c8328

6 files changed

Lines changed: 364 additions & 39 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAlertButtonChoice.swift‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ enum RunnerAlertButtonChoice {
3636
return action != "accept" && popupMarkerSurface ? labels.indices.last : nil
3737
}
3838

39-
static func isAcceptButton(_ label: String) -> Bool {
40-
acceptPreferences.contains { matches(label, pattern: $0) }
41-
}
42-
4339
private static func matches(_ label: String, pattern: String) -> Bool {
4440
label.trimmingCharacters(in: .whitespacesAndNewlines)
4541
.range(of: pattern, options: [.regularExpression, .caseInsensitive]) != nil

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+AlertButtonChoiceTests.swift‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ extension RunnerTests {
3838
}
3939
}
4040

41-
func testAlertAcceptTreatsOpenAsAffirmative() {
42-
XCTAssertTrue(RunnerAlertButtonChoice.isAcceptButton("Open"))
43-
}
44-
4541
func testAlertDismissPicksTheTrackingPromptDeclineLabel() {
4642
// The App Tracking Transparency prompt, as iOS words it in English (#3627).
4743
XCTAssertEqual(

‎contracts/fixtures/ios-alert-button-choice.json‎

Lines changed: 336 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,341 @@
388388
"labels": ["Cancel", "Done later"],
389389
"action": "accept",
390390
"expected": null
391+
},
392+
{
393+
"name": "accept-adjacent-rank-0",
394+
"labels": ["Allow While Using App", "While using the app"],
395+
"action": "accept",
396+
"expected": 0
397+
},
398+
{
399+
"name": "accept-adjacent-rank-0-reversed",
400+
"labels": ["While using the app", "Allow While Using App"],
401+
"action": "accept",
402+
"expected": 1
403+
},
404+
{
405+
"name": "accept-adjacent-rank-1",
406+
"labels": ["While using the app", "Allow all"],
407+
"action": "accept",
408+
"expected": 0
409+
},
410+
{
411+
"name": "accept-adjacent-rank-1-reversed",
412+
"labels": ["Allow all", "While using the app"],
413+
"action": "accept",
414+
"expected": 1
415+
},
416+
{
417+
"name": "accept-adjacent-rank-2",
418+
"labels": ["Allow all", "Always allow"],
419+
"action": "accept",
420+
"expected": 0
421+
},
422+
{
423+
"name": "accept-adjacent-rank-2-reversed",
424+
"labels": ["Always allow", "Allow all"],
425+
"action": "accept",
426+
"expected": 1
427+
},
428+
{
429+
"name": "accept-adjacent-rank-3",
430+
"labels": ["Always allow", "Allow all the time"],
431+
"action": "accept",
432+
"expected": 0
433+
},
434+
{
435+
"name": "accept-adjacent-rank-3-reversed",
436+
"labels": ["Allow all the time", "Always allow"],
437+
"action": "accept",
438+
"expected": 1
439+
},
440+
{
441+
"name": "accept-adjacent-rank-4",
442+
"labels": ["Allow all the time", "Allow notifications"],
443+
"action": "accept",
444+
"expected": 0
445+
},
446+
{
447+
"name": "accept-adjacent-rank-4-reversed",
448+
"labels": ["Allow notifications", "Allow all the time"],
449+
"action": "accept",
450+
"expected": 1
451+
},
452+
{
453+
"name": "accept-adjacent-rank-5",
454+
"labels": ["Allow notifications", "Allow"],
455+
"action": "accept",
456+
"expected": 0
457+
},
458+
{
459+
"name": "accept-adjacent-rank-5-reversed",
460+
"labels": ["Allow", "Allow notifications"],
461+
"action": "accept",
462+
"expected": 1
463+
},
464+
{
465+
"name": "accept-adjacent-rank-6",
466+
"labels": ["Allow", "OK"],
467+
"action": "accept",
468+
"expected": 0
469+
},
470+
{
471+
"name": "accept-adjacent-rank-6-reversed",
472+
"labels": ["OK", "Allow"],
473+
"action": "accept",
474+
"expected": 1
475+
},
476+
{
477+
"name": "accept-adjacent-rank-7",
478+
"labels": ["OK", "Yes"],
479+
"action": "accept",
480+
"expected": 0
481+
},
482+
{
483+
"name": "accept-adjacent-rank-7-reversed",
484+
"labels": ["Yes", "OK"],
485+
"action": "accept",
486+
"expected": 1
487+
},
488+
{
489+
"name": "accept-adjacent-rank-8",
490+
"labels": ["Yes", "Continue"],
491+
"action": "accept",
492+
"expected": 0
493+
},
494+
{
495+
"name": "accept-adjacent-rank-8-reversed",
496+
"labels": ["Continue", "Yes"],
497+
"action": "accept",
498+
"expected": 1
499+
},
500+
{
501+
"name": "accept-adjacent-rank-9",
502+
"labels": ["Continue", "Save"],
503+
"action": "accept",
504+
"expected": 0
505+
},
506+
{
507+
"name": "accept-adjacent-rank-9-reversed",
508+
"labels": ["Save", "Continue"],
509+
"action": "accept",
510+
"expected": 1
511+
},
512+
{
513+
"name": "accept-adjacent-rank-10",
514+
"labels": ["Save", "Confirm"],
515+
"action": "accept",
516+
"expected": 0
517+
},
518+
{
519+
"name": "accept-adjacent-rank-10-reversed",
520+
"labels": ["Confirm", "Save"],
521+
"action": "accept",
522+
"expected": 1
523+
},
524+
{
525+
"name": "accept-adjacent-rank-11",
526+
"labels": ["Confirm", "Turn on"],
527+
"action": "accept",
528+
"expected": 0
529+
},
530+
{
531+
"name": "accept-adjacent-rank-11-reversed",
532+
"labels": ["Turn on", "Confirm"],
533+
"action": "accept",
534+
"expected": 1
535+
},
536+
{
537+
"name": "accept-adjacent-rank-12",
538+
"labels": ["Turn on", "Open Settings"],
539+
"action": "accept",
540+
"expected": 0
541+
},
542+
{
543+
"name": "accept-adjacent-rank-12-reversed",
544+
"labels": ["Open Settings", "Turn on"],
545+
"action": "accept",
546+
"expected": 1
547+
},
548+
{
549+
"name": "accept-adjacent-rank-13",
550+
"labels": ["Open Settings", "Done"],
551+
"action": "accept",
552+
"expected": 0
553+
},
554+
{
555+
"name": "accept-adjacent-rank-13-reversed",
556+
"labels": ["Done", "Open Settings"],
557+
"action": "accept",
558+
"expected": 1
559+
},
560+
{
561+
"name": "accept-adjacent-rank-14",
562+
"labels": ["Done", "Open"],
563+
"action": "accept",
564+
"expected": 0
565+
},
566+
{
567+
"name": "accept-adjacent-rank-14-reversed",
568+
"labels": ["Open", "Done"],
569+
"action": "accept",
570+
"expected": 1
571+
},
572+
{
573+
"name": "accept-adjacent-rank-15",
574+
"labels": ["Open", "Allow once"],
575+
"action": "accept",
576+
"expected": 0
577+
},
578+
{
579+
"name": "accept-adjacent-rank-15-reversed",
580+
"labels": ["Allow once", "Open"],
581+
"action": "accept",
582+
"expected": 1
583+
},
584+
{
585+
"name": "accept-adjacent-rank-16",
586+
"labels": ["Allow once", "Only this time"],
587+
"action": "accept",
588+
"expected": 0
589+
},
590+
{
591+
"name": "accept-adjacent-rank-16-reversed",
592+
"labels": ["Only this time", "Allow once"],
593+
"action": "accept",
594+
"expected": 1
595+
},
596+
{
597+
"name": "dismiss-adjacent-rank-0",
598+
"labels": ["Cancel", "Deny"],
599+
"action": "dismiss",
600+
"expected": 0
601+
},
602+
{
603+
"name": "dismiss-adjacent-rank-0-reversed",
604+
"labels": ["Deny", "Cancel"],
605+
"action": "dismiss",
606+
"expected": 1
607+
},
608+
{
609+
"name": "dismiss-adjacent-rank-1",
610+
"labels": ["Deny", "Don't Allow"],
611+
"action": "dismiss",
612+
"expected": 0
613+
},
614+
{
615+
"name": "dismiss-adjacent-rank-1-reversed",
616+
"labels": ["Don't Allow", "Deny"],
617+
"action": "dismiss",
618+
"expected": 1
619+
},
620+
{
621+
"name": "dismiss-adjacent-rank-2",
622+
"labels": ["Don't Allow", "Not now"],
623+
"action": "dismiss",
624+
"expected": 0
625+
},
626+
{
627+
"name": "dismiss-adjacent-rank-2-reversed",
628+
"labels": ["Not now", "Don't Allow"],
629+
"action": "dismiss",
630+
"expected": 1
631+
},
632+
{
633+
"name": "dismiss-adjacent-rank-3",
634+
"labels": ["Not now", "No"],
635+
"action": "dismiss",
636+
"expected": 0
637+
},
638+
{
639+
"name": "dismiss-adjacent-rank-3-reversed",
640+
"labels": ["No", "Not now"],
641+
"action": "dismiss",
642+
"expected": 1
643+
},
644+
{
645+
"name": "dismiss-adjacent-rank-4",
646+
"labels": ["No", "Dismiss"],
647+
"action": "dismiss",
648+
"expected": 0
649+
},
650+
{
651+
"name": "dismiss-adjacent-rank-4-reversed",
652+
"labels": ["Dismiss", "No"],
653+
"action": "dismiss",
654+
"expected": 1
655+
},
656+
{
657+
"name": "dismiss-adjacent-rank-5",
658+
"labels": ["Dismiss", "Close"],
659+
"action": "dismiss",
660+
"expected": 0
661+
},
662+
{
663+
"name": "dismiss-adjacent-rank-5-reversed",
664+
"labels": ["Close", "Dismiss"],
665+
"action": "dismiss",
666+
"expected": 1
667+
},
668+
{
669+
"name": "dismiss-adjacent-rank-6",
670+
"labels": ["Close", "Close app"],
671+
"action": "dismiss",
672+
"expected": 0
673+
},
674+
{
675+
"name": "dismiss-adjacent-rank-6-reversed",
676+
"labels": ["Close app", "Close"],
677+
"action": "dismiss",
678+
"expected": 1
679+
},
680+
{
681+
"name": "dismiss-adjacent-rank-7",
682+
"labels": ["Close app", "Later"],
683+
"action": "dismiss",
684+
"expected": 0
685+
},
686+
{
687+
"name": "dismiss-adjacent-rank-7-reversed",
688+
"labels": ["Later", "Close app"],
689+
"action": "dismiss",
690+
"expected": 1
691+
},
692+
{
693+
"name": "dismiss-adjacent-rank-8",
694+
"labels": ["Later", "Skip"],
695+
"action": "dismiss",
696+
"expected": 0
697+
},
698+
{
699+
"name": "dismiss-adjacent-rank-8-reversed",
700+
"labels": ["Skip", "Later"],
701+
"action": "dismiss",
702+
"expected": 1
703+
},
704+
{
705+
"name": "dismiss-adjacent-rank-9",
706+
"labels": ["Skip", "Ask App Not to Track"],
707+
"action": "dismiss",
708+
"expected": 0
709+
},
710+
{
711+
"name": "dismiss-adjacent-rank-9-reversed",
712+
"labels": ["Ask App Not to Track", "Skip"],
713+
"action": "dismiss",
714+
"expected": 1
715+
},
716+
{
717+
"name": "dismiss-adjacent-rank-10",
718+
"labels": ["Ask App Not to Track", "Keep Browsing"],
719+
"action": "dismiss",
720+
"expected": 0
721+
},
722+
{
723+
"name": "dismiss-adjacent-rank-10-reversed",
724+
"labels": ["Keep Browsing", "Ask App Not to Track"],
725+
"action": "dismiss",
726+
"expected": 1
391727
}
392728
]

‎packages/contracts/src/alert-contract.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2+
import fs from 'node:fs';
23
import { classifyAlertButtonRole, selectRankedAlertButtonByRole } from './alert-contract.ts';
34

45
type Button = { label: string; role: ReturnType<typeof classifyAlertButtonRole> };
@@ -105,3 +106,29 @@ describe('selectRankedAlertButtonByRole', () => {
105106
expect(selectRankedAlertButtonByRole(buttons, 'accept', rankById)).toBeNull();
106107
});
107108
});
109+
110+
// Selection over admitted buttons only: capture's two-button minimum is outside this table.
111+
type AlertChoiceCase = {
112+
name: string;
113+
labels: string[];
114+
action: 'accept' | 'dismiss';
115+
expected: number | null;
116+
xctestPopupMarkerExpected?: number | null;
117+
};
118+
const alertChoiceCases = JSON.parse(
119+
fs.readFileSync(
120+
new URL('../../../contracts/fixtures/ios-alert-button-choice.json', import.meta.url),
121+
'utf8',
122+
),
123+
) as AlertChoiceCase[];
124+
125+
describe('selectRankedAlertButtonByRole shared Apple label choices', () => {
126+
it.each(alertChoiceCases)('$name', ({ labels, action, expected }) => {
127+
const buttons = labels.map((label) => ({
128+
label,
129+
role: classifyAlertButtonRole(label),
130+
}));
131+
const chosen = selectRankedAlertButtonByRole(buttons, action);
132+
expect(chosen === null ? null : buttons.indexOf(chosen)).toBe(expected);
133+
});
134+
});

0 commit comments

Comments
 (0)