Skip to content

Commit 54d3931

Browse files
committed
V:: New tests
1 parent ecabdb5 commit 54d3931

File tree

13 files changed

+168
-50
lines changed

13 files changed

+168
-50
lines changed

viewer/cypress/integration/initial_screen.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import { getByCustomClass, getByCustomId, haveCustomClass, hexToRGB, notHaveCustomClass, renderViewer } from "../utils";
1+
import { getByCustomId, haveCustomClass, hexToRGB, notHaveCustomClass, renderViewer } from "../utils";
2+
import { initialScreenShouldBeVisible } from "../shared";
23

34
describe.only('Initial screen', () => {
45
before(() => cy.visit('/'));
56

67
beforeEach(renderViewer);
78

89
it('Initial screen is visible', () => {
9-
cy.contains("DjVu.js Viewer").should('be.visible');
10-
cy.contains("powered with DjVu.js").should('be.visible');
11-
// getByCustomClass('help_button').its('length').should('eq', 2);
12-
// getByCustomClass('options_button').its('length').should('eq', 2);
13-
getByCustomClass('help_button').should('be.visible');
14-
getByCustomClass('options_button').should('be.visible');
10+
initialScreenShouldBeVisible();
1511
});
1612

1713
it('Dark and white theme', () => {

viewer/cypress/integration/menu.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { customClass, customId, loadDocument, renderViewer } from "../utils";
2+
import { helpWindowShouldBeOpen, initialScreenShouldBeVisible, optionsWindowShouldBeOpen } from "../shared";
3+
4+
const menuShouldNotBeVisible = () => cy.get(customId('menu')).should('not.be.visible');
5+
6+
describe('Document menu opens and closes', () => {
7+
before(() => {
8+
cy.visit('/');
9+
renderViewer();
10+
});
11+
12+
beforeEach(loadDocument);
13+
14+
it('Menu opens and closes via menu button', () => {
15+
cy.contains("Menu").should('not.be.visible');
16+
cy.get(customId('menu_button')).click();
17+
cy.contains("Menu").should('be.visible');
18+
cy.get(customId('menu_button')).click();
19+
menuShouldNotBeVisible();
20+
});
21+
22+
it('Menu can be closed with the close button', () => {
23+
cy.get(customId('menu_button')).click().wait(500);
24+
cy.get(customId('menu')).should('be.visible')
25+
.find(customClass('close_button')).first().click();
26+
menuShouldNotBeVisible();
27+
});
28+
});
29+
30+
describe('Document menu controls', () => {
31+
before(() => {
32+
cy.visit('/');
33+
renderViewer();
34+
});
35+
36+
beforeEach(() => {
37+
loadDocument();
38+
cy.get(customId('menu_button')).click().wait(500);
39+
});
40+
41+
it('Options inside menu and menu closes', () => {
42+
cy.contains('Options').click();
43+
optionsWindowShouldBeOpen();
44+
menuShouldNotBeVisible();
45+
});
46+
47+
it('Help button inside menu', () => {
48+
cy.contains('About').click();
49+
helpWindowShouldBeOpen();
50+
menuShouldNotBeVisible();
51+
});
52+
53+
it('Print document', () => {
54+
cy.contains('Print').click();
55+
menuShouldNotBeVisible();
56+
cy.get(customClass('modal_window')).within(() => {
57+
cy.contains('Pages must be rendered before printing').should('be.visible');
58+
cy.contains('From').should('be.visible');
59+
cy.contains('to').should('be.visible');
60+
cy.contains('Prepare pages for printing').click();
61+
});
62+
63+
cy.contains('Prepare pages for printing').should('not.exist');
64+
cy.get(customClass('modal_window'))
65+
.contains('Preparing pages for printing...').should('be.visible');
66+
});
67+
68+
it('Close document', () => {
69+
cy.contains('test_document').should('be.visible');
70+
cy.contains('Close').click();
71+
cy.get(customId('menu')).should('not.exist');
72+
initialScreenShouldBeVisible();
73+
});
74+
});
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { customClass, customId, renderViewer } from "../utils";
2+
import { closeModalWindow, helpWindowShouldBeOpen, optionsWindowShouldBeOpen } from "../shared";
23

34
describe('Modal windows', () => {
45
before(() => cy.visit('/'));
@@ -13,26 +14,17 @@ describe('Modal windows', () => {
1314

1415
it('The close button closes the modal window', () => {
1516
cy.get(customClass('help_button')).click();
16-
cy.get(customClass('modal_window')).as('modal_window').should('be.visible')
17-
.find(customClass('close_button')).click();
17+
closeModalWindow();
1818
cy.get("@modal_window").should('not.exist');
1919
});
2020

2121
it('Options window', () => {
2222
cy.get(customClass('options_button')).click();
23-
cy.get(customClass('modal_window')).should('be.visible').within(() => {
24-
cy.contains('Options');
25-
cy.contains('Language');
26-
cy.contains('Color theme');
27-
});
23+
optionsWindowShouldBeOpen();
2824
});
2925

3026
it('Help window', () => {
3127
cy.get(customClass('help_button')).click();
32-
cy.get(customClass('modal_window')).should('be.visible').within(() => {
33-
cy.contains('DjVu.js Viewer');
34-
cy.contains('Hotkeys');
35-
cy.contains('Controls');
36-
});
28+
helpWindowShouldBeOpen();
3729
});
3830
});

viewer/cypress/integration/other_tests.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,4 @@ describe('Full page mode', () => {
1919
check('be.lessThan');
2020
})
2121
});
22-
});
23-
24-
describe('Work with a document', () => {
25-
before(() => {
26-
cy.visit('/');
27-
renderViewer();
28-
});
29-
30-
beforeEach(() => {
31-
cy.clearLocalStorage();
32-
cy.window().then(win => {
33-
win.viewer.loadDocumentByUrl('DjVu3Spec.djvu', {
34-
name: "My test document",
35-
locale: 'en',
36-
});
37-
});
38-
});
39-
40-
it('Go to the next/previous page', () => {
41-
cy.contains('1 / 71').next('svg').click();
42-
cy.contains('2 / 71').prev('svg').click();
43-
cy.contains('1 / 71').prev('svg').click();
44-
cy.contains('71 / 71').next('svg').click();
45-
cy.contains('1 / 71');
46-
});
4722
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { customId, loadDocument, renderViewer } from "../utils";
2+
3+
describe('Toolbar controls', () => {
4+
before(() => {
5+
cy.visit('/');
6+
renderViewer();
7+
});
8+
9+
beforeEach(loadDocument);
10+
11+
it('Pin/Unpin toolbar', () => {
12+
cy.get(customId('toolbar')).should('be.visible');
13+
cy.get(customId('pin_button')).click();
14+
cy.get(customId('toolbar')).trigger('mouseout').wait(500);
15+
cy.get(customId('toolbar')).should('not.be.visible');
16+
cy.get(customId('root')).trigger('mouseover', 'bottom');
17+
cy.get(customId('toolbar')).should('be.visible');
18+
cy.get(customId('pin_button')).click();
19+
cy.get(customId('toolbar')).trigger('mouseout').wait(500);
20+
cy.get(customId('toolbar')).should('be.visible');
21+
});
22+
23+
it('Contents button works', () => {
24+
cy.contains("Contents").should('be.visible');
25+
cy.get(customId('contents_button')).click().wait(500);
26+
cy.contains("Contents").should('not.be.visible');
27+
cy.get(customId('contents_button')).click();
28+
cy.contains("Contents").should('be.visible');
29+
});
30+
31+
it('Go to the next/previous page', () => {
32+
cy.contains('1 / 71').next('svg').click();
33+
cy.contains('2 / 71').prev('svg').click();
34+
cy.contains('1 / 71').prev('svg').click();
35+
cy.contains('71 / 71').next('svg').click();
36+
cy.contains('1 / 71');
37+
});
38+
});

viewer/cypress/shared.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { customClass } from "./utils";
2+
3+
export function helpWindowShouldBeOpen() {
4+
cy.get(customClass('modal_window')).should('be.visible').within(() => {
5+
cy.contains('DjVu.js Viewer');
6+
cy.contains('Hotkeys');
7+
cy.contains('Controls');
8+
});
9+
}
10+
11+
export function optionsWindowShouldBeOpen() {
12+
cy.get(customClass('modal_window')).should('be.visible').within(() => {
13+
cy.contains('Options');
14+
cy.contains('Language');
15+
cy.contains('Color theme');
16+
});
17+
}
18+
19+
export function closeModalWindow() {
20+
cy.get(customClass('modal_window')).as('modal_window').should('be.visible')
21+
.find(customClass('close_button')).click();
22+
}
23+
24+
export function initialScreenShouldBeVisible() {
25+
cy.contains("DjVu.js Viewer").should('be.visible');
26+
cy.contains("powered with DjVu.js").should('be.visible');
27+
cy.get(customClass('help_button')).should('be.visible');
28+
cy.get(customClass('options_button')).should('be.visible');
29+
}

viewer/cypress/utils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ export const renderViewer = () => {
2929
win.viewer = new win.DjVu.Viewer({ language: 'en', theme: 'light' });
3030
win.viewer.render(win.document.getElementById('root'));
3131
});
32-
};
32+
};
33+
34+
export function loadDocument() {
35+
cy.clearLocalStorage();
36+
cy.window().then(win => {
37+
win.viewer.loadDocumentByUrl('DjVu3Spec.djvu', {
38+
name: "test_document",
39+
locale: 'en',
40+
});
41+
});
42+
}

viewer/public/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626
margin: 0;
2727
padding: 0;
2828
font-family: sans-serif;
29+
background: repeating-linear-gradient(135deg, #5aa0fa, #ffffff 50%);
2930
}
3031

3132
#root, #root2 {
3233
box-sizing: border-box;
3334
width: 80%;
34-
padding: 1em;
35+
padding: 2px;
3536
height: 90vh;
3637
margin: 5vh auto;
3738
box-shadow: 0 0 1px gray;
39+
background: #b0c093;
3840
}
3941
</style>
4042
<script id="djvu_js_lib" src="%PUBLIC_URL%/tmp/djvu.js"></script>

viewer/src/components/Menu.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default ({ isOpened, onClose }) => {
106106
const closeHandler = onClose;
107107

108108
return (
109-
<Root $opened={isOpened}>
109+
<Root $opened={isOpened} data-djvujs-id="menu">
110110
<Header>
111111
<span>{t('Menu')}</span>
112112
<CloseButton onClick={closeHandler} />

viewer/src/components/Toolbar/ContentsButton.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default () => {
2020
<Root
2121
as={isOpened ? IoListCircleSharp : IoListCircleOutline}
2222
onClick={() => dispatch({ type: ActionTypes.TOGGLE_CONTENTS })}
23+
data-djvujs-id="contents_button"
2324
/>
2425
);
2526
}

0 commit comments

Comments
 (0)