Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 88 additions & 72 deletions e2e/SideMenu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,105 @@ import TestIDs from '../playground/src/testIDs';

const {elementByLabel, elementById, expectImagesToBeEqual} = Utils;

describe.each(['aboveContent', 'pushContent'])('SideMenu', (openMode) => {
beforeEach(async () => {
await device.launchApp({newInstance: true});
await elementById(TestIDs.SIDE_MENU_BTN).tap();

if (openMode === 'aboveContent') {
await elementById(TestIDs.TOGGLE_SIDE_MENU_OPEN_MODE_BTN).tap();
}
});

describe(`Open mode '${openMode}'`, () => {
it('close SideMenu and push to stack with static id', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.LEFT_SIDE_MENU_PUSH_BTN).tap();
await elementById(TestIDs.CLOSE_LEFT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.CENTER_SCREEN_HEADER)).toBeVisible();
describe('SideMenu', () => {
beforeEach(async () => {
await device.launchApp({newInstance : true});
await elementById(TestIDs.SIDE_MENU_BTN).tap();
});

it('Push to stack with static id and close SideMenu with screen options', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.LEFT_SIDE_MENU_PUSH_AND_CLOSE_BTN).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.CENTER_SCREEN_HEADER)).toBeVisible();
});
describe.each(['aboveContent', 'pushContent'])('Open mode %s', (openMode) => {
beforeEach(async () => {
if (openMode === 'pushContent') {
await elementById(TestIDs.TOGGLE_SIDE_MENU_OPEN_MODE_BTN).tap();
}
});

it('side menu visibility - left', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.CLOSE_LEFT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.CLOSE_LEFT_SIDE_MENU_BTN)).toBeNotVisible();
});
it('close SideMenu and push to stack with static id', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.LEFT_SIDE_MENU_PUSH_BTN).tap();
await elementById(TestIDs.CLOSE_LEFT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.CENTER_SCREEN_HEADER)).toBeVisible();
});

it('side menu visibility - right', async () => {
await elementById(TestIDs.OPEN_RIGHT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.CLOSE_RIGHT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.CLOSE_RIGHT_SIDE_MENU_BTN)).toBeNotVisible();
});
it('Push to stack with static id and close SideMenu with screen options', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.LEFT_SIDE_MENU_PUSH_AND_CLOSE_BTN).tap();
await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.CENTER_SCREEN_HEADER)).toBeVisible();
});

it.e2e('should rotate', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await device.setOrientation('landscape');
await expect(elementById(TestIDs.LEFT_SIDE_MENU_PUSH_BTN)).toBeVisible();
});
it('side menu visibility - left', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.CLOSE_LEFT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.CLOSE_LEFT_SIDE_MENU_BTN)).toBeNotVisible();
});

it.e2e(':ios: rotation should update drawer height', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('left drawer height: 869')).toBeVisible();
await device.setOrientation('landscape');
await expect(elementByLabel('left drawer height: 428')).toBeVisible();
await device.setOrientation('portrait');
await expect(elementByLabel('left drawer height: 869')).toBeVisible();
});
it('side menu visibility - right', async () => {
await elementById(TestIDs.OPEN_RIGHT_SIDE_MENU_BTN).tap();
await elementById(TestIDs.CLOSE_RIGHT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.CLOSE_RIGHT_SIDE_MENU_BTN)).toBeNotVisible();
});

it.e2e('should set left drawer width', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.SIDE_MENU_LEFT_DRAWER_HEIGHT_TEXT)).toBeVisible();
await expect(elementByLabel('left drawer width: 250')).toBeVisible();
});
it.e2e('should rotate', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await device.setOrientation('landscape');
await expect(elementById(TestIDs.LEFT_SIDE_MENU_PUSH_BTN)).toBeVisible();
});

it.e2e('should change left drawer width', async () => {
await elementById(TestIDs.CHANGE_LEFT_SIDE_MENU_WIDTH_BTN).tap();
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('left drawer width: 50')).toBeVisible();
});
it.e2e(':ios: rotation should update drawer height', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('left drawer height: 869')).toBeVisible();
await device.setOrientation('landscape');
await expect(elementByLabel('left drawer height: 428')).toBeVisible();
await device.setOrientation('portrait');
await expect(elementByLabel('left drawer height: 869')).toBeVisible();
});

it.e2e('should set right drawer width', async () => {
await elementById(TestIDs.OPEN_RIGHT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('right drawer width: 250')).toBeVisible();
});
it.e2e('should set left drawer width', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await expect(elementById(TestIDs.SIDE_MENU_LEFT_DRAWER_HEIGHT_TEXT)).toBeVisible();
await expect(elementByLabel('left drawer width: 250')).toBeVisible();
});

it.e2e('should change left drawer width', async () => {
await elementById(TestIDs.CHANGE_LEFT_SIDE_MENU_WIDTH_BTN).tap();
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('left drawer width: 50')).toBeVisible();
});

it.e2e('should set right drawer width', async () => {
await elementById(TestIDs.OPEN_RIGHT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('right drawer width: 250')).toBeVisible();
});

it.e2e('should change right drawer width', async () => {
await elementById(TestIDs.CHANGE_RIGHT_SIDE_MENU_WIDTH_BTN).tap();
await elementById(TestIDs.OPEN_RIGHT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('right drawer width: 50')).toBeVisible();
it.e2e('should change right drawer width', async () => {
await elementById(TestIDs.CHANGE_RIGHT_SIDE_MENU_WIDTH_BTN).tap();
await elementById(TestIDs.OPEN_RIGHT_SIDE_MENU_BTN).tap();
await expect(elementByLabel('right drawer width: 50')).toBeVisible();
});

it.e2e(':ios: should render side menu correctly', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
const snapshottedImagePath = `./e2e/assets/side_menu.${openMode}.png`;
const actual =
await elementById('SideMenuContainer').takeScreenshot(`side_menu_${openMode}`);
expectImagesToBeEqual(actual, snapshottedImagePath);
});
});

it.e2e(':ios: should render side menu correctly', async () => {
await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();
const snapshottedImagePath = `./e2e/assets/side_menu.${openMode}.png`;
const actual = await elementById('SideMenuContainer').takeScreenshot(`side_menu_${openMode}`);
expectImagesToBeEqual(actual, snapshottedImagePath);
it.e2e(':ios: should open as push-content by default', async () => {
await elementById(TestIDs.TOGGLE_SIDE_MENU_OPEN_MODE_BTN).tap(); // aboveContent --> pushContent
await elementById(TestIDs.TOGGLE_SIDE_MENU_OPEN_MODE_BTN).tap(); // pushContent --> undefined
await expect(elementByLabel('Open mode: undefined')).toBeVisible();

await elementById(TestIDs.OPEN_LEFT_SIDE_MENU_BTN).tap();

const snapshottedImagePath = `./e2e/assets/side_menu.undefined.png`;
const actual =
await elementById('SideMenuContainer').takeScreenshot(`side_menu_undefined`);
expectImagesToBeEqual(actual, snapshottedImagePath);
});
});
});
Binary file added e2e/assets/side_menu.undefined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 17 additions & 12 deletions playground/src/screens/SideMenuCenterScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const {
CHANGE_RIGHT_SIDE_MENU_WIDTH_BTN,
DISABLE_DRAWERS,
ENABLE_DRAWERS,
CENTER_SCREEN_CONTAINER
SIDE_MENU_CENTER_SCREEN_CONTAINER,
} = testIDs;

interface ScreenState {
openMode: 'aboveContent' | 'pushContent';
openMode: 'aboveContent' | 'pushContent' | undefined;
}

export default class SideMenuCenterScreen extends NavigationComponent {
Expand Down Expand Up @@ -58,7 +58,7 @@ export default class SideMenuCenterScreen extends NavigationComponent {
constructor(props: NavigationProps) {
super(props);
this.state = {
openMode: 'pushContent',
openMode: 'aboveContent',
};
Navigation.events().bindComponent(this);
}
Expand All @@ -69,17 +69,11 @@ export default class SideMenuCenterScreen extends NavigationComponent {
}
}

toggleAboveContent = () => {
this.setState((state: ScreenState) => ({
openMode: state.openMode === 'pushContent' ? 'aboveContent' : 'pushContent',
}));
};

render() {
const { openMode } = this.state;

return (
<Root componentId={this.props.componentId} testID={CENTER_SCREEN_CONTAINER}>
<Root componentId={this.props.componentId} testID={SIDE_MENU_CENTER_SCREEN_CONTAINER}>
<Button
label="Open Left"
testID={OPEN_LEFT_SIDE_MENU_BTN}
Expand Down Expand Up @@ -112,11 +106,11 @@ export default class SideMenuCenterScreen extends NavigationComponent {
/>

<TouchableOpacity
onPress={this.toggleAboveContent}
onPress={this.toggleOpenMode}
testID={TOGGLE_SIDE_MENU_OPEN_MODE_BTN}
style={{ margin: 10, padding: 10, backgroundColor: '#ddd', borderRadius: 5 }}
>
<Text>Open mode: {openMode}</Text>
<Text>Open mode: {openMode || 'undefined'}</Text>
</TouchableOpacity>
</Root>
);
Expand All @@ -135,6 +129,17 @@ export default class SideMenuCenterScreen extends NavigationComponent {
});
};

toggleOpenMode = () => {
this.setState((state: ScreenState) => ({
openMode:
state.openMode === 'aboveContent'
? 'pushContent'
: state.openMode === 'pushContent'
? undefined
: 'aboveContent',
}));
};

open = (side: 'left' | 'right') =>
Navigation.mergeOptions(this, {
sideMenu: {
Expand Down
4 changes: 2 additions & 2 deletions playground/src/testIDs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ const testIDs = {
SIDE_MENU_LEFT_DRAWER_HEIGHT_TEXT: 'SIDE_MENU_LEFT_DRAWER_HEIGHT_TEXT',
SIDE_MENU_LEFT_DRAWER_WIDTH_TEXT: 'SIDE_MENU_LEFT_DRAWER_WIDTH_TEXT',
SIDE_MENU_LEFT_DRAWER_CONTAINER: 'SIDE_MENU_LEFT_DRAWER_CONTAINER',
CENTER_SCREEN_CONTAINER: 'CENTER_SCREEN_CONTAINER',
SIDE_MENU_CENTER_SCREEN_CONTAINER: 'SIDE_MENU_CENTER_SCREEN_CONTAINER',
SIDE_MENU_RIGHT_DRAWER_WIDTH_TEXT: 'SIDE_MENU_RIGHT_DRAWER_WIDTH_TEXT',
TOGGLE_REACT_DECLARED_MODAL: 'TOGGLE_REACT_DECLARED_MODAL',
REPLACE_TAB_TEST_ID: 'REPLACE_TAB_TEST_ID',
REPLACED_TAB: 'REPLACED_TAB',
MOUNTED_SCREENS_TEXT: 'MOUNTED_SCREENS_TEXT',

//External Component Buttons
// External Component Buttons
EXTERNAL_DISMISS_MODAL_BTN: 'EXTERNAL_DISMISS_MODAL_BTN',
EXTERNAL_TOP_BAR_RIGHT_BTN: 'EXTERNAL_TOP_BAR_RIGHT_BTN',
GOTO_SHARED_ELEMENT_SCREEN: 'GOTO_SHARED_ELEMENT_SCREEN',
Expand Down