Skip to content

Commit

Permalink
Merge pull request #198 from Arquisoft/feat/e2e
Browse files Browse the repository at this point in the history
test: initial e2e testing
  • Loading branch information
dariogmori authored Apr 8, 2024
2 parents f861fa8 + 61d4ffb commit bcf6b64
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
node-version: 20
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
#- run: npm --prefix webapp run test:e2e TODO: re-enable
- run: npm --prefix webapp run test:e2e
docker-push-api:
runs-on: ubuntu-latest
needs: [ e2e-tests ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Feature: Seeing the about screen of the webpage
Scenario: A logged user wants to see the about screen of the webpage
Given A logged user in the main menu
When The user presses the button for deploying the lateral menu
And the user presses the button for seeing the about secction (i)
Then The screen shows redirects the user to the about screen
And the user presses the button for seeing the about section (i)
Then The user is presented to the about screen
4 changes: 2 additions & 2 deletions webapp/e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testMatch: ["**/steps/*.js"],
testTimeout: 30000,
setupFilesAfterEnv: ["expect-puppeteer"]
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testTimeout: 30000
}
60 changes: 60 additions & 0 deletions webapp/e2e/steps/about.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { defineFeature, loadFeature }=require('jest-cucumber');
const puppeteer = require('puppeteer');
const setDefaultOptions = require("expect-puppeteer").setDefaultOptions;
const feature = loadFeature('./features/about_features/positive_logged_user_seeing_about_screen.feature');
let page;
let browser;

defineFeature(feature, test => {

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })

await page
.goto("http://localhost:3000", {
waitUntil: "networkidle0",
})
.catch(() => {});
});

test("A logged user wants to see the about screen of the webpage", ({given,when,and,then}) => {

let username;
let password;

given("A logged user in the main menu", async () => {
username = "[email protected]"
password = "password"

await expect(page).toClick("button[data-testid='Login'");
await expect(page).toFill("#user", username);
await expect(page).toFill("#password", password);
await expect(page).toClick("button[data-testid='Login'");
});

when("The user presses the button for deploying the lateral menu", async () => {
await expect(page).toClick("#lateralMenuButton");
});

and("the user presses the button for seeing the about section (i)", async () => {
await expect(page).toClick("#aboutButton");
});

then("The user is presented to the about screen", async () => {
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "About" || header === "Sobre nosotros";
expect(value).toBeTruthy();
});
});

afterAll((done) => {
done();
});
});
52 changes: 0 additions & 52 deletions webapp/e2e/steps/register-form.steps.js

This file was deleted.

19 changes: 0 additions & 19 deletions webapp/e2e/test-environment-setup.js

This file was deleted.

2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build": "react-scripts build",
"prod": "serve -s build",
"test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!axios)/'",
"test:e2e": "start-server-and-test 'node e2e/test-environment-setup.js' http://localhost:8000/health prod 3000 \"cd e2e && jest\"",
"test:e2e": "start-server-and-test start 3000 \"cd e2e && jest --detectOpenHandles\"",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/LateralMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const LateralMenu = ({ isOpen, onClose, changeLanguage, isDashboard }) => {
{isLoggedIn && (
<Button data-testid={"LogOut"} type="submit" colorScheme="raw_umber" margin={"10px"} className={"custom-button effect1"} onClick={handleLogout} width="70%">{t("common.logout")}</Button>
)}
<IconButton type="submit" aria-label='About' colorScheme={"forest_green"} icon={<InfoIcon />} className={"custom-button effect1"} onClick={() => {navigate("/about");}} margin={"10px"}></IconButton>
<IconButton type="submit" aria-label='About' colorScheme={"forest_green"} icon={<InfoIcon />} className={"custom-button effect1"} onClick={() => {navigate("/about");}} margin={"10px"} id={"aboutButton"}></IconButton>
</Flex>
</DrawerFooter>
</DrawerContent>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/MenuButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MenuButton = ({ onClick }) => {
}, []);

return (
<Box position={isFixed ? "fixed" : "absolute"} top="1rem" left="1rem">
<Box position={isFixed ? "fixed" : "absolute"} top="1rem" left="1rem" id={"lateralMenuButton"}>
<IconButton
bg="pigment_green.600"
color="whiteAlpha.900"
Expand Down
3 changes: 1 addition & 2 deletions webapp/src/pages/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export default function About() {
<InfoIcon boxSize={10} color="pigment_green.500" />
<Heading as="h2">{t('about.title')}</Heading>
</Box>
<Stack spacing={4} p="1rem" backgroundColor="whiteAlpha.900" boxShadow="md" rounded="1rem">
<Stack spacing={4} p="1rem" backgroundColor="whiteAlpha.900" boxShadow="md" rounded="1rem" data-testid={"About page"}>
<Text>{t("about.description1")}</Text>
<br></br>
<Table variant="simple">
<Thead>
<Tr>
Expand Down

0 comments on commit bcf6b64

Please sign in to comment.