Skip to content

Commit a15cc20

Browse files
agangladasmeijer
andauthored
test: add e2e tests for header (#321)
Co-authored-by: Stephan Meijer <[email protected]>
1 parent 92ede07 commit a15cc20

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.rts2_cache*
22
.cache
33
.parcel-cache
4-
cypress
4+
cypress/videos
55

66
dist/
77
node_modules/

cypress/e2e/header.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
it('renders Testing Playground Header', () => {
2+
cy.visit('/');
3+
4+
cy.findByRole('heading', {
5+
level: 1,
6+
name: 'Testing Playground mascot Froggy ️ Testing Playground',
7+
}).should('exist');
8+
9+
cy.findByRole('link', {
10+
name: 'Testing Playground mascot Froggy ️ Testing Playground',
11+
})
12+
.should('exist')
13+
.and('have.attr', 'href', '/');
14+
15+
cy.findByRole('button', { name: /playground/i }).should('exist');
16+
cy.findByRole('button', { name: /run/i }).should('exist');
17+
cy.findByRole('button', { name: /settings/i }).should('exist');
18+
cy.findByRole('button', { name: /more info/i }).should('exist');
19+
20+
cy.findByRole('button', { name: /playground/i }).click();
21+
// playground menu shows
22+
cy.findByRole('menuitem', { name: /new/i }).should('exist');
23+
cy.findByRole('menuitem', { name: /save/i }).should('exist');
24+
cy.findByRole('menuitem', { name: /fork/i }).should('exist');
25+
cy.findByRole('menuitem', { name: /share/i }).should('exist');
26+
cy.findByRole('menuitem', { name: /embed/i }).should('exist');
27+
28+
cy.findByRole('button', { name: /settings/i }).click();
29+
// previous menu disappear
30+
cy.findByRole('menuitem', { name: /new/i }).should('not.exist');
31+
cy.findByRole('menuitem', { name: /save/i }).should('not.exist');
32+
cy.findByRole('menuitem', { name: /fork/i }).should('not.exist');
33+
cy.findByRole('menuitem', { name: /share/i }).should('not.exist');
34+
cy.findByRole('menuitem', { name: /embed/i }).should('not.exist');
35+
36+
// settings menu shows
37+
cy.findByLabelText(/auto-run code/i).should('exist');
38+
cy.findByLabelText(/test-id attribute:/i).should('exist');
39+
40+
cy.findByRole('button', { name: /more info/i }).click();
41+
// previous menu disappear
42+
cy.findByLabelText(/auto-run code/i).should('not.be.visible');
43+
cy.findByLabelText(/test-id attribute:/i).should('not.be.visible');
44+
45+
// more info menu shows
46+
cy.findByRole('menuitem', { name: /roadmap/i }).should('exist').and('have.attr', 'href', 'https://github.com/testing-library/testing-playground/projects/1');
47+
cy.findByRole('menuitem', { name: /github/i }).should('exist').and('have.attr', 'href', 'https://github.com/testing-library/testing-playground/issues');
48+
cy.findByRole('menuitem', { name: /support us/i }).should('exist').and('have.attr', 'href', 'https://github.com/sponsors/smeijer');
49+
cy.findByRole('menuitem', { name: /twitter/i }).should('exist').and('have.attr', 'href', 'https://twitter.com/meijer_s');
50+
cy.findByRole('menuitem', { name: /chrome extension/i }).should('exist').and('have.attr', 'href', 'https://chrome.google.com/webstore/detail/testing-playground/hejbmebodbijjdhflfknehhcgaklhano');
51+
cy.findByRole('menuitem', { name: /introduction/i }).should('exist').and('have.attr', 'href', 'https://testing-library.com/docs/dom-testing-library/intro');
52+
cy.findByRole('menuitem', { name: /query priority/i }).should('exist').and('have.attr', 'href', 'https://testing-library.com/docs/guide-which-query');
53+
cy.findByRole('menuitem', { name: /common mistakes/i }).should('exist').and('have.attr', 'href', 'https://kentcdodds.com/blog/common-mistakes-with-react-testing-library');
54+
55+
// click outside
56+
cy.findByRole('button', { name: /more info/i }).parent().click();
57+
// previous menu disappear
58+
cy.findByRole('menuitem', { name: /roadmap/i }).should('not.exist');
59+
cy.findByRole('menuitem', { name: /github/i }).should('not.exist');
60+
cy.findByRole('menuitem', { name: /support us/i }).should('not.exist');
61+
cy.findByRole('menuitem', { name: /twitter/i }).should('not.exist');
62+
cy.findByRole('menuitem', { name: /chrome extension/i }).should('not.exist');
63+
cy.findByRole('menuitem', { name: /introduction/i }).should('not.exist');
64+
cy.findByRole('menuitem', { name: /query priority/i }).should('not.exist');
65+
cy.findByRole('menuitem', { name: /common mistakes/i }).should('not.exist');
66+
});

cypress/e2e/initApp.spec.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
it('renders Testing Playground with an example', () => {
22
cy.visit('/');
33

4-
cy.findByRole('heading', {
5-
level: 1,
6-
name: 'Testing Playground mascot Froggy ️ Testing Playground',
7-
}).should('exist');
8-
9-
cy.findByRole('link', {
10-
name: 'Testing Playground mascot Froggy ️ Testing Playground',
11-
})
12-
.should('exist')
13-
.and('have.attr', 'href', '/');
14-
15-
cy.findByRole('button', { name: 'playground' }).should('exist');
16-
cy.findByRole('button', { name: 'run' }).should('exist');
17-
cy.findByRole('button', { name: 'settings' }).should('exist');
18-
cy.findByRole('button', { name: 'kebab menu' }).should('exist');
19-
204
cy.getMarkupEditor().should('exist');
215

226
cy.getSandboxBody().within(() => {

src/components/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function Header({
156156
</Menu>
157157

158158
<Menu>
159-
<MenuButton title="kebab menu">
159+
<MenuButton title="more info">
160160
<span>
161161
<KebabHorizontalIcon
162162
size={12}

src/components/Settings.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ function Settings({ settings, dispatch }) {
5454
{showTestingLibrary && (
5555
<div>
5656
<h3 className="text-sm font-bold mb-2">Testing-Library</h3>
57-
<label className="text-xs">test-id attribute:</label>
57+
<label htmlFor="test-id" className="text-xs">
58+
test-id attribute:
59+
</label>
5860
<Input
5961
defaultValue={settings.testIdAttribute}
6062
name="testIdAttribute"
63+
id="test-id"
6164
/>
6265
</div>
6366
)}

0 commit comments

Comments
 (0)