Skip to content

Commit

Permalink
Added Two more Test Suites for Hooks and Selenium GUI Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
NightWalker7558 committed May 13, 2024
1 parent d20e091 commit 5c5a3b1
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 117 deletions.
125 changes: 125 additions & 0 deletions PhotoGallery.side
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"id": "5961be57-55dc-4f00-854f-8c09b6e6875f",
"version": "2.0",
"name": "PhotoGallery",
"url": "http://localhost:3000",
"tests": [{
"id": "c196feb8-a3a1-4b30-aa00-896b11c5977f",
"name": "Logging in and uploading image",
"commands": [{
"id": "b4d664ef-2971-4428-90da-822bbd627110",
"comment": "",
"command": "open",
"target": "/login",
"targets": [],
"value": ""
}, {
"id": "df90103a-093c-4981-8b5f-6747e9fdb05b",
"comment": "",
"command": "setWindowSize",
"target": "954x693",
"targets": [],
"value": ""
}, {
"id": "82335a41-e785-4a5d-a3bc-700cd57c70e9",
"comment": "",
"command": "click",
"target": "id=username",
"targets": [
["id=username", "id"],
["css=#username", "css:finder"],
["xpath=//input[@id='username']", "xpath:attributes"],
["xpath=//div[@id='root']/div/div/div/div/div/form/div[2]/input", "xpath:idRelative"],
["xpath=//input", "xpath:position"]
],
"value": ""
}, {
"id": "cd74eff1-dc9c-48b5-962c-9a5630614d83",
"comment": "",
"command": "type",
"target": "id=username",
"targets": [
["id=username", "id"],
["css=#username", "css:finder"],
["xpath=//input[@id='username']", "xpath:attributes"],
["xpath=//div[@id='root']/div/div/div/div/div/form/div[2]/input", "xpath:idRelative"],
["xpath=//input", "xpath:position"]
],
"value": "AshIsHere"
}, {
"id": "58118ef3-5918-40fd-9d56-6da599f7ecc2",
"comment": "",
"command": "click",
"target": "id=password",
"targets": [
["id=password", "id"],
["css=#password", "css:finder"],
["xpath=//input[@id='password']", "xpath:attributes"],
["xpath=//div[@id='root']/div/div/div/div/div/form/div[3]/input", "xpath:idRelative"],
["xpath=//div[3]/input", "xpath:position"]
],
"value": ""
}, {
"id": "1a9597cc-3260-4407-b90a-e27ff5722a1c",
"comment": "",
"command": "type",
"target": "id=password",
"targets": [
["id=password", "id"],
["css=#password", "css:finder"],
["xpath=//input[@id='password']", "xpath:attributes"],
["xpath=//div[@id='root']/div/div/div/div/div/form/div[3]/input", "xpath:idRelative"],
["xpath=//div[3]/input", "xpath:position"]
],
"value": "Ash@12345"
}, {
"id": "91def1cf-f42a-4738-9fac-e3f513dbdba2",
"comment": "",
"command": "click",
"target": "css=.css-1ikp3wz",
"targets": [
["css=.css-1ikp3wz", "css:finder"],
["xpath=//button[@type='submit']", "xpath:attributes"],
["xpath=//div[@id='root']/div/div/div/div/div/form/button", "xpath:idRelative"],
["xpath=//button", "xpath:position"],
["xpath=//button[contains(.,'Log In')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "77e9dfc5-89d9-47dd-94ca-dbef5ccaa556",
"comment": "",
"command": "click",
"target": "css=.css-6r4ark",
"targets": [
["css=.css-6r4ark", "css:finder"],
["xpath=//div[@id='root']/div/div/div[2]/div/div/div/p", "xpath:idRelative"],
["xpath=//div[2]/div/div/div/p", "xpath:position"],
["xpath=//p[contains(.,'View Type:')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "ef3a29f4-4db6-4565-a45c-2fba0960c730",
"comment": "",
"command": "click",
"target": "id=field-:r9:",
"targets": [
["id=field-:r9:", "id"],
["css=#field-\\3Ar9\\3A", "css:finder"],
["xpath=//input[@id='field-:r9:']", "xpath:attributes"],
["xpath=//div[@id='root']/div/div/div[2]/div/div/form/div/input", "xpath:idRelative"],
["xpath=//input", "xpath:position"]
],
"value": ""
}]
}],
"suites": [{
"id": "1fb9c823-da16-48d5-8c26-cccc61116a03",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["c196feb8-a3a1-4b30-aa00-896b11c5977f"]
}],
"urls": ["http://localhost:3000/"],
"plugins": []
}
158 changes: 47 additions & 111 deletions view_generator_serv/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion view_generator_serv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!axios)/\"",
"test": "react-scripts test --watchAll --transformIgnorePatterns \"node_modules/(?!axios)/\"",
"testCI": "CI=true react-scripts test --transformIgnorePatterns \"node_modules/(?!axios)/\"",
"eject": "react-scripts eject"
},
Expand All @@ -54,6 +54,7 @@
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@faker-js/faker": "^8.4.1",
"@testing-library/react-hooks": "^8.0.1",
"jest-mock-axios": "^4.7.3",
"react-test-renderer": "^18.3.1"
}
Expand Down
10 changes: 6 additions & 4 deletions view_generator_serv/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import renderer from 'react-test-renderer';
import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';
import { configure } from '@testing-library/react';

// automatically unmount and cleanup DOM after the test is finished.
configure({ autoCleanup: true });
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { useAuthContext } from '../../hooks/useAuthContext';
Expand Down
38 changes: 38 additions & 0 deletions view_generator_serv/src/context/__test__/AuthContext.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { render, screen } from '@testing-library/react';
import { AuthContextProvider, AuthContext } from '../AuthContext';
import { useContext } from 'react';

const TestingComponent = () => {
const { user } = useContext(AuthContext);
return (
<>
<p data-testid="user-name">{user?.name}</p>
</>
);
};

describe('<AuthContextProvider />', () => {
let user;

beforeAll(() => {
user = {
name: 'John Doe',
};
});

beforeEach(() => {
// Mock localStorage
Storage.prototype.getItem = jest.fn(() => JSON.stringify(user));

render(
<AuthContextProvider>
<TestingComponent />
</AuthContextProvider>,
);
});

it('provides expected AuthContext to child elements', () => {
const userName = screen.getByTestId('user-name');
expect(userName.textContent).toEqual(user.name);
});
});
Loading

0 comments on commit 5c5a3b1

Please sign in to comment.