Skip to content

Commit

Permalink
Implement on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
d4vidi committed May 20, 2024
1 parent e1f9fa2 commit c03cc32
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
36 changes: 31 additions & 5 deletions e2e/Stack.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import jestExpect from 'expect';
import Utils from './Utils';
import TestIDs from '../playground/src/testIDs';
import Android from './AndroidUtils';

const { elementByLabel, elementById, sleep } = Utils;

const driver = {
root: {
navToTitleAndSubtitle: async () => {
await elementById(TestIDs.PUSH_TITLE_WITH_SUBTITLE).tap();
return driver.titleWithSubtitle;
},
},

titleWithSubtitle: {
title: () => elementByLabel('Title'),
subtitle: () => elementByLabel('Subtitle'),
},
};

describe('Stack', () => {
beforeEach(async () => {
await device.launchApp({ newInstance: true });
Expand Down Expand Up @@ -78,11 +93,22 @@ describe('Stack', () => {
});

it('push title with subtitle', async () => {
await elementById(TestIDs.PUSH_TITLE_WITH_SUBTITLE).tap();
await expect(elementByLabel('Title')).toBeVisible();
await expect(elementByLabel('Subtitle')).toBeVisible();
await expect(elementById(`${TestIDs.TOPBAR_ID}.title`)).toBeVisible();
await expect(elementById(`${TestIDs.TOPBAR_ID}.subtitle`)).toBeVisible();
const innerDriver = await driver.root.navToTitleAndSubtitle();
await expect(innerDriver.title()).toBeVisible();
await expect(innerDriver.subtitle()).toBeVisible();
});

it('push title & subtitle with derived test IDs', async () => {
const expectedTitleId = `${TestIDs.TOPBAR_ID}.title`;
const expectedSubtitleId = `${TestIDs.TOPBAR_ID}.subtitle`;

const innerDriver = await driver.root.navToTitleAndSubtitle();

const titleAttr = await innerDriver.title().getAttributes();
jestExpect(titleAttr.identifier).toEqual(expectedTitleId);

const subtitleAttr = await innerDriver.subtitle().getAttributes();
jestExpect(subtitleAttr.identifier).toEqual(expectedSubtitleId);
});

it.e2e('screen lifecycle', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public void setSubtitleAlignment(Alignment alignment) {

public void setTestId(String testId) {
setTag(testId);
titleAndButtonsContainer.setTestId(testId);
}

public void setTitleTextColor(@ColorInt int color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class TitleAndButtonsContainer(context: Context) : ViewGroup(context) {
clearComponent()
}

fun setTestId(testId: String) {
titleSubTitleBar.setTestId(testId)
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
val titleComponent = getTitleComponent()
val isCenter = titleComponentAlignment == Alignment.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class TitleSubTitleLayout(context: Context) : LinearLayout(context) {
}
}

fun setTestId(testId: String) {
if (testId.isNotEmpty()) {
this.titleTextView.tag = "$testId.title"
this.subTitleTextView.tag = "$testId.subtitle"
}
}

fun getTitle() = (this.titleTextView.text ?: "").toString()

fun clear() {
Expand Down

0 comments on commit c03cc32

Please sign in to comment.