Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autorefresh tasks for a courier #1840

Merged
merged 41 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d6c346f
refactored TaskListPage into a function component
vladimir-8 Jul 30, 2024
494061f
WIP: use RTK query to get the list of myTasks
vladimir-8 Jul 31, 2024
7606e22
update taskEntities on rtk query
vladimir-8 Jul 31, 2024
d47ad37
extracted baseQuery into a separate file
vladimir-8 Aug 1, 2024
3203b13
added: token refresh flow to rtk api client
vladimir-8 Aug 1, 2024
4d7b641
added: rtk query listeners
vladimir-8 Aug 1, 2024
f7e79a2
added: re-fetch data on page focus
vladimir-8 Aug 1, 2024
28b0810
added: re-fetch data on map page focus
vladimir-8 Aug 2, 2024
0d6baa8
added: comment
vladimir-8 Aug 2, 2024
4a3c754
disable isFetching for rtk query request
vladimir-8 Aug 2, 2024
404df2b
WIP (iOS tests); run coopcycle-web instance locally
vladimir-8 Aug 2, 2024
7aa21d6
temporary disable android tests
vladimir-8 Aug 2, 2024
a41cd7e
updated docker-compose command
vladimir-8 Aug 2, 2024
a984a27
Revert "updated docker-compose command"
vladimir-8 Aug 2, 2024
ed1a520
WIP (android tests); run coopcycle-web instance locally
vladimir-8 Aug 2, 2024
984a5ca
updated docker-compose command
vladimir-8 Aug 2, 2024
8c987d0
set default working-dir
vladimir-8 Aug 2, 2024
c8e136f
updated default working dir
vladimir-8 Aug 2, 2024
b432a58
specify working directory per action
vladimir-8 Aug 2, 2024
faf314f
set working directory per step
vladimir-8 Aug 2, 2024
79b9f71
temporary disable caching
vladimir-8 Aug 2, 2024
47c9fd4
added missing command
vladimir-8 Aug 2, 2024
365af87
added run hints
vladimir-8 Aug 2, 2024
f0409e6
fixed: simulator version
vladimir-8 Aug 2, 2024
0e0585c
added; basic e2e test for the role: courier
vladimir-8 Aug 2, 2024
8c80d29
(e2e tests) use the same Android version on dev as on Github actions
vladimir-8 Aug 3, 2024
410895a
(e2e tests) fixed auth flow on Android
vladimir-8 Aug 3, 2024
47c083d
WIP (android tests); run coopcycle-web instance locally
vladimir-8 Aug 3, 2024
63fd219
fixed: BACKGROUND_PERMISSION_DISCLOSURE alert handling
vladimir-8 Aug 3, 2024
6800099
fixed: working directory per step
vladimir-8 Aug 3, 2024
9c7d234
fix `Decode sentry.properties file` dir
vladimir-8 Aug 3, 2024
f4e24e6
WIP; debug sentry
vladimir-8 Aug 6, 2024
9dd70e4
Revert "WIP; debug sentry"
vladimir-8 Aug 6, 2024
af13500
added: display loading indicator on task list/map
vladimir-8 Aug 6, 2024
1fcfdc7
display sentry upload in test builds
vladimir-8 Aug 8, 2024
cdde81c
disable gradle daemon in test builds
vladimir-8 Aug 8, 2024
fc49f6b
disabled local coopcycle-web instance setup
vladimir-8 Aug 8, 2024
ad73ae2
disabled courier e2e test
vladimir-8 Aug 8, 2024
836fed8
added: comment
vladimir-8 Aug 8, 2024
f7667c2
added: comment
vladimir-8 Aug 8, 2024
726ddc5
updated: comment
vladimir-8 Aug 12, 2024
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
4 changes: 2 additions & 2 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ module.exports = {
devices: {
iosSimulator: {
type: 'ios.simulator',
device: { type: 'iPhone 15', os: 'iOS 17.4' },
device: { type: 'iPhone 15', os: 'iOS 17.5' },
},
androidEmulator: {
type: 'android.emulator',
device: { avdName: 'Pixel_8_API_34' },
device: { avdName: 'Pixel_6_API_28' },
},
attached: {
type: 'android.attached',
Expand Down
67 changes: 61 additions & 6 deletions .github/workflows/testOnDevice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ jobs:
if: github.actor != 'dependabot[bot]'
name: Android Emulator Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: coopcycle-app
env:
GEOCODE_EARTH_API_KEY: ${{ secrets.GEOCODE_EARTH_API_KEY }}
STRIPE_PUBLISHABLE_KEY: ${{ secrets.STRIPE_PUBLISHABLE_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_CONNECT_CLIENT_ID: ${{ secrets.STRIPE_CONNECT_CLIENT_ID }}
AWS_ENDPOINT: ${{ secrets.AWS_ENDPOINT }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
strategy:
# Allow tests to continue on other devices if they fail on one device.
fail-fast: false
Expand All @@ -125,21 +136,65 @@ jobs:
- 28
# - 33
steps:
# setup local coopcycle-web instance:
- uses: actions/checkout@v3
with:
repository: coopcycle/coopcycle-web
path: coopcycle-web
- name: Create .env file
run: cp .env.dist .env
working-directory: coopcycle-web
- name: Pull Docker images
run: docker compose pull --ignore-pull-failures
working-directory: coopcycle-web
- name: Prepare OSRM data
run: |
docker compose run -T --rm osrm wget --no-check-certificate https://coopcycle-assets.sfo2.digitaloceanspaces.com/osm/paris-france.osm.pbf -O /data/data.osm.pbf
docker compose run -T --rm osrm osrm-extract -p /opt/bicycle.lua /data/data.osm.pbf
docker compose run -T --rm osrm osrm-partition /data/data.osrm
docker compose run -T --rm osrm osrm-customize /data/data.osrm
working-directory: coopcycle-web
# Cypress GitHub Action uses npm ci, and it causes a "permission denied" error,
# because it tries to remove the node_modules/ folder, which is mounted with root:root
# We create the node_modules/ folder *BEFORE* starting the containers,
# so that it can be removed without problems.
- name: Create node_modules directory
run: mkdir node_modules
working-directory: coopcycle-web
- name: Start Docker containers
run: docker compose up -d
working-directory: coopcycle-web
- name: Wait for PHP-FPM
run: until docker inspect --format='{{ .State.Health.Status }}' $(docker compose ps -q php) | grep -wq healthy; do sleep 5; done
working-directory: coopcycle-web
- name: Create database
run: docker compose exec -T php bin/console doctrine:schema:create --env=test
working-directory: coopcycle-web
- name: Create typesense collections
run: docker compose exec -T php bin/console typesense:create --env=test
working-directory: coopcycle-web
- name: Setup CoopCycle
run: docker compose exec -T php bin/console coopcycle:setup --env=test
working-directory: coopcycle-web

- uses: actions/checkout@v3
with:
path: coopcycle-app

- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
# https://github.com/jlumbroso/free-disk-space?tab=readme-ov-file#example
android: false
# large-packages: true
# swap-storage: true

- uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'
# Temporary disable yarn caching
# cache: 'yarn'
# cache-dependency-path: "coopcycle-app"

- uses: actions/setup-java@v3
with:
Expand All @@ -150,7 +205,7 @@ jobs:
- name: Decode sentry.properties file
uses: timheuer/[email protected]
with:
fileDir: "./android/"
fileDir: "./coopcycle-app/android/"
fileName: "sentry.properties"
encodedString: ${{ secrets.SENTRY_PROPERTIES_BASE64 }}

Expand Down Expand Up @@ -227,8 +282,8 @@ jobs:
disable-animations: true
script: |
node node_modules/.bin/detox test -c android.emu.release --device-name="test" -l debug
# node node_modules/.bin/detox test -c android.att.release --device-name="test" --take-screenshots all
# node node_modules/.bin/detox test -c android.att.release --device-name="test" --take-screenshots manual -o e2e/screenshots.config.json
# node node_modules/.bin/detox test -c android.att.release --device-name="test" --take-screenshots all
# node node_modules/.bin/detox test -c android.att.release --device-name="test" --take-screenshots manual -o e2e/screenshots.config.json

- name: List supported devices
if: false # useful only for debugging
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ yarn ios
Testing
-------

```
```sh
yarn test
```

Expand All @@ -131,15 +131,21 @@ Build the app and run tests:

Android:

```
```sh
detox build -c android.emu.debug
```

```sh
detox test -c android.emu.debug
```

iOS:

```
```sh
detox build -c ios.sim.debug
```

```sh
detox test -c ios.sim.debug
```

Expand Down
1 change: 1 addition & 0 deletions e2e/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
afterAll: true,
beforeAll: true,
beforeEach: true,
expect: true,
by: true,
device: true,
element: true,
Expand Down
45 changes: 45 additions & 0 deletions e2e/02_courier.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
authenticateWithCredentials,
connectToTestInstance,
symfonyConsole,
} from './utils';

const execSync = require('child_process').execSync;

describe('Courier', () => {
beforeEach(async () => {
symfonyConsole('coopcycle:fixtures:load -f cypress/fixtures/courier.yml');

if (device.getPlatform() === 'ios') {
// disable password autofill: https://github.com/wix/Detox/issues/3761
execSync(
`plutil -replace restrictedBool.allowPasswordAutoFill.value -bool NO ~/Library/Developer/CoreSimulator/Devices/${device.id}/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles/Library/ConfigurationProfiles/UserSettings.plist`,
);
execSync(
`plutil -replace restrictedBool.allowPasswordAutoFill.value -bool NO ~/Library/Developer/CoreSimulator/Devices/${device.id}/data/Library/UserConfigurationProfiles/EffectiveUserSettings.plist`,
);
execSync(
`plutil -replace restrictedBool.allowPasswordAutoFill.value -bool NO ~/Library/Developer/CoreSimulator/Devices/${device.id}/data/Library/UserConfigurationProfiles/PublicInfo/PublicEffectiveUserSettings.plist`,
);
}
await device.reloadReactNative();
await connectToTestInstance();
});

it(`should be able to login and see tasks`, async () => {
await authenticateWithCredentials('jane', '12345678');

if (device.getPlatform() === 'android') {
// dismiss BACKGROUND_PERMISSION_DISCLOSURE alert
await element(by.text('CLOSE')).tap();
}

await expect(element(by.id('messengerTabMap'))).toBeVisible();
await expect(element(by.id('messengerTabList'))).toBeVisible();

await element(by.id('messengerTabList')).tap();

await expect(element(by.id('task:0'))).toBeVisible();
await expect(element(by.id('task:1'))).toBeVisible();
});
});
50 changes: 50 additions & 0 deletions e2e/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
const execSync = require('child_process').execSync;
const os = require('os');

export const COMMAND_PREFIX = "cd ../coopcycle-web && docker compose exec -T php"

export const symfonyConsole = (command) => {
const prefix = COMMAND_PREFIX
let cmd = `bin/console ${ command } --env="test"`
if (prefix) {
cmd = `${ prefix } ${ cmd }`
}
execSync(cmd)
}

export const connectToDemo = async () => {
await expect(element(by.id('chooseCityBtn'))).toBeVisible();
await element(by.id('chooseCityBtn')).tap();
Expand All @@ -14,10 +28,46 @@ export const connectToDemo = async () => {
} catch (e) {}
};

const getLocalIpAddress = () => {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
return iface.address;
}
}
}
return null;
};

export const connectToTestInstance = async () => {
await expect(element(by.id('chooseCityBtn'))).toBeVisible();
await element(by.id('chooseCityBtn')).tap();

await expect(element(by.id('moreServerOptions'))).toBeVisible();
await element(by.id('moreServerOptions')).tap();

await element(by.id('customServerURL')).typeText(`${getLocalIpAddress()}:9080\n`);

try {
// We deliberately add "\n" to hide the keyboard
// The tap below shouldn't be necessary
await element(by.id('submitCustomServer')).tap();
} catch (e) {}
};

export const authenticateWithCredentials = async (username, password) => {
await expect(element(by.id('menuBtn'))).toBeVisible();
await element(by.id('menuBtn')).tap();

await element(by.id('drawerAccountBtn')).tap();
//FIXME: for some reason drawer menu does not close after the first tap on Android
if (device.getPlatform() === 'android') {
const attrs = await element(by.id('drawerAccountBtn')).getAttributes()
if (attrs.visible) {
await element(by.id('drawerAccountBtn')).tap();
}
}

await element(by.id('loginUsername')).typeText(`${username}\n`);
await element(by.id('loginPassword')).typeText(`${password}\n`);
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ SPEC CHECKSUMS:
StripePaymentSheet: a25d920bb3bb5e2580696476482dc7df9cb5e4e2
StripePaymentsUI: 66088abec88754bbdd522ef227dfdbb2265a653e
StripeUICore: b193c7d35e9cd1b04bc9ed4a6fb8c548fcee83fa
Yoga: 9e6a04eacbd94f97d94577017e9f23b3ab41cf6c
Yoga: a716eea57d0d3430219c0a5a233e1e93ee931eb7
ZXingObjC: 8898711ab495761b2dbbdec76d90164a6d7e14c5

PODFILE CHECKSUM: d949c9fd9c4ce5f3ec67d52ca1f4a1ca13072560
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@tabler/icons-react-native": "^3.2.0",
"@turf/turf": "^6.5.0",
"abortcontroller-polyfill": "^1.7.5",
"async-mutex": "^0.5.0",
"axios": "^1.6.8",
"buffer": "^6.0.3",
"centrifuge": "^2.8.4",
Expand Down
Loading
Loading