-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdd50c6
commit 8c0c3de
Showing
6 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Build Android APK | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup node 16 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
cache: 'gradle' | ||
|
||
- name: Setup Android SDK | ||
uses: android-actions/setup-android@v2 | ||
|
||
- name: Install dependencies | ||
run: | | ||
npm install | ||
cd example | ||
npm install | ||
- name: Build APK | ||
run: | | ||
npm run prepack | ||
cd example/android | ||
./gradlew assembleRelease | ||
mv app/build/outputs/apk/release/app-release.apk app-release-${{ github.sha }}.apk | ||
- name: Upload APK | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: app-release-${{ github.sha }}.apk | ||
path: example/android/app-release-${{ github.sha }}.apk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
android/src/test/java/com/jimmydaddy/imagemarker/base/CornerRadiusTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.jimmydaddy.imagemarker.base | ||
|
||
import android.graphics.RectF | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.bridge.ReadableMapKeySetIterator | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.mockito.Mockito | ||
|
||
class CornerRadiusTest { | ||
|
||
@Test | ||
fun testRadii() { | ||
// 创建一个 mock 的 ReadableMap | ||
val mockMap = Mockito.mock(ReadableMap::class.java) | ||
val mockMapTopLeft = Mockito.mock(ReadableMap::class.java) | ||
|
||
val mockIterator = Mockito.mock(ReadableMapKeySetIterator::class.java) | ||
|
||
// 设置 mock 对象的行为 | ||
Mockito.`when`(mockMap.keySetIterator()).thenReturn(mockIterator) | ||
Mockito.`when`(mockIterator.hasNextKey()).thenReturn(true, false) | ||
Mockito.`when`(mockIterator.nextKey()).thenReturn("topLeft") | ||
Mockito.`when`(mockMap.getMap("topLeft")).thenReturn(mockMapTopLeft) | ||
|
||
// 创建一个 CornerRadius 对象 | ||
val cornerRadius = CornerRadius(mockMap) | ||
|
||
// 测试 radii 方法 | ||
val rect = RectF(0f, 0f, 100f, 100f) | ||
val radii = cornerRadius.radii(rect) | ||
|
||
// 验证结果 | ||
Assert.assertEquals(8, radii.size) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
example/android/app/src/androidTest/java/com/imagemarkerexample/MainActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.imagemarkerexample | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class MainActivityTest { | ||
@Test | ||
fun test() { | ||
onView(withText("background image format:")).check(matches(isDisplayed())) | ||
onView(withText("topLeft")).perform(click()).check(matches(isDisplayed())) | ||
} | ||
|
||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
Assert.assertEquals("com.imagemarkerexample", appContext.packageName) | ||
} | ||
} |