Skip to content

Commit d202645

Browse files
author
Pippo Ramos
authored
add tests folder
1 parent 7b863a8 commit d202645

File tree

7 files changed

+182
-0
lines changed

7 files changed

+182
-0
lines changed

tests/App.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { render, screen } from '@testing-library/react';
2+
import App from '../App';
3+
import { BrowserRouter as Router } from 'react-router-dom';
4+
5+
test('renders learn react link', () => {
6+
render(
7+
<Router>
8+
<App />
9+
</Router>);
10+
const linkElement = screen.getByText(/Quickly build an visualisation animation form problem or VFG file shows the plan and subplan for each problem./i);
11+
expect(linkElement).toBeInTheDocument();
12+
});

tests/Student.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// <reference types="cypress" />
2+
import 'cypress-file-upload';
3+
4+
describe('user student E2E', () =>{
5+
beforeEach(()=>{
6+
cy.visit('/')
7+
})
8+
9+
10+
it('Build from problem',()=>{
11+
//go to pageONe
12+
cy.contains('from problem').parent().parent().parent().find('[type=button]').click()
13+
//test to upload file click with no file
14+
cy.contains('Upload Files').click()
15+
cy.contains("Some files are missing").should("be.visible")
16+
cy.contains("Some files are missing").parent().find('button').click()
17+
//Upload files
18+
cy.fixture('./demoData/Blockworld_domain_normal.pddl').then(fileContent => {
19+
cy.contains('Domain File').parent().parent().parent().find('input[type="file"]').attachFile({
20+
fileContent: fileContent.toString(),
21+
fileName: 'Blockworld_domain_normal.pddl',
22+
mimeType: 'file'
23+
});
24+
});
25+
cy.fixture('./demoData/Blockworld_problem_normal.pddl').then(fileContent => {
26+
cy.contains('Problem File').parent().parent().parent().find('input[type="file"]').attachFile({
27+
fileContent: fileContent.toString(),
28+
fileName: 'Blockworld_problem_normal.pddl',
29+
mimeType: 'file'
30+
});
31+
});
32+
cy.fixture('./demoData/Blocksworld_AP.pddl').then(fileContent => {
33+
cy.contains('Animation File').parent().parent().parent().find('input[type="file"]').attachFile({
34+
fileContent: fileContent.toString(),
35+
fileName: 'Blocksworld_AP.pddl',
36+
mimeType: 'file'
37+
});
38+
});
39+
//check messages
40+
cy.contains("File Blocksworld_AP.pddl successfully added.").should("be.visible")
41+
//Load next file
42+
cy.contains('Upload Files').click()
43+
cy.wait(5000)
44+
45+
cy.get('canvas').should("be.visible")
46+
})
47+
})

tests/Testing.pdf

630 KB
Binary file not shown.

tests/dropAndFetch.test.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import React from 'react';
2+
import ReactDOM, {render, unmountComponentAtNode} from 'react-dom';
3+
import DropAndFetch from './dropAndFetch';
4+
import { act } from "react-dom/test-utils";
5+
import { constant } from 'lodash';
6+
7+
8+
9+
10+
describe('pageOne dropAndFetch: rendering correctly', () =>{
11+
12+
let container = null;
13+
beforeEach(() => {
14+
// setup a DOM element as a render target
15+
container = document.createElement("div");
16+
document.body.appendChild(container);
17+
});
18+
19+
afterEach(() => {
20+
// cleanup on exiting
21+
unmountComponentAtNode(container);
22+
container.remove();
23+
container = null;
24+
});
25+
// Unit test
26+
it("DropAndFetch component renders correctly ", () => {
27+
ReactDOM.render(<DropAndFetch
28+
/>, container);
29+
console.log(container.textContent);
30+
expect(container.textContent).toMatch('Upload Files');
31+
});
32+
// Integration test
33+
it("DropZone component inside DropAndFetch renders correctly", () =>{
34+
ReactDOM.render(<DropAndFetch
35+
/>, container);
36+
//Renders dropzone icon
37+
expect(container.querySelector("svg")).toBeInTheDocument();
38+
});
39+
})
40+
41+
describe('pageOne dropAndFetch: fetch correctly', () =>{
42+
let container = null;
43+
beforeEach(() => {
44+
// setup a DOM element as a render target
45+
container = document.createElement("div");
46+
document.body.appendChild(container);
47+
//fetch.resetMocks();
48+
});
49+
50+
afterEach(() => {
51+
// cleanup on exiting
52+
unmountComponentAtNode(container);
53+
container.remove();
54+
container = null;
55+
});
56+
57+
58+
it('UploadPDDL fetch works correctly', async () =>{
59+
const fakevfg = {vfg: 'correct'};
60+
global.fetch = jest.fn(() =>
61+
Promise.resolve({
62+
json: () => Promise.resolve(fakevfg)
63+
})
64+
);
65+
66+
React.useState = jest.fn()
67+
.mockReturnValueOnce([{domain: '',problem:'',animation:''},{}])
68+
.mockReturnValueOnce([false, ()=>{}])
69+
.mockReturnValueOnce([false, ()=>{}]);
70+
71+
const handleStore = (content) => {
72+
expect(content).toMatch(JSON.stringify({vfg: 'correct'}));
73+
}
74+
75+
// Use the asynchronous version of act to apply resolved promises
76+
await act(async () => {
77+
render(<DropAndFetch onStore={handleStore} newURL={''}/>, container);
78+
});
79+
80+
container.querySelector("button[class~='MuiButton-containedPrimary']").click();
81+
global.fetch.mockRestore();
82+
})
83+
})
84+
85+

tests/dropZone.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import DropZone from './dropZone';
4+
5+
6+
it("Renders Correctly ", () => {
7+
const div = document.createElement("div");
8+
ReactDOM.render(<DropZone
9+
/>, div);
10+
ReactDOM.unmountComponentAtNode(div);
11+
});

tests/pageTwo.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import ReactDOM, {render, unmountComponentAtNode} from 'react-dom';
3+
import PageTwo from './index';
4+
5+
describe('pageTwo: rendering correctly', () =>{
6+
7+
let container = null;
8+
beforeEach(() => {
9+
// setup a DOM element as a render target
10+
container = document.createElement("div");
11+
document.body.appendChild(container);
12+
});
13+
14+
afterEach(() => {
15+
// cleanup on exiting
16+
unmountComponentAtNode(container);
17+
container.remove();
18+
container = null;
19+
});
20+
// Unit test
21+
it("DropAndFetch component renders correctly ", () => {
22+
ReactDOM.render(<PageTwo
23+
/>, container);
24+
expect(container.textContent).toMatch('Drag and drop a file here');
25+
});
26+
})

tests/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
automated tests

0 commit comments

Comments
 (0)