Skip to content

Commit 86a4c4f

Browse files
updated
1 parent 81cdca7 commit 86a4c4f

File tree

10 files changed

+223
-0
lines changed

10 files changed

+223
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GENERATE_SOURCEMAP=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cypress
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/// <reference types="cypress" />
2+
3+
context('Querying', () => {
4+
beforeEach(() => {
5+
cy.visit('https://example.cypress.io/commands/querying')
6+
})
7+
8+
// The most commonly used query is 'cy.get()', you can
9+
// think of this like the '$' in jQuery
10+
11+
it('cy.get() - query DOM elements', () => {
12+
// https://on.cypress.io/get
13+
14+
cy.get('#query-btn').should('contain', 'Button')
15+
16+
cy.get('.query-btn').should('contain', 'Button')
17+
18+
cy.get('#querying .well>button:first').should('contain', 'Button')
19+
// ↲
20+
// Use CSS selectors just like jQuery
21+
22+
cy.get('[data-test-id="test-example"]').should('have.class', 'example')
23+
24+
// 'cy.get()' yields jQuery object, you can get its attribute
25+
// by invoking `.attr()` method
26+
cy.get('[data-test-id="test-example"]')
27+
.invoke('attr', 'data-test-id')
28+
.should('equal', 'test-example')
29+
30+
// or you can get element's CSS property
31+
cy.get('[data-test-id="test-example"]')
32+
.invoke('css', 'position')
33+
.should('equal', 'static')
34+
35+
// or use assertions directly during 'cy.get()'
36+
// https://on.cypress.io/assertions
37+
cy.get('[data-test-id="test-example"]')
38+
.should('have.attr', 'data-test-id', 'test-example')
39+
.and('have.css', 'position', 'static')
40+
})
41+
42+
it('cy.contains() - query DOM elements with matching content', () => {
43+
// https://on.cypress.io/contains
44+
cy.get('.query-list')
45+
.contains('bananas')
46+
.should('have.class', 'third')
47+
48+
// we can pass a regexp to `.contains()`
49+
cy.get('.query-list')
50+
.contains(/^b\w+/)
51+
.should('have.class', 'third')
52+
53+
cy.get('.query-list')
54+
.contains('apples')
55+
.should('have.class', 'first')
56+
57+
// passing a selector to contains will
58+
// yield the selector containing the text
59+
cy.get('#querying')
60+
.contains('ul', 'oranges')
61+
.should('have.class', 'query-list')
62+
63+
cy.get('.query-button')
64+
.contains('Save Form')
65+
.should('have.class', 'btn')
66+
})
67+
68+
it('.within() - query DOM elements within a specific element', () => {
69+
// https://on.cypress.io/within
70+
cy.get('.query-form').within(() => {
71+
cy.get('input:first').should('have.attr', 'placeholder', 'Email')
72+
cy.get('input:last').should('have.attr', 'placeholder', 'Password')
73+
})
74+
})
75+
76+
it('cy.root() - query the root DOM element', () => {
77+
// https://on.cypress.io/root
78+
79+
// By default, root is the document
80+
cy.root().should('match', 'html')
81+
82+
cy.get('.query-ul').within(() => {
83+
// In this within, the root is now the ul DOM element
84+
cy.root().should('have.class', 'query-ul')
85+
})
86+
})
87+
88+
it('best practices - selecting elements', () => {
89+
// https://on.cypress.io/best-practices#Selecting-Elements
90+
cy.get('[data-cy=best-practices-selecting-elements]').within(() => {
91+
// Worst - too generic, no context
92+
cy.get('button').click()
93+
94+
// Bad. Coupled to styling. Highly subject to change.
95+
cy.get('.btn.btn-large').click()
96+
97+
// Average. Coupled to the `name` attribute which has HTML semantics.
98+
cy.get('[name=submission]').click()
99+
100+
// Better. But still coupled to styling or JS event listeners.
101+
cy.get('#main').click()
102+
103+
// Slightly better. Uses an ID but also ensures the element
104+
// has an ARIA role attribute
105+
cy.get('#main[role=button]').click()
106+
107+
// Much better. But still coupled to text content that may change.
108+
cy.contains('Submit').click()
109+
110+
// Best. Insulated from all changes.
111+
cy.get('[data-cy=submit]').click()
112+
})
113+
})
114+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/// <reference types="cypress" />
2+
3+
context('Viewport', () => {
4+
beforeEach(() => {
5+
cy.visit('https://example.cypress.io/commands/viewport')
6+
})
7+
8+
it('cy.viewport() - set the viewport size and dimension', () => {
9+
// https://on.cypress.io/viewport
10+
11+
cy.get('#navbar').should('be.visible')
12+
cy.viewport(320, 480)
13+
14+
// the navbar should have collapse since our screen is smaller
15+
cy.get('#navbar').should('not.be.visible')
16+
cy.get('.navbar-toggle').should('be.visible').click()
17+
cy.get('.nav').find('a').should('be.visible')
18+
19+
// lets see what our app looks like on a super large screen
20+
cy.viewport(2999, 2999)
21+
22+
// cy.viewport() accepts a set of preset sizes
23+
// to easily set the screen to a device's width and height
24+
25+
// We added a cy.wait() between each viewport change so you can see
26+
// the change otherwise it is a little too fast to see :)
27+
28+
cy.viewport('macbook-15')
29+
cy.wait(200)
30+
cy.viewport('macbook-13')
31+
cy.wait(200)
32+
cy.viewport('macbook-11')
33+
cy.wait(200)
34+
cy.viewport('ipad-2')
35+
cy.wait(200)
36+
cy.viewport('ipad-mini')
37+
cy.wait(200)
38+
cy.viewport('iphone-6+')
39+
cy.wait(200)
40+
cy.viewport('iphone-6')
41+
cy.wait(200)
42+
cy.viewport('iphone-5')
43+
cy.wait(200)
44+
cy.viewport('iphone-4')
45+
cy.wait(200)
46+
cy.viewport('iphone-3')
47+
cy.wait(200)
48+
49+
// cy.viewport() accepts an orientation for all presets
50+
// the default orientation is 'portrait'
51+
cy.viewport('ipad-2', 'portrait')
52+
cy.wait(200)
53+
cy.viewport('iphone-4', 'landscape')
54+
cy.wait(200)
55+
56+
// The viewport will be reset back to the default dimensions
57+
// in between tests (the default can be set in cypress.json)
58+
})
59+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createSelector } from '@reduxjs/toolkit';
2+
3+
import { RootState } from 'types';
4+
import { initialState } from './slice';
5+
6+
const selectDomain = (state: RootState) => state.{{ camelCase ComponentName }} || initialState;
7+
8+
export const select{{ properCase ComponentName }} = createSelector(
9+
[selectDomain],
10+
{{ camelCase ComponentName }}State => {{ camelCase ComponentName }}State,
11+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Asynchronously loads the component for HomePage
3+
*/
4+
5+
import { lazyLoad } from 'utils/loadable';
6+
7+
export const HomePage = lazyLoad(
8+
() => import('./index'),
9+
module => module.HomePage,
10+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom/extend-expect';
6+
7+
import 'react-app-polyfill/ie11';
8+
import 'react-app-polyfill/stable';
9+
10+
import 'jest-styled-components';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as utils from '../utils';
2+
3+
describe('theme utils', () => {
4+
it('should get storage item', () => {
5+
utils.saveTheme('system');
6+
expect(utils.getThemeFromStorage()).toBe('system');
7+
});
8+
it('should check system theme', () => {
9+
expect(utils.isSystemDark).toBeUndefined();
10+
});
11+
});

0 commit comments

Comments
 (0)