Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Nov 9, 2023
1 parent 3440a37 commit 2cf6d2f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 108 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y python3-setuptools python3-pip chromium-browser libgbm1 && make install-deps
- name: DB setup
run: |
cp cres/db.sqlite standards_cache.sqlite
make migrate-upgrade
- name: Run App in background
- name: Run app and e2e tests
run: |
yarn build
[ -d "./venv" ] && . ./venv/bin/activate
export FLASK_APP=./cre.py
export FLASK_CONFIG=development
FLASK_CONFIG=development flask run&
- name: Test-e2e
run: yarn test:e2e
FLASK_CONFIG=development flask run &
sleep 20s
yarn test:e2e
7 changes: 6 additions & 1 deletion application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
StructuredRel,
db,
)
import neo4j
from sqlalchemy.orm import aliased
import os
import logging
Expand Down Expand Up @@ -547,7 +548,11 @@ def standards(self) -> List[str]:

@classmethod
def everything(self) -> List[str]:
return [NEO_DB.parse_node(rec) for rec in NeoDocument.nodes.all()]
try:
return [NEO_DB.parse_node(rec) for rec in NeoDocument.nodes.all()]
except neo4j.exceptions.ServiceUnavailable:
logger.error("Neo4j DB offline")
return None

@staticmethod
def parse_node(node: NeoDocument) -> cre_defs.Document:
Expand Down
12 changes: 5 additions & 7 deletions application/frontend/src/pages/Search/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ export const SearchBar = () => {
term: e.target.value,
});
}}
label={
<Button id="SearchButton" primary onSubmit={onSubmit}>
<Icon name="search" />
Search
</Button>
}
labelPosition="right"
action={{
icon: 'search',
content: 'Search',
color: 'primary',
}}
placeholder="Search..."
/>
</Form.Field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('App.js', () => {
jest.setTimeout(1000000);
browser = await puppeteer.launch(debug);
page = await browser.newPage();
page.setDefaultTimeout(15000)
});

it('contains the welcome text', async () => {
Expand All @@ -25,26 +26,24 @@ describe('App.js', () => {

it('can search for random strs', async () => {
await page.goto('http://127.0.0.1:5000');
await page.waitForSelector('#SearchBar', { timeout: 10000 });
await page.waitForSelector('#SearchButton', { timeout: 10000 });
await page.waitForSelector('#SearchBar');
await page.type('#SearchBar > div > input', 'asdf');
await page.click('#SearchButton');
await page.waitForSelector('.content', { timeout: 10000 });
await page.click('#SearchBar > div > button');
await page.waitForSelector('.content');
const text = await page.$eval('.content', (e) => e.textContent);
expect(text).toContain('No results match your search term');
});

it('can search for cryptography using the free text method and it returns both Nodes and CRES', async () => {
await page.goto('http://127.0.0.1:5000');
await page.waitForSelector('#SearchBar', { timeout: 10000 });
await page.waitForSelector('#SearchButton', { timeout: 10000 });
await page.waitForSelector('#SearchBar');
await page.type('#SearchBar > div > input', 'crypto');
await page.click('#SearchButton');
await page.waitForSelector('.content', { timeout: 10000 });
await page.waitForSelector('.standard-page__links-container', { timeout: 10000 });
await page.click('#SearchBar > div > button');
await page.waitForSelector('.content');
const text = await page.$eval('.content', (e) => e.textContent);
expect(text).not.toContain('No results match your search term');


await page.waitForSelector('.standard-page__links-container');
const results = await page.$$('.standard-page__links-container');
expect(results.length).toBeGreaterThan(1);

Expand All @@ -57,11 +56,12 @@ describe('App.js', () => {

it('can search for a standard by name, section and the standard page works as expected', async () => {
await page.goto('http://127.0.0.1:5000/node/standard/ASVS');
await page.waitForSelector('.content', { timeout: 10000 });
await page.waitForSelector('.standard-page__links-container', { timeout: 10000 });
await page.waitForSelector('.content');
const text = await page.$$('.content', (e) => e.textContent);
expect(text).not.toContain('No results match your search term');

await page.waitForSelector('.standard-page__links-container');

// title match
const page_title = await page.$eval('.standard-page__heading', (e) => e.textContent);
expect(page_title).toContain('ASVS');
Expand All @@ -73,12 +73,12 @@ describe('App.js', () => {
// pagination
const original_content = await page.content();
await page.click('a[type="pageItem"][value="2"]');
await page.waitForSelector('.content', { timeout: 10000 });
await page.waitForSelector('.content');
expect(await page.content()).not.toEqual(original_content);

// link to section
await page.click('.standard-page__links-container>.title>a');
await page.waitForSelector('.content', { timeout: 10000 });
await page.waitForSelector('.content');
const url = await page.url();
expect(url).toContain('section');
const section = await page.$eval('.standard-page > span:nth-child(2)', (e) => e.textContent);
Expand All @@ -103,14 +103,14 @@ describe('App.js', () => {

it('can search for a cre', async () => {
await page.goto('http://127.0.0.1:5000');
await page.waitForSelector('#SearchBar', { timeout: 10000 });
await page.waitForSelector('#SearchButton', { timeout: 10000 });
await page.waitForSelector('#SearchBar');
await page.type('#SearchBar > div > input', '558-807');
await page.click('#SearchButton');
await page.waitForSelector('.content', { timeout: 10000 });
await page.waitForSelector('.standard-page__links-container', { timeout: 10000 });
await page.click('#SearchBar > div > button');
await page.waitForSelector('.content');
const text = await page.$$('.content', (e) => e.textContent);
expect(text).not.toContain('No results match your search term');

await page.waitForSelector('.standard-page__links-container');

// title match
const entry_title = await page.$eval('div.title.document-node', (e) => e.textContent);
Expand All @@ -124,7 +124,7 @@ describe('App.js', () => {
await page.click('.dropdown');
const selector =
'.standard-page__links-container>.document-node>.document-node__link-type-container:nth-child(2)';
await page.waitForSelector(selector, { timeout: 10000 });
await page.waitForSelector(selector);

const nested = await page.$$(
'.standard-page__links-container>.document-node>.document-node__link-type-container>div>.accordion'
Expand All @@ -134,7 +134,7 @@ describe('App.js', () => {

it('can filter', async () => {
await page.goto('http://127.0.0.1:5000/cre/558-807?applyFilters=true&filters=asvs');
await page.waitForSelector('.cre-page__links-container', { timeout: 10000 });
await page.waitForSelector('.cre-page__links-container');
// Get inner text
const innerText = await page.evaluate(
() => (document.querySelector('.cre-page__links-container') as HTMLElement)?.innerText
Expand All @@ -145,7 +145,7 @@ describe('App.js', () => {

// ensure case insensitive filtering
await page.goto('http://127.0.0.1:5000/cre/558-807?applyFilters=true&filters=ASVS');
await page.waitForSelector('.cre-page__links-container', { timeout: 10000 });
await page.waitForSelector('.cre-page__links-container');
const intxt = await page.evaluate(
() => (document.querySelector('.cre-page__links-container') as HTMLElement)?.innerText
);
Expand All @@ -164,7 +164,6 @@ describe('App.js', () => {
expect(response.url()).toBe('http://127.0.0.1:5000/node/standard/CWE/sectionid/1002');

const redirectResponse = await page.goto('http://127.0.0.1:5000/smartlink/standard/CWE/404');
page.waitForNavigation('networkidle2');
expect(redirectResponse.url()).toBe('https://cwe.mitre.org/data/definitions/404.html');
});

Expand Down
72 changes: 0 additions & 72 deletions jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lint": "prettier --write '**/*.tsx' '**/*.ts' '**/*.js'",
"build": "webpack --config webpack.prod.js",
"start": "webpack serve",
"test:e2e": "jest -c jest.config.js --testPathPattern=.*-e2etest.tsx?$",
"test:e2e": "jest",
"postinstall": "del-cli node_modules/@types/react-dom/node_modules/@types && del-cli node_modules/webpack/types.d.ts"
},
"keywords": [],
Expand Down

0 comments on commit 2cf6d2f

Please sign in to comment.