From aedff7cc24ed81558726d9523adffca70a63695c Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 9 Aug 2022 16:15:34 +0500 Subject: [PATCH] tests: make note creation tests pass --- apps/mobile/e2e/config.json | 2 +- apps/mobile/e2e/tests/auth.e2e.js | 4 +-- apps/mobile/e2e/tests/index.e2e.js | 4 +-- apps/mobile/e2e/tests/note.e2e.js | 9 +++---- apps/mobile/e2e/tests/utils.js | 32 ++++++++++------------- apps/mobile/src/stores/useSettingStore.ts | 3 ++- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/apps/mobile/e2e/config.json b/apps/mobile/e2e/config.json index c05111ae8..4bbdf635f 100644 --- a/apps/mobile/e2e/config.json +++ b/apps/mobile/e2e/config.json @@ -3,7 +3,7 @@ "testRunner": "jest-circus/runner", "setupFilesAfterEnv": ["./setup.ts"], "testTimeout": 120000, - "testRegex": "index\\.e2e\\.js$", + "testRegex": "\\.e2e\\.js$", "reporters": ["detox/runners/jest/streamlineReporter"], "verbose": true } diff --git a/apps/mobile/e2e/tests/auth.e2e.js b/apps/mobile/e2e/tests/auth.e2e.js index 6027a0f3d..b639c974b 100644 --- a/apps/mobile/e2e/tests/auth.e2e.js +++ b/apps/mobile/e2e/tests/auth.e2e.js @@ -17,7 +17,6 @@ const credentials = { describe('AUTH', () => { it('Sign up', async () => { await prepare(); - await openSideMenu(); await tapByText('Login to sync your notes.'); await sleep(500); @@ -42,7 +41,7 @@ describe('AUTH', () => { await visibleByText('Tap here to sync your notes.'); }); - it.only('Delete account', async () => { + it('Delete account', async () => { await prepare(); await openSideMenu(); await tapByText('Login to sync your notes.'); @@ -50,7 +49,6 @@ describe('AUTH', () => { await elementById('input.password').typeText(credentials.password); await elementById('input.password').tapReturnKey(); await sleep(5000); - await tapByText('Settings'); await sleep(1000); await elementById('scrollview').scrollToIndex(6); diff --git a/apps/mobile/e2e/tests/index.e2e.js b/apps/mobile/e2e/tests/index.e2e.js index 29750dd7a..37ca2f04d 100644 --- a/apps/mobile/e2e/tests/index.e2e.js +++ b/apps/mobile/e2e/tests/index.e2e.js @@ -1,6 +1,4 @@ -const { notesnook } = require('../test.ids'); -const { navigate, tapByText, prepare } = require('./utils'); -const { sleep } = require('./utils'); +const { navigate, tapByText, prepare, sleep } = require('./utils'); describe('APP LAUNCH AND NAVIGATION', () => { it('App should launch successfully & hide welcome screen', async () => { diff --git a/apps/mobile/e2e/tests/note.e2e.js b/apps/mobile/e2e/tests/note.e2e.js index ed4380f15..5b833ec0e 100644 --- a/apps/mobile/e2e/tests/note.e2e.js +++ b/apps/mobile/e2e/tests/note.e2e.js @@ -7,12 +7,9 @@ const { prepare, visibleById, notVisibleById, - elementById, - tapByText, - matchSnapshot, - elementByText + sleep, + exitEditor } = require('./utils'); -const { sleep } = require('./utils'); describe('NOTE TESTS', () => { it('Create a note in editor', async () => { @@ -24,7 +21,7 @@ describe('NOTE TESTS', () => { await prepare(); await createNote(); await tapById(notesnook.ids.note.get(1)); - await tapById(notesnook.editor.back); + await exitEditor(); }); it('Notes properties should show', async () => { diff --git a/apps/mobile/e2e/tests/utils.js b/apps/mobile/e2e/tests/utils.js index 044542445..cbd457670 100644 --- a/apps/mobile/e2e/tests/utils.js +++ b/apps/mobile/e2e/tests/utils.js @@ -2,6 +2,7 @@ const { notesnook } = require('../test.ids'); const fs = require('fs'); const { expect: jestExpect } = require('@jest/globals'); const { toMatchImageSnapshot } = require('jest-image-snapshot'); +const detox = require('detox'); jestExpect.extend({ toMatchImageSnapshot }); const sleep = duration => @@ -13,17 +14,8 @@ const sleep = duration => ); async function LaunchApp() { - await expect(element(by.id('notesnook.splashscreen'))).toBeVisible(); + await expect(element(by.id(notesnook.ids.default.root))).toBeVisible(); await sleep(500); - await element(by.text('Get started')).tap(); - await sleep(500); - await element(by.text('Next')).tap(); - - await sleep(500); - await element(by.text('Create your account')).tap(); - await sleep(500); - await element(by.text('Skip for now')).tap(); - await sleep(300); } function elementById(id) { @@ -58,18 +50,21 @@ async function notVisibleByText(text) { await expect(elementByText(text)).not.toBeVisible(); } +async function exitEditor() { + await detox.device.pressBack(); + await detox.device.pressBack(); +} + async function createNote(_title, _body) { let title = _title || 'Test note description that '; let body = _body || 'Test note description that is very long and should not fit in text.'; await tapById(notesnook.buttons.add); - await elementById(notesnook.editor.id).tap({ - x: 15, - y: 15 - }); - await elementById(notesnook.editor.id).typeText(body); - await tapById(notesnook.editor.back); - await sleep(500); + let webview = web(by.id(notesnook.editor.id)); + await expect(webview.element(by.web.className('ProseMirror'))).toExist(); + await webview.element(by.web.className('ProseMirror')).tap(); + await webview.element(by.web.className('ProseMirror')).typeText(body, true); + await exitEditor(); await expect(element(by.text(body))).toBeVisible(); return { title, body }; @@ -127,5 +122,6 @@ module.exports = { tapByText, elementByText, elementById, - sleep + sleep, + exitEditor }; diff --git a/apps/mobile/src/stores/useSettingStore.ts b/apps/mobile/src/stores/useSettingStore.ts index d343bbf45..b1e1e8678 100644 --- a/apps/mobile/src/stores/useSettingStore.ts +++ b/apps/mobile/src/stores/useSettingStore.ts @@ -1,5 +1,6 @@ //@ts-ignore import { Dimensions } from 'react-native'; +import Config from 'react-native-config'; import { FileType } from 'react-native-scoped-storage'; import create, { State } from 'zustand'; import { ACCENT } from '../utils/color-scheme'; @@ -93,7 +94,7 @@ export const useSettingStore = create((set, get) => ({ reduceAnimations: false, rateApp: false, migrated: false, - introCompleted: false, + introCompleted: Config.isTesting ? true : false, nextBackupRequestTime: undefined, lastBackupDate: undefined, userEmailConfirmed: false,