Skip to content

Commit 81d1cf7

Browse files
authored
Adding some tests with cypress (#1)
1 parent 12e2eea commit 81d1cf7

File tree

12 files changed

+18521
-16294
lines changed

12 files changed

+18521
-16294
lines changed

.github/workflows/run-tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run Tests
2+
on: [push, pull_request]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v3
8+
- uses: actions/setup-node@v3
9+
with:
10+
node-version: "18"
11+
12+
- name: Setup PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: "8.3"
16+
17+
- name: Install composer dependencies
18+
run: composer install --no-interaction
19+
20+
- name: Install npm dependencies
21+
run: npm ci
22+
23+
- name: Run tests
24+
run: npm run test

cypress.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
screenshotOnRunFailure: false,
5+
video: false,
6+
fixturesFolder: 'tests/cypress/fixtures',
7+
screenshotsFolder: 'tests/cypress/screenshots',
8+
videosFolder: 'tests/cypress/videos',
9+
e2e: {
10+
// We've imported your old cypress plugins here.
11+
// You may want to clean this up later by importing these.
12+
setupNodeEvents(on, config) {
13+
return require('./tests/cypress/plugins/index.js')(on, config)
14+
},
15+
excludeSpecPattern: '*.html',
16+
specPattern: 'tests/cypress/integration/**/*.cy.{js,jsx,ts,tsx}',
17+
supportFile: 'tests/cypress/support/index.js',
18+
},
19+
})

package-lock.json

Lines changed: 18295 additions & 16264 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
{
2-
"name": "paver",
3-
"version": "0.0.1",
4-
"description": "Block based drag and drop editor made with Alpine.js.",
5-
"scripts": {
6-
"test": "echo \"Error: no test specified\" && exit 1"
7-
},
8-
"repository": {
9-
"type": "git",
10-
"url": "git+https://github.com/paver/paver.git"
11-
},
12-
"keywords": [],
13-
"author": "",
14-
"license": "ISC",
15-
"bugs": {
16-
"url": "https://github.com/paver/paver/issues"
17-
},
18-
"homepage": "https://github.com/paver/paver#readme",
19-
"devDependencies": {
20-
"laravel-mix": "^6.0.49",
21-
"postcss": "^8.4.41",
22-
"postcss-import": "^16.1.0",
23-
"postcss-prefixer": "^3.0.0"
24-
},
25-
"dependencies": {
26-
"@alpinejs/morph": "^3.14.1",
27-
"alpinejs": "^3.14.1",
28-
"postcss-nested": "^6.0.1",
29-
"sortablejs": "^1.15.2",
30-
"tippy.js": "^6.3.7"
31-
}
2+
"name": "paver",
3+
"version": "0.0.1",
4+
"description": "Block based drag and drop editor made with Alpine.js.",
5+
"scripts": {
6+
"start-server": "php -S localhost:8000 -t ./tests/localhost",
7+
"stop-server": "lsof -t -i:8000 | xargs kill -9",
8+
"cypress:open": "cypress open",
9+
"cypress:run": "cypress run --headless",
10+
"test": "npm run start-server & npm run cypress:run && npm run stop-server"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/paver/paver.git"
15+
},
16+
"keywords": [],
17+
"author": "",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/paver/paver/issues"
21+
},
22+
"homepage": "https://github.com/paver/paver#readme",
23+
"devDependencies": {
24+
"cypress": "^13.14.1",
25+
"laravel-mix": "^6.0.49",
26+
"postcss": "^8.4.41",
27+
"postcss-import": "^16.1.0",
28+
"postcss-prefixer": "^3.0.0"
29+
},
30+
"dependencies": {
31+
"@alpinejs/morph": "^3.14.1",
32+
"alpinejs": "^3.14.1",
33+
"postcss-nested": "^6.0.1",
34+
"sortablejs": "^1.15.2",
35+
"tippy.js": "^6.3.7"
36+
}
3237
}
Lines changed: 5 additions & 0 deletions
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
beforeEach(() => {
2+
cy.visit('http://localhost:8000/?content=1')
3+
})
4+
5+
it('renders the editor block in the frame', () => {
6+
cy.getIframeBody('.paver__editor').within(() => {
7+
cy.get('.paver__editor-root').eq(0).contains('This is an example')
8+
})
9+
})
10+
11+
it('can enter a block edit state', () => {
12+
cy.getIframeBody('.paver__editor').within(() => {
13+
cy.wait(100).get('.paver__block-toolbar button').eq(1).click({force: true})
14+
})
15+
16+
cy.get('.paver__component-sidebar').should('be.visible')
17+
})
18+
19+
it('can modify a block', () => {
20+
cy.getIframeBody('.paver__editor').within(() => {
21+
cy.wait(200).get('.paver__block-toolbar button').eq(1).click({force: true})
22+
})
23+
24+
cy.get('.paver__component-sidebar').should('be.visible')
25+
cy.get('.paver__component-sidebar').find('.paver__option input').clear().type('John Smith')
26+
27+
cy.getIframeBody('.paver__editor').within(() => {
28+
cy.get('.paver__editor-root').eq(0).contains('John Smith')
29+
})
30+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
beforeEach(() => {
2+
cy.visit('http://localhost:8000')
3+
})
4+
5+
it('renders the editor', () => {
6+
cy.get('.paver__container').should('be.visible')
7+
cy.get('.paver__editor').should('be.visible')
8+
cy.get('.paver__sidebar').should('be.visible')
9+
})
10+
11+
it('renders the editor frame', () => {
12+
cy.getIframeBody('.paver__editor').within(() => {
13+
cy.get('.paver__editor-root').eq(0).should('be.visible')
14+
cy.get('.paver__editor-frame').eq(0).should('be.visible')
15+
})
16+
})

tests/cypress/plugins/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
module.exports = (on, config) => {
19+
// `on` is used to hook into various events Cypress emits
20+
// `config` is the resolved Cypress config
21+
}

tests/cypress/support/commands.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Cypress.Commands.add('getIframeBody', (iframeSelector) => {
2+
return cy
3+
.get(iframeSelector)
4+
.its('0.contentDocument.body')
5+
.should('not.be.empty')
6+
.then(cy.wrap)
7+
})

tests/cypress/support/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './commands'

0 commit comments

Comments
 (0)