Skip to content

Commit

Permalink
Bypass react error overlay in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tudde committed Nov 9, 2024
1 parent 7e8fbfb commit bb42c81
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/WrapperApp/components/NavDrawer/NavDrawer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@ describe('NavDrawer component', () => {
await driver.quit();
}, 30000);

// this function hides the react error overlay, as its presence interferes with the tests when running locally
async function hideErrorOverlay() {
try {
const overlay = await driver.wait(
until.elementLocated(By.id('webpack-dev-server-client-overlay')),
1000 // short timeout to avoid unnecessary waiting
);
await driver.executeScript("arguments[0].style.display = 'none';", overlay);
} catch (error) {
// overlay not found within timeout, proceed without hiding it
}
}

//this test checks if the menu button (upper left corner, next to the yaptide logo) has rendered
test('renders a menu button', async () => {
await driver.get('http://localhost:3000');
//hide react overlay if present
await hideErrorOverlay();
const menuButton = await driver.findElement(
By.xpath("//button[@aria-label = 'Toggle drawer button']")
);
Expand All @@ -28,6 +43,8 @@ describe('NavDrawer component', () => {
//this test check if the menu button works (closes and opens the menu drawer)
test('closes and opens the drawer on click', async () => {
await driver.get('http://localhost:3000');
//hide react overlay if present
await hideErrorOverlay();

//find the menu button and then click it
const menuButton = await driver.findElement(
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/FlukaConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ describe('Fluka Converter', () => {
await driver.quit();
}, 30_000);

// this function hides the react error overlay, as its presence interferes with the tests when running locally
async function hideErrorOverlay() {
try {
const overlay = await driver.wait(
until.elementLocated(By.id('webpack-dev-server-client-overlay')),
1000 // short timeout to avoid unnecessary waiting
);
await driver.executeScript("arguments[0].style.display = 'none';", overlay);
} catch (error) {
// overlay not found within timeout, proceed without hiding it
}
}

//this test checks if converter works correctly - opens an example and generates config files
test('converter generates correct files', async () => {
await driver.get('http://localhost:3000');

//hide react overlay if present
await hideErrorOverlay();

// Wait for the application to load
expect(
await driver.wait(
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/ShieldhitConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,26 @@ describe('ShieldhitConverter', () => {
await driver.quit();
}, 30_000);

// this function hides the react error overlay, as its presence interferes with the tests when running locally
async function hideErrorOverlay() {
try {
const overlay = await driver.wait(
until.elementLocated(By.id('webpack-dev-server-client-overlay')),
1000 // short timeout to avoid unnecessary waiting
);
await driver.executeScript("arguments[0].style.display = 'none';", overlay);
} catch (error) {
// overlay not found within timeout, proceed without hiding it
}
}

//this test checks if converter works correctly - opens an example and generates config files
test('converter generates correct files', async () => {
await driver.get('http://localhost:3000');

//hide react overlay if present
await hideErrorOverlay();

// Wait for the application to load
expect(
await driver.wait(
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/TopasConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@ describe('TopasConverter', () => {
await driver.quit();
}, 30_000);

// this function hides the react error overlay, as its presence interferes with the tests when running locally
async function hideErrorOverlay() {
try {
const overlay = await driver.wait(
until.elementLocated(By.id('webpack-dev-server-client-overlay')),
1000 // short timeout to avoid unnecessary waiting
);
await driver.executeScript("arguments[0].style.display = 'none';", overlay);
} catch (error) {
// overlay not found within timeout, proceed without hiding it
}
}

//this test checks if converter works correctly - opens an example and generates config files
// expected to fail because Topas was temporarily removed from the project
xtest('converter generates correct files', async () => {
await driver.get('http://localhost:3000');

//hide react overlay if present
await hideErrorOverlay();

// Wait for the application to load
expect(
await driver.wait(
Expand Down

0 comments on commit bb42c81

Please sign in to comment.