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
2 changes: 1 addition & 1 deletion lib/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ dependencies {
if ("Playground".toLowerCase() == rootProject.name.toLowerCase()) {
// tests only for our playground
testImplementation 'junit:junit:4.13.2'
testImplementation "org.robolectric:robolectric:4.7.2"
testImplementation "org.robolectric:robolectric:4.14.1"
testImplementation 'org.assertj:assertj-core:3.11.1'
testImplementation 'org.mockito:mockito-core:4.0.0'
testImplementation 'com.squareup.assertj:assertj-android:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.reactnativenavigation.react;

import android.app.Activity;
import android.content.Context;

import com.facebook.react.ReactInstanceManager;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ReactViewCreator;

public class ReactComponentViewCreator implements ReactViewCreator {
@Override
public ReactView create(final Activity activity, final String componentId, final String componentName) {
return new ReactView(activity, componentId, componentName);
public ReactView create(final Context context, final String componentId, final String componentName) {
return new ReactView(context, componentId, componentName);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.reactnativenavigation.viewcontrollers.viewcontroller;

import android.app.Activity;
import android.content.Context;

public interface ReactViewCreator {

IReactView create(Activity activity, String componentId, String componentName);
IReactView create(Context context, String componentId, String componentName);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.reactnativenavigation.views.component;

import android.app.Activity;
import android.content.Context;

import com.facebook.react.ReactInstanceManager;
import com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ReactViewCreator;
import com.reactnativenavigation.react.ReactComponentViewCreator;
import com.reactnativenavigation.react.ReactView;
import com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ReactViewCreator;

public class ComponentViewCreator implements ReactViewCreator {
@Override
public IReactView create(Activity activity, String componentId, String componentName) {
ReactView reactView = new ReactComponentViewCreator().create(activity, componentId, componentName);
return new ComponentLayout(activity, reactView);
public IReactView create(Context context, String componentId, String componentName) {
ReactView reactView = new ReactComponentViewCreator().create(context, componentId, componentName);
return new ComponentLayout(context, reactView);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.reactnativenavigation.views.stack.topbar;

import android.app.Activity;
import android.content.Context;

import com.facebook.react.ReactInstanceManager;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ReactViewCreator;

public class TopBarBackgroundViewCreator implements ReactViewCreator {

@Override
public TopBarBackgroundView create(Activity activity, String componentId, String componentName) {
return new TopBarBackgroundView(activity, componentId, componentName);
public TopBarBackgroundView create(Context context, String componentId, String componentName) {
return new TopBarBackgroundView(context, componentId, componentName);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.reactnativenavigation.views.stack.topbar.titlebar;

import android.app.Activity;
import android.content.Context;

import com.facebook.react.ReactInstanceManager;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ReactViewCreator;

public class TitleBarReactViewCreator implements ReactViewCreator {

@Override
public TitleBarReactView create(Activity activity, String componentId, String componentName) {
return new TitleBarReactView(activity, componentId, componentName);
public TitleBarReactView create(Context context, String componentId, String componentName) {
return new TitleBarReactView(context, componentId, componentName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.reactnativenavigation

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.mock
import org.mockito.kotlin.any
import org.mockito.kotlin.whenever
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config


@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
abstract class BaseRobolectricTest {

val context: Context = RuntimeEnvironment.getApplication()
lateinit var mockConfiguration: Configuration


@Before
open fun beforeEach() {
NavigationApplication.instance = mock(NavigationApplication::class.java)
mockConfiguration = mock(Configuration::class.java)
val res: Resources = mock(Resources::class.java)
mockConfiguration.uiMode = Configuration.UI_MODE_NIGHT_NO
whenever(res.getConfiguration()).thenReturn(mockConfiguration)
whenever(NavigationApplication.instance.resources).thenReturn(res)
whenever(res.getColor(ArgumentMatchers.anyInt())).thenReturn(0x00000)
whenever(res.getColor(ArgumentMatchers.anyInt(), any())).thenReturn(0x00000)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

import static org.assertj.core.api.Java6Assertions.*;

import com.reactnativenavigation.R;

@Ignore("New architecture - WIP")
public class EnvironmentTest extends BaseTest {
public class EnvironmentTest extends BaseRobolectricTest {
@Test
public void assertJ() {
assertThat(1 + 2).isEqualTo(3).isGreaterThan(2).isLessThan(4).isNotNegative().isPositive().isNotZero();
Expand Down Expand Up @@ -41,6 +38,6 @@ public void androidR() {

@Test
public void ableToLoadApplication() throws Exception {
assertThat(RuntimeEnvironment.application).isNotNull();
assertThat(getContext()).isNotNull();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.reactnativenavigation.mocks;

import android.app.Activity;
import static org.mockito.Mockito.spy;

import android.content.Context;

import com.reactnativenavigation.react.ReactView;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ReactViewCreator;
import com.reactnativenavigation.views.component.ComponentLayout;
import com.reactnativenavigation.views.component.ReactComponent;

import static org.mockito.Mockito.spy;

public class TestComponentViewCreator implements ReactViewCreator {
@Override
public ReactComponent create(final Activity activity, final String componentId, final String componentName) {
ReactView reactView = spy(new TestReactView(activity));
return new ComponentLayout(activity, reactView);
public ReactComponent create(final Context context, final String componentId, final String componentName) {
ReactView reactView = spy(new TestReactView(context));
return new ComponentLayout(context, reactView);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import static org.assertj.core.api.Java6Assertions.*;

@Ignore("New architecture - WIP")
public class LayoutNodeParserTest extends BaseTest {
public class LayoutNodeParserTest extends BaseRobolectricTest {
@Test
public void dto() throws Exception {
LayoutNode node = new LayoutNode("the id", LayoutNode.Type.Component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.reactnativenavigation.options;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;

import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.BaseRobolectricTest;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.options.params.Colour;
import com.reactnativenavigation.options.params.NullText;
Expand All @@ -15,7 +14,6 @@

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
Expand All @@ -25,8 +23,7 @@
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.when;

@Ignore("New architecture - WIP")
public class OptionsTest extends BaseTest {
public class OptionsTest extends BaseRobolectricTest {

private static final String TITLE = "the title";
private static final Number TITLE_HEIGHT = new Number(100);
Expand Down Expand Up @@ -59,12 +56,10 @@ public class OptionsTest extends BaseTest {
private static final String BOTTOM_TABS_CURRENT_TAB_ID = "ComponentId";
private static final Number BOTTOM_TABS_CURRENT_TAB_INDEX = new Number(1);
private TypefaceLoader mockLoader;
private Activity activity;

@Override
public void beforeEach() {
super.beforeEach();
activity = newActivity();
mockLoader = Mockito.mock(TypefaceLoader.class);
when(mockLoader.getTypeFace("HelveticaNeue-Condensed", null, null, null)).then((Answer<Typeface>) invocation -> SUBTITLE_TYPEFACE);
when(mockLoader.getTypeFace("HelveticaNeue-CondensedBold", null, null, null)).then((Answer<Typeface>) invocation -> TOP_BAR_TYPEFACE);
Expand All @@ -86,7 +81,7 @@ public void parsesJson() throws Exception {
.put("fab", createFab())
.put("bottomTabs", createBottomTabs())
.put("layout", layout);
Options result = Options.parse(activity, mockLoader, json);
Options result = Options.parse(getContext(), mockLoader, json);
assertResult(result);
}

Expand Down Expand Up @@ -220,12 +215,12 @@ private JSONObject createOtherBottomTabs() throws JSONException {
public void mergeDoesNotMutate() throws Exception {
JSONObject json1 = new JSONObject();
json1.put("topBar", createTopBar(true));
Options options1 = Options.parse(activity, mockLoader, json1);
Options options1 = Options.parse(getContext(), mockLoader, json1);
options1.topBar.title.text = new Text("some title");

JSONObject json2 = new JSONObject();
json2.put("topBar", createTopBar(false));
Options options2 = Options.parse(activity, mockLoader, json2);
Options options2 = Options.parse(getContext(), mockLoader, json2);
options2.topBar.title.text = new NullText();

Options merged = options1.mergeWith(options2);
Expand All @@ -243,7 +238,7 @@ public void mergeDefaultOptions() throws Exception {
.put("fab", createFab())
.put("bottomTabs", createBottomTabs())
.put("layout", layout);
Options defaultOptions = Options.parse(activity, mockLoader, json);
Options defaultOptions = Options.parse(getContext(), mockLoader, json);
Options options = new Options();

assertResult(options.mergeWith(defaultOptions));
Expand All @@ -258,12 +253,12 @@ public void mergedDefaultOptionsDontOverrideGivenOptions() throws Exception {
.put("fab", createOtherFab())
.put("bottomTabs", createOtherBottomTabs())
.put("layout", layout);
Options defaultOptions = Options.parse(activity, mockLoader, defaultJson);
Options defaultOptions = Options.parse(getContext(), mockLoader, defaultJson);

JSONObject json = new JSONObject()
.put("topBar", createTopBar(TOP_BAR_VISIBLE.get()))
.put("bottomTabs", createBottomTabs());
Options options = Options.parse(activity, mockLoader, json);
Options options = Options.parse(getContext(), mockLoader, json);
options.withDefaultOptions(defaultOptions);
assertResult(options);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.reactnativenavigation.options
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import com.reactnativenavigation.BaseTest
import com.reactnativenavigation.BaseRobolectricTest
import org.assertj.core.api.Assertions.assertThat
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Ignore
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

@Ignore("New architecture - WIP")
class TransitionAnimationOptionsTest : BaseTest() {
class TransitionAnimationOptionsTest : BaseRobolectricTest() {
lateinit var uut: TransitionAnimationOptions

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.reactnativenavigation.options.parsers;

import com.reactnativenavigation.BaseTest;
import static org.assertj.core.api.Java6Assertions.assertThat;

import com.reactnativenavigation.BaseRobolectricTest;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;

import static org.assertj.core.api.Java6Assertions.assertThat;

@Ignore("New architecture - WIP")
public class BoolParserTest extends BaseTest {
public class BoolParserTest extends BaseRobolectricTest {

@Test
public void parse() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
package com.reactnativenavigation.options.parsers;

import static org.assertj.core.api.Java6Assertions.assertThat;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.BaseRobolectricTest;
import com.reactnativenavigation.options.params.DontApplyColour;
import com.reactnativenavigation.options.params.ReactPlatformColor;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import static org.assertj.core.api.Java6Assertions.assertThat;

import android.app.Activity;

@Ignore("New architecture - WIP")
public class ColorParseTest extends BaseTest {

Activity activity;
@Override
public void beforeEach() {
super.beforeEach();
activity = newActivity();
}
public class ColorParseTest extends BaseRobolectricTest {

@Test
public void nullIsParsedAsNoColor() throws JSONException {
Expand All @@ -46,7 +36,7 @@ public void shouldParsePlatformColors() throws JSONException {
try (MockedStatic<Arguments> theMock = Mockito.mockStatic(Arguments.class)) {
theMock.when(Arguments::createMap).thenReturn(new JavaOnlyMap());
theMock.when(Arguments::createArray).thenReturn(new JavaOnlyArray());
assertThat(ColorParser.parse(activity, color, "color")).isInstanceOf(ReactPlatformColor.class);
assertThat(ColorParser.parse(getContext(), color, "color")).isInstanceOf(ReactPlatformColor.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.reactnativenavigation.options.parsers;

import static org.assertj.core.api.Java6Assertions.assertThat;

import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.BaseRobolectricTest;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;

import static org.assertj.core.api.Java6Assertions.assertThat;

@Ignore("New architecture - WIP")
public class JSONParserTest extends BaseTest {
public class JSONParserTest extends BaseRobolectricTest {
@Test
public void parsesMap() throws Exception {
JavaOnlyMap input = new JavaOnlyMap();
Expand Down
Loading
Loading