Skip to content

Commit b9ce4db

Browse files
committed
WIP e2e tests
1 parent e362680 commit b9ce4db

File tree

5 files changed

+157
-4
lines changed

5 files changed

+157
-4
lines changed

cypress/integration/menu_spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import baseSelectors from '../fixtures/selectors.json';
2+
3+
const selector = {
4+
caseDefault: '[data-cy="case-default"]',
5+
caseExpandDown: '[data-cy="case-expand-down"]',
6+
scrollContainer: '[data-cy="scroll-container"]',
7+
};
8+
//
9+
// const viewport = ['macbook-15', 'iphone-6'];
10+
11+
Cypress.Screenshot.defaults({
12+
screenshotOnRunFailure: false,
13+
});
14+
15+
describe('Menus', () => {
16+
before(function() {
17+
cy.visit('http://localhost:8000/cypress-menu-tests');
18+
});
19+
20+
it('test page renders successfully', () => {
21+
cy.get('h1').should('contain', 'Test Page for React-Select Menus');
22+
});
23+
24+
describe('Inside scroll containers', () => {
25+
describe('by default', () => {
26+
it('menu should be visible when select is clicked', () => {
27+
cy.get(selector.caseDefault)
28+
.find('.react-select__control')
29+
.click()
30+
.get(selector.caseDefault)
31+
.find(baseSelectors.menu)
32+
.should('be.visible');
33+
});
34+
});
35+
36+
describe('At bottom of container', () => {
37+
it('menu should be visible when select is clicked', () => {
38+
cy.get(selector.caseExpandDown)
39+
.find('.react-select__control')
40+
.click()
41+
.get(selector.caseExpandDown)
42+
.find(baseSelectors.menu)
43+
.should('be.visible');
44+
});
45+
46+
it('scroll container should expland & scroll to bottom', () => {
47+
cy.get(selector.caseExpandDown)
48+
.find(selector.scrollContainer)
49+
.then(scrollContainer => {
50+
console.log(scrollContainer[0].scrollHeight);
51+
const originalHeight = scrollContainer[0].scrollHeight;
52+
cy.get(selector.caseExpandDown)
53+
.find('.react-select__control')
54+
.click()
55+
.then(() => {
56+
cy.get(selector.caseExpandDown)
57+
.find(selector.scrollContainer)
58+
.its('scrollHeight')
59+
.should('be.gt', originalHeight);
60+
});
61+
});
62+
});
63+
});
64+
});
65+
});

docs/App/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import Section from './Section';
2020
import PageNav from './PageNav';
2121
import Tests from '../Tests';
22+
import TestsMenu from '../TestsMenu';
2223

2324
const sections = [
2425
{ label: 'Home', path: '/home' },
@@ -37,6 +38,7 @@ export default class App extends Component<*> {
3738
<BrowserRouter>
3839
<Switch>
3940
<Route exact path="/cypress-tests" component={Tests} />
41+
<Route exact path="/cypress-menu-tests" component={TestsMenu} />
4042
<Route>
4143
<div>
4244
<Header>

docs/TestsMenu.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// @flow
2+
3+
import * as React from 'react';
4+
import Select from '../src';
5+
import { stateOptions } from './data';
6+
import { H1, H2, Note, ScrollContainer } from './styled-components';
7+
8+
const defaultSelectProps = {
9+
maxMenuHeight: 250,
10+
classNamePrefix: 'react-select',
11+
placeholder: 'Choose a state…',
12+
options: stateOptions,
13+
};
14+
15+
export default function TestsMenu() {
16+
return (
17+
<div
18+
style={{
19+
margin: 'auto',
20+
maxWidth: 440,
21+
padding: 20,
22+
}}
23+
>
24+
<H1>Test Page for React-Select Menus</H1>
25+
<H2>Inside scroll containers</H2>
26+
27+
<div data-cy="case-default">
28+
<h3>Default, plenty of height</h3>
29+
<ScrollContainer height={defaultSelectProps.maxMenuHeight + 100}>
30+
<Select {...defaultSelectProps} />
31+
</ScrollContainer>
32+
<Note>
33+
Nothing special going on here, just the base case of opening a menu in
34+
a scroll container
35+
</Note>
36+
</div>
37+
38+
<div data-cy="case-expand-down">
39+
<h3>Expand and Scroll Down</h3>
40+
<ScrollContainer height={400}>
41+
<div style={{ height: 300 }} />
42+
<Select {...defaultSelectProps} />
43+
</ScrollContainer>
44+
<Note>
45+
If the menu doesn’t have enough room to open down, by default the
46+
container should expand down
47+
</Note>
48+
</div>
49+
</div>
50+
);
51+
}

docs/styled-components.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import React from 'react';
3+
import * as React from 'react';
44

55
import SyntaxHighlighter, {
66
registerLanguage,
@@ -49,13 +49,19 @@ export const Note = ({ Tag = 'div', ...props }: { Tag?: string }) => (
4949
export const H1 = (props: any) => <h1 css={{ marginTop: 0 }} {...props} />;
5050
export const H2 = (props: any) => <h2 css={{ marginTop: '2em' }} {...props} />;
5151

52-
export const ColorSample = ({ name, color }: { color: string, name: string }) => (
52+
export const ColorSample = ({
53+
name,
54+
color,
55+
}: {
56+
color: string,
57+
name: string,
58+
}) => (
5359
<div
5460
css={{
5561
display: 'inline-flex',
5662
marginBottom: '0.5em',
5763
alignItems: 'center',
58-
minWidth: '10em'
64+
minWidth: '10em',
5965
}}
6066
>
6167
<span
@@ -66,13 +72,41 @@ export const ColorSample = ({ name, color }: { color: string, name: string }) =>
6672
borderRadius: 3,
6773
width: '1em',
6874
height: '1em',
69-
backgroundColor: color
75+
backgroundColor: color,
7076
}}
7177
/>
7278
<Code>{name}</Code>
7379
</div>
7480
);
7581

82+
type ScrollContainerProps = {
83+
children: React.Node,
84+
height?: number | string,
85+
width?: number | string,
86+
};
87+
88+
export const ScrollContainer = ({
89+
children,
90+
height,
91+
width,
92+
}: ScrollContainerProps) => {
93+
return (
94+
<div
95+
data-cy="scroll-container"
96+
css={{
97+
overflow: 'scroll',
98+
height: height || 'auto',
99+
width: width || '100%',
100+
border: '1px solid hsl(0, 0%, 40%)',
101+
position: 'relative',
102+
boxSizing: 'border-box',
103+
}}
104+
>
105+
{children}
106+
</div>
107+
);
108+
};
109+
76110
// ==============================
77111
// Code
78112
// ==============================

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"test": "npm run test:jest && npm run test:cypress",
101101
"test:jest": "jest --coverage",
102102
"e2e": "concurrently --kill-others --success=first --names 'SERVER,E2E' 'yarn start --progress=false --no-info' 'yarn test:cypress'",
103+
"e2e-watch": "concurrently --kill-others --success=first --names 'SERVER,E2E' 'yarn start --progress=false --no-info' 'yarn test:cypress-watch'",
103104
"test:cypress": "cypress run --spec ./cypress/integration/select_spec.js",
104105
"test:cypress-watch": "node ./node_modules/.bin/cypress open",
105106
"precommit": "flow check && lint-staged"

0 commit comments

Comments
 (0)