Skip to content

Commit b143b3e

Browse files
authored
fix: add cypress test skeleton (#186)
1 parent e2abe75 commit b143b3e

File tree

8 files changed

+72
-29
lines changed

8 files changed

+72
-29
lines changed

cypress/fixtures/story.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.storyUrl = 'http://localhost:6096';

cypress/integration/sample.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
describe('SortablePane', () => {
2+
const { storyUrl } = require('../../fixtures/story');
3+
4+
beforeEach(() => {
5+
cy.visit(storyUrl);
6+
});
7+
8+
context('Uncontrolled horizontal', () => {
9+
it('should sort horizontal pane', () => {
10+
selectStory('horizontal');
11+
cy.get('#storybook-preview-iframe').then($iframe => {
12+
const doc = $iframe.contents();
13+
iget(doc, '.pane0').trigger('mousedown', { which: 1 });
14+
iget($iframe.contents(), 'body').trigger('mousemove', { clientX: 200, clientY: 0 });
15+
iget(doc, '.pane0').trigger('mouseup', { force: true });
16+
iget(doc, '.panes div')
17+
.eq(0)
18+
.and('have.css', 'transform')
19+
.and('match', /matrix\(1, 0, 0, 1, 140, 0\)/);
20+
cy.screenshot('horizontal');
21+
});
22+
});
23+
});
24+
});
25+
26+
function iget(doc: JQuery<HTMLElement | Text | Comment>, selector: string) {
27+
return cy.wrap(doc.find(selector));
28+
}
29+
30+
function selectStory(name: string) {
31+
cy.get(`a[data-name="${name}"]`).click();
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
describe('SortablePane', () => {
2+
const { storyUrl } = require('../../fixtures/story');
3+
4+
beforeEach(() => {
5+
cy.visit(storyUrl);
6+
});
7+
8+
context('Uncontrolled vertical', () => {
9+
it('should sort vertical pane', () => {
10+
selectStory('vertical');
11+
cy.get('#storybook-preview-iframe').then($iframe => {
12+
const doc = $iframe.contents();
13+
iget(doc, '.pane0').trigger('mousedown', { which: 1 });
14+
iget($iframe.contents(), 'body').trigger('mousemove', { clientX: 0, clientY: 200 });
15+
iget(doc, '.pane0').trigger('mouseup', { force: true });
16+
iget(doc, '.panes div')
17+
.eq(0)
18+
.and('have.css', 'transform')
19+
.and('match', /matrix\(1, 0, 0, 1, 0, 140\)/);
20+
cy.screenshot('vertical');
21+
});
22+
});
23+
});
24+
});
25+
26+
function iget(doc: JQuery<HTMLElement | Text | Comment>, selector: string) {
27+
return cy.wrap(doc.find(selector));
28+
}
29+
30+
function selectStory(name: string) {
31+
cy.get(`a[data-name="${name}"]`).click();
32+
}

cypress/support/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import './commands'
18-
17+
import './commands';
18+
// import './helper'
1919
// Alternatively you can use CommonJS syntax:
2020
// require('./commands')

stories/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { storiesOf } from '@storybook/react';
33
import './styles.css';
44

55
import SimpleVertical from './simple/vertical';
6-
import SimpleHorizontal from './simple/horizontal.stories';
6+
import SimpleHorizontal from './simple/horizontal';
77

88
import ControlledOrder from './controlled/order';
99
import ControlledSize from './controlled/size';

stories/simple/horizontal.stories.tsx renamed to stories/simple/horizontal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { textStyle, paneStyle } from '../styles';
44

55
export default function SimpleVertical() {
66
const panes = [0, 1, 2].map(key => (
7-
<Pane key={key} defaultSize={{ width: 120, height: '100%' }} style={paneStyle}>
7+
<Pane key={key} className={`pane${key}`} defaultSize={{ width: 120, height: '100%' }} style={paneStyle}>
88
<p style={textStyle}>00{key}</p>
99
</Pane>
1010
));
1111
return (
1212
<div style={{ padding: '10px' }}>
13-
<SortablePane direction="horizontal" margin={20}>
13+
<SortablePane direction="horizontal" margin={20} className="panes">
1414
{panes}
1515
</SortablePane>
1616
</div>

stories/simple/vertical.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { textStyle, paneStyle } from '../styles';
44

55
export default function SimpleVertical() {
66
const panes = [0, 1, 2].map(key => (
7-
<Pane key={key} defaultSize={{ width: '100%', height: 120 }} style={paneStyle}>
7+
<Pane key={key} className={`pane${key}`} defaultSize={{ width: '100%', height: 120 }} style={paneStyle}>
88
<p style={textStyle}>00{key}</p>
99
</Pane>
1010
));
1111
return (
1212
<div style={{ padding: '10px' }}>
13-
<SortablePane direction="vertical" margin={20}>
13+
<SortablePane direction="vertical" margin={20} className="panes">
1414
{panes}
1515
</SortablePane>
1616
</div>

0 commit comments

Comments
 (0)