-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing instructions and auto tests (#171)
* Adding a link to Running-man-01/trashai_nbs project (#168) * update frontend app doc * Add manual instructions. * Added test-ids * Add test-ids to the navigation tabs * Add smoke test draft * Add placeholder file * Add photos for manual testing instructions * Upgrade node version * Remove cypress * Add test ids to summary page * Jest + Puppeteer setup * Add smoke test * Added back manual instructions * Add images for manual instructions * Add instruction for running auto tests --------- Co-authored-by: Dan Fey <feydanm@gmail.com>
- Loading branch information
Showing
23 changed files
with
295 additions
and
12 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 |
---|---|---|
|
@@ -29,3 +29,4 @@ delete.bat | |
model/build/Mask* | ||
model/build/taco* | ||
tags | ||
frontend/yarn.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Tests and Verifications | ||
|
||
## Automatic Tests | ||
|
||
### Scenarios | ||
1. Does the landing pag load? | ||
2. On hitting show samples, does processing complete in an expected amount of time? Does it show all the results expected? | ||
3. After recieving results, can you click an image and does the page show the expected data/metadata/etc? | ||
4. After recieving results, does the summary page contain the correct data? | ||
|
||
## How to run | ||
|
||
1. Navigate to `frontend/` | ||
2. Run `yarn install` | ||
2. Spin up docker container | ||
`docker-compose up` | ||
3. Run the auto tests | ||
`yarn run jest` | ||
|
||
## Manual Tests | ||
|
||
1. Does the landing pag load? | ||
|
||
When you open the landing page. Either at https://www.trashai.org/ or http://localhost:5150 | ||
|
||
The page should loads in a reasonable timeframe. (<2 seconds) | ||
|
||
*You can use the `Network` tab in the dev tools for more fine grained analysis.* | ||
|
||
2. On hitting show samples, does processing complete in an expected amount of time? Does it show all the results expected? | ||
|
||
When the show samples button is pressed. (as depicted below) | ||
![Instructions](misc/Show_Samples_Button.png "Show Title Button") | ||
|
||
Then the app will start processing images. (as depcited below) | ||
![Processing](misc/Processing_Samples.png "Processing Samples Progress Bar") | ||
|
||
*The processing should be relatively quick, it it takes more than a minute, something is definetly wrong.* | ||
|
||
When the processing is done, the results will be available in the summary page. | ||
|
||
![Summary ](misc/Summary_Of_Samples.png "Summary of Sample Results") | ||
|
||
It should be populated like above. | ||
|
||
3. After recieving results, can you click an image and does the page show the expected data/metadata/etc? | ||
|
||
When one of the links in the summary table is clicked. | ||
|
||
![Open images](misc/Open_images.png "Open Images") | ||
|
||
Then the images will be displayed along with the segmentation and classes detected. | ||
|
||
![List Images](misc/Images_with_Segmentation.png "List Images") | ||
|
||
When the METADATA tab is opened, the relevant metadata for the image is displayed. | ||
|
||
![View Metadata](misc/Viewing_Metadata.png "View Metadata") | ||
|
||
4. After recieving results, does the summary page contain the correct data? | ||
|
||
*The summary page shows the results of processing a random sample of images, as long as it's not empty it can be considered as correct.* |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
*placeholder* |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-disable no-undef */ | ||
const timeout = 12000 | ||
const url = 'http://localhost:5150/' | ||
|
||
describe( | ||
'Smoke test for Trash-AI', | ||
() => { | ||
let page | ||
beforeAll(async () => { | ||
page = await global.__BROWSER__.newPage() | ||
await page.setViewport({ | ||
width: 1536, | ||
height: 960, | ||
}) | ||
await page.goto(url) | ||
}, timeout) | ||
|
||
afterAll(async () => { | ||
await page.close() | ||
}) | ||
|
||
it('should load without error', async () => { | ||
const text = await page.evaluate(() => document.body.textContent) | ||
expect(text).toContain('Trash AI') | ||
}) | ||
|
||
it( | ||
'should show samples when prompted', | ||
async () => { | ||
// Open actions menu | ||
const openActionsBtn = await page.waitForSelector( | ||
'#actions-button-test-id', | ||
) | ||
await openActionsBtn.click() | ||
await page.waitForTimeout(1000) | ||
|
||
// Click Show Samples | ||
const showSamplesBtn = await page.waitForSelector( | ||
'#show-samples-test-id', | ||
) | ||
await showSamplesBtn.click() | ||
await page.waitForTimeout(2000) | ||
|
||
// Navigate to Summary page | ||
const summaryBtn = await page.waitForSelector( | ||
'#summary-tab-test-id', | ||
) | ||
await summaryBtn.click() | ||
await page.waitForTimeout(500) | ||
|
||
// Check if navigations was successful | ||
current_url = await page.url() | ||
expect(current_url).toBe(`${url}summary/detections`) | ||
|
||
// Check if results are displayed | ||
const drinkCanImg = await page.waitForSelector( | ||
'a[href="/detection/Drink%20can"]', | ||
) | ||
await drinkCanImg.click() | ||
await page.waitForTimeout(500) | ||
|
||
// Check if navigation happened | ||
current_url = await page.url() | ||
expect(current_url).toBe(`${url}detection/Drink%20can`) | ||
|
||
// Navigate to image view page | ||
const sampleImg = await page.waitForSelector( | ||
'div[id="sample01.jpg-test-id"]', | ||
) | ||
await sampleImg.click() | ||
await page.waitForTimeout(500) | ||
|
||
// Check if navigation happened | ||
current_url = await page.url() | ||
expect(current_url).toBe(`${url}image/0/image`) | ||
|
||
// Check if the image is loaded | ||
const canvasImg = await page.waitForSelector('#canvasparent') | ||
|
||
// Check of the images classes are loaded | ||
const drinkCanClass = await page.waitForSelector( | ||
'a[href="/detection/Drink%20can"]', | ||
) | ||
|
||
const paperCupClass = await page.waitForSelector( | ||
'a[href="/detection/Paper%20cup"]', | ||
) | ||
|
||
// Check of the image and metadata tabs are loaded | ||
const imageTab = await page.waitForSelector( | ||
'#image-tab-test-id', | ||
) | ||
|
||
const metadataTab = await page.waitForSelector( | ||
'#meta-tab-test-id', | ||
) | ||
metadataTab.click() | ||
await page.waitForTimeout(500) | ||
|
||
// Check is exif data is displayed | ||
const exifData = await page.waitForSelector('#exifData-test-id') | ||
// Check if metadata is displayed | ||
const metaData = await page.waitForSelector('#metaData-test-id') | ||
await page.waitForTimeout(500) | ||
}, | ||
timeout, | ||
) | ||
}, | ||
timeout, | ||
) |
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,8 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
baseUrl: "https://www.trashai.org/", | ||
pageLoadTimeout: 3000 | ||
}, | ||
}); |
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,5 @@ | ||
module.exports = { | ||
globalSetup: './setup.js', | ||
globalTeardown: './teardown.js', | ||
testEnvironment: './puppeteer_environment.js', | ||
} |
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,36 @@ | ||
import NodeEnvironment from 'jest-environment-node' | ||
import puppeteer from 'puppeteer' | ||
import fs from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup') | ||
|
||
class PuppeteerEnvironment extends NodeEnvironment { | ||
constructor(config) { | ||
super(config) | ||
} | ||
|
||
async setup() { | ||
console.log('Setup Test Environment.') | ||
await super.setup() | ||
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8') | ||
if (!wsEndpoint) { | ||
throw new Error('wsEndpoint not found') | ||
} | ||
this.global.__BROWSER__ = await puppeteer.connect({ | ||
browserWSEndpoint: wsEndpoint, | ||
}) | ||
} | ||
|
||
async teardown() { | ||
console.log('Teardown Test Environment.') | ||
await super.teardown() | ||
} | ||
|
||
runScript(script) { | ||
return super.runScript(script) | ||
} | ||
} | ||
|
||
module.exports = PuppeteerEnvironment |
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,23 @@ | ||
import puppeteer from 'puppeteer' | ||
import fs from 'fs' | ||
import mkdirp from 'mkdirp' | ||
import os from 'os' | ||
import path from 'path' | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup') | ||
|
||
module.exports = async function () { | ||
console.log('Setup Puppeteer') | ||
const browser = await puppeteer.launch({ | ||
headless: false, | ||
defaultViewport: null, | ||
args: ['--window-size=1920,1080'], | ||
}) | ||
// This global is not available inside tests but only in global teardown | ||
global.__BROWSER_GLOBAL__ = browser | ||
// Instead, we expose the connection details via file system to be used in tests | ||
mkdirp.sync(DIR) | ||
|
||
console.log(`DIR ${DIR}`) | ||
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint()) | ||
} |
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
Oops, something went wrong.