-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(apps/mobile-e2e): add E2E tests covering functionality as define…
…d in the spec
- Loading branch information
1 parent
1c1b5de
commit acd6e1b
Showing
19 changed files
with
190 additions
and
35 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
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 @@ | ||
CAT_API_KEY= |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,31 +1,97 @@ | ||
import { device, element, by, expect } from 'detox'; | ||
import { deleteImage, uploadImage } from '../utils/api'; | ||
|
||
describe('KittyGram home screen', () => { | ||
const getSystemDialog = (label: string) => { | ||
if (device.getPlatform() === 'ios') { | ||
return element(by.label(label)).atIndex(0); | ||
} | ||
return element(by.text(label)); | ||
}; | ||
|
||
describe('KittyGram home screen with a fresh account', () => { | ||
beforeEach(async () => { | ||
await device.reloadReactNative(); | ||
}); | ||
|
||
// it('should be able to upload a photo', () => { | ||
// | ||
// }); | ||
it('should show the empty list with no images message', async () => { | ||
await expect(element(by.id('NoData<CatCard>'))).toBeVisible(); | ||
}); | ||
|
||
it.skip('should be able to upload a photo', () => { | ||
// This test is skipped because it requires relatively extensive system | ||
// dialog handling which is not yet supported by Detox on Android. | ||
// See https://wix.github.io/Detox/docs/api/system/#bysystemlabellabel | ||
}); | ||
|
||
it('should be able to remove a photo', async () => { | ||
const image = await uploadImage(); | ||
await device.reloadReactNative(); | ||
|
||
const deleteButton = element(by.id(`Card.Button<Delete>.${image.id}`)); | ||
await expect(deleteButton).toBeVisible(); | ||
await deleteButton.tap(); | ||
|
||
await getSystemDialog('Confirm').tap(); | ||
|
||
await expect(element(by.id('NoData<CatCard>'))).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('KittyGram home screen with an existing account', () => { | ||
let image; | ||
|
||
beforeEach(async () => { | ||
image = await uploadImage(); | ||
await device.reloadReactNative(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteImage(image.id); | ||
}); | ||
|
||
it('should display a single image', async () => { | ||
await expect(element(by.id('List<CatCard>'))).toBeVisible(); | ||
}); | ||
|
||
it('should be able to upvote a photo', async () => { | ||
const upvoteButton = element(by.id(`Card.Button<Upvote>.${image.id}`)); | ||
|
||
await expect(upvoteButton).toBeVisible(); | ||
await expect(element(by.id(`Card.Score.${image.id}`))).toHaveText('0'); | ||
|
||
await upvoteButton.tap(); | ||
await expect(element(by.id(`Card.Score.${image.id}`))).toHaveText('1'); | ||
}); | ||
|
||
it('should be able to downvote a photo', async () => { | ||
const downvoteButton = element(by.id(`Card.Button<Downvote>.${image.id}`)); | ||
|
||
await expect(downvoteButton).toBeVisible(); | ||
await expect(element(by.id(`Card.Score.${image.id}`))).toHaveText('0'); | ||
|
||
await downvoteButton.tap(); | ||
await expect(element(by.id(`Card.Score.${image.id}`))).toHaveText('-1'); | ||
}); | ||
|
||
it('should be able to favourite and unfavourite a photo', async () => { | ||
const favouriteButton = element( | ||
by.id(`Card.Button<Favourite>.${image.id}`) | ||
); | ||
const unfavouriteButton = element( | ||
by.id(`Card.Button<Unfavourite>.${image.id}`) | ||
); | ||
|
||
// it('should be able to remove a photo', () => { | ||
// | ||
// }); | ||
await expect(favouriteButton).toBeVisible(); | ||
await expect(unfavouriteButton).not.toBeVisible(); | ||
|
||
// it('should be able to upvote a photo', () => { | ||
// | ||
// }); | ||
await favouriteButton.tap(); | ||
|
||
// it('should be able to downvote a photo', () => { | ||
// | ||
// }); | ||
await expect(favouriteButton).not.toBeVisible(); | ||
await expect(unfavouriteButton).toBeVisible(); | ||
|
||
// it('should be able to favourite a photo', () => { | ||
// | ||
// }); | ||
await unfavouriteButton.tap(); | ||
|
||
it('should display welcome message', async () => { | ||
await expect(element(by.id('heading'))).toHaveText('Welcome Mobile 👋'); | ||
await expect(favouriteButton).toBeVisible(); | ||
await expect(unfavouriteButton).not.toBeVisible(); | ||
}); | ||
}); |
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,53 @@ | ||
import { getFixture } from './fixtures'; | ||
|
||
const getUrl = (endpoint: string) => `https://api.thecatapi.com/v1/${endpoint}`; | ||
const getOptions = (options: RequestInit) => ({ | ||
...options, | ||
headers: { | ||
'x-api-key': process.env.CAT_API_KEY, | ||
...options.headers, | ||
}, | ||
}); | ||
|
||
const makeRequest = async (endpoint: string, options: RequestInit) => { | ||
const r = await fetch(getUrl(endpoint), getOptions(options)); | ||
|
||
if (r.ok && options.method === 'DELETE') { | ||
return; | ||
} | ||
|
||
if (r.ok) { | ||
return r.json(); | ||
} | ||
|
||
const error = await r.text(); | ||
console.error(error); | ||
throw new Error(error); | ||
}; | ||
|
||
export const listImages = async () => { | ||
return makeRequest('images?limit=10', { | ||
method: 'GET', | ||
}); | ||
}; | ||
|
||
export const uploadImage = async () => { | ||
const fileName = 'image.jpg'; | ||
const image = await getFixture(fileName); | ||
const body = new FormData(); | ||
body.append('file', image, fileName); | ||
|
||
return makeRequest('images/upload', { | ||
method: 'POST', | ||
headers: { | ||
ContentType: 'multipart/form-data', | ||
}, | ||
body, | ||
}); | ||
}; | ||
|
||
export const deleteImage = async (imageId: string) => { | ||
return makeRequest(`images/${imageId}`, { | ||
method: 'DELETE', | ||
}); | ||
}; |
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,11 @@ | ||
import * as path from 'node:path'; | ||
import { openAsBlob } from 'node:fs'; | ||
import { lookup } from 'mime-types'; | ||
|
||
const fixturesPath = path.resolve(__dirname, '../__fixtures__'); | ||
|
||
export const getFixture = async (fixtureName: string) => { | ||
const resolvedPath = path.resolve(fixturesPath, fixtureName); | ||
const mimeType = lookup(resolvedPath) || 'image/jpg'; | ||
return openAsBlob(resolvedPath, { type: mimeType }); | ||
}; |
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
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
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
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
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
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