Skip to content

Commit

Permalink
tests(e2e): add tests for hittability with overlay subview of UIWindow.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Dec 11, 2022
1 parent de16a38 commit 1dd95c3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
43 changes: 34 additions & 9 deletions detox/test/e2e/35.overlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const custom = require('./utils/custom-it');

describe(':ios: Overlay', () => {
let showAlertButton;
let showOverlayButton;
let showOverlayWindowButton;
let showOverlayViewButton;
let verticalScrollView;

beforeEach(async () => {
Expand All @@ -12,8 +13,11 @@ describe(':ios: Overlay', () => {

await element(by.text('Overlay')).tap();

showOverlayButton = await element(by.id('ShowOverlayButton'));
await expect(showOverlayButton).toBeVisible();
showOverlayWindowButton = await element(by.id('ShowOverlayWindowButton'));
await expect(showOverlayWindowButton).toBeVisible();

showOverlayViewButton = await element(by.id('ShowOverlayViewButton'));
await expect(showOverlayViewButton).toBeVisible();

showAlertButton = await element(by.id('ShowDismissibleAlertButton'));
await expect(showAlertButton).toBeVisible();
Expand All @@ -24,7 +28,7 @@ describe(':ios: Overlay', () => {
describe('default behaviour', () => {
it('should be able to scroll elements', async () => {
await verticalScrollView.scrollTo('bottom');
await expect(showOverlayButton).not.toBeVisible();
await expect(showOverlayWindowButton).not.toBeVisible();
});
});

Expand All @@ -38,7 +42,7 @@ describe(':ios: Overlay', () => {

describe('when shown', () => {
it('should not be able to tap on elements', async () => {
await expectToThrow(() => showOverlayButton.tap());
await expectToThrow(() => showOverlayWindowButton.tap());
});

it('should not be able to scroll elements', async () => {
Expand All @@ -52,29 +56,50 @@ describe(':ios: Overlay', () => {
});

custom.it.withFailureIf.iOSWithRNLessThan67('should be able to tap on elements', async () => {
await showOverlayButton.tap();
await showOverlayWindowButton.tap();
});

custom.it.withFailureIf.iOSWithRNLessThan67('should be able to scroll elements', async () => {
await verticalScrollView.scrollTo('bottom');
await expect(showOverlayButton).not.toBeVisible();
await expect(showOverlayWindowButton).not.toBeVisible();
});
});
});

describe('overlay window', () => {
describe('when shown', () => {
beforeEach(async () => {
await showOverlayButton.tap();
await showOverlayWindowButton.tap();
});

it('should not be able to tap on elements', async () => {
await expectToThrow(() => showOverlayButton.tap());
await expectToThrow(() => showOverlayWindowButton.tap());
});

it('should not be able to scroll elements', async () => {
await expectToThrow(() => verticalScrollView.scrollTo('bottom'));
});
});
});

describe('overlay view', () => {
describe('when shown', () => {
beforeEach(async () => {
await showOverlayViewButton.tap();
});

it('should be hittable', async () => {
const overlayView = await element(by.id('OverlayView'));
await overlayView.tap();
});

it('should not be able to tap on elements', async () => {
await expectToThrow(() => showOverlayViewButton.tap());
});

it('should not be able to scroll elements', async () => {
await expectToThrow(() => showOverlayViewButton.scrollTo('bottom'));
});
});
});
});
31 changes: 23 additions & 8 deletions detox/test/ios/example/NativeModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ @implementation NativeModule
[label sizeToFit];
[[newRoot view] addSubview:label];
label.center = newRoot.view.center;

id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
[[delegate window]setRootViewController:newRoot];
[[delegate window] makeKeyAndVisible];
Expand All @@ -54,27 +54,27 @@ @implementation NativeModule
dispatch_async(dispatch_get_main_queue(), ^{
id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
RCTBridge* bridge = ((RCTRootView*)delegate.window.rootViewController.view).bridge;

UIViewController* newRoot = [UIViewController new];
newRoot.view = [[RCTRootView alloc]initWithBridge:bridge moduleName:@"example" initialProperties:nil];
newRoot.tabBarItem.title = @"1";


UIViewController* newRoot2 = [UIViewController new];
newRoot2.view = [[RCTRootView alloc]initWithBridge:bridge moduleName:@"example" initialProperties:nil];
newRoot2.tabBarItem.title = @"2";

UIViewController* newRoot3 = [UIViewController new];
newRoot3.view = [[RCTRootView alloc]initWithBridge:bridge moduleName:@"example" initialProperties:nil];
newRoot3.tabBarItem.title = @"3";

UIViewController* newRoot4 = [UIViewController new];
newRoot4.view = [[RCTRootView alloc]initWithBridge:bridge moduleName:@"example" initialProperties:nil];
newRoot4.tabBarItem.title = @"4";

UITabBarController* tbc = [UITabBarController new];
tbc.viewControllers = @[newRoot, newRoot2, newRoot3, newRoot4];

[[delegate window]setRootViewController:tbc];
[[delegate window] makeKeyAndVisible];
});
Expand All @@ -93,6 +93,7 @@ @implementation NativeModule
dispatch_async(dispatch_get_main_queue(), ^{
CGRect screenBounds = UIScreen.mainScreen.bounds;
overlayWindow = [[UIWindow alloc] initWithFrame:screenBounds];
overlayWindow.accessibilityIdentifier = @"OverlayWindow";

[overlayWindow setWindowLevel:UIWindowLevelStatusBar];
[overlayWindow setHidden:NO];
Expand All @@ -101,4 +102,18 @@ @implementation NativeModule
});
}

RCT_EXPORT_METHOD(presentOverlayView) {
static UIView *overlayView;

dispatch_async(dispatch_get_main_queue(), ^{
CGRect screenBounds = UIScreen.mainScreen.bounds;
overlayView = [[UIView alloc] initWithFrame:screenBounds];
overlayView.userInteractionEnabled = YES;
overlayView.accessibilityIdentifier = @"OverlayView";

UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
[keyWindow addSubview:overlayView];
});
}

@end
8 changes: 6 additions & 2 deletions detox/test/src/Screens/OverlayScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ export default class OverlayScreen extends Component {
</Text>
</TouchableOpacity>

<TouchableOpacity onPress={() => NativeModule.presentOverlayWindow()} style={styles.button} testID='ShowOverlayButton'>
<Text style={styles.text}>Show Overlay</Text>
<TouchableOpacity onPress={() => NativeModule.presentOverlayWindow()} style={styles.button} testID='ShowOverlayWindowButton'>
<Text style={styles.text}>Show Overlay Window</Text>
</TouchableOpacity>

<TouchableOpacity onPress={() => NativeModule.presentOverlayView()} style={styles.button} testID='ShowOverlayViewButton'>
<Text style={styles.text}>Show Overlay View</Text>
</TouchableOpacity>

<View style={styles.item}><Text style={styles.itemText}>Text1</Text></View>
Expand Down

0 comments on commit 1dd95c3

Please sign in to comment.