Skip to content

Commit

Permalink
feat(DIST-691): Add cypress functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Lednicky committed Feb 3, 2021
1 parent f158d99 commit a00ee15
Show file tree
Hide file tree
Showing 14 changed files with 574 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ build
node_modules

# tests
e2e/screenshots
cypress/screenshots
cypress/videos
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
"@storybook/addon-links": "^6.1.16",
"@storybook/html": "^6.1.16",
"@typeform/eslint-config": "^3.0.2",
"@types/cypress": "^1.1.3",
"@types/jest": "^26.0.20",
"babel-loader": "^8.2.2",
"commitlint": "^11.0.0",
"cypress": "^6.4.0",
"eslint": "^7.19.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^4.3.8",
"jest": "^26.6.3",
Expand Down
7 changes: 7 additions & 0 deletions packages/embed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ Run unit tests
```bash
yarn test
```

Run functional tests via Cypress

```bash
yarn cy:run # run in background (headless)
yarn cy:open # open cypress UI
```
11 changes: 11 additions & 0 deletions packages/embed/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"chromeWebSecurity": false,
"integrationFolder": "./e2e/spec",
"screenshotsFolder": "./e2e/screenshots",
"baseUrl": "http://localhost:6006/",
"trashAssetsBeforeRuns": true,
"viewportWidth": 1280,
"viewportHeight": 1000,
"animationDistanceThreshold": 2,
"video": false
}
21 changes: 21 additions & 0 deletions packages/embed/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions packages/embed/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions packages/embed/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
9 changes: 9 additions & 0 deletions packages/embed/e2e/spec/popup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Popup', () => {
it('should open popup', () => {
cy.visit('/iframe.html?id=embed-popup--popup&viewMode=story')
cy.get('.typeform-popup').should('not.be.visible')
cy.get('button').click()
cy.get('.typeform-popup').should('be.visible')
cy.get('.typeform-popup iframe').invoke('attr', 'src').should('contain', 'form.typeform.com/to/')
})
})
7 changes: 7 additions & 0 deletions packages/embed/e2e/spec/widget.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('Widget', () => {
it('should display widget', () => {
cy.visit('/iframe.html?id=embed-widget--widget&viewMode=story')
cy.get('.typeform-widget iframe').should('be.visible')
cy.get('.typeform-widget iframe').invoke('attr', 'src').should('contain', 'form.typeform.com/to/')
})
})
8 changes: 8 additions & 0 deletions packages/embed/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"types": ["cypress"]
},
"include": ["../node_modules/cypress", "./**/*.ts"]
}
2 changes: 1 addition & 1 deletion packages/embed/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"testMatch": ["**/*.spec.(ts|tsx)"]
"testMatch": ["**/src/**/*.spec.(ts|tsx)"]
}
4 changes: 3 additions & 1 deletion packages/embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"dev": "tsc -w",
"demo": "cd ../embed-kitchen-sink && yarn dev",
"lint": "eslint src --ext .js,.ts,.jsx,.tsx --max-warnings=0",
"test": "jest"
"test": "jest",
"cy:run": "yarn cypress run --browser chrome --headless",
"cy:open": "yarn cypress open"
}
}
3 changes: 1 addition & 2 deletions packages/embed/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
"typeRoots": ["./types", "./node_modules/@types"],
"types": ["@types/jest", "node"]
},
"exclude": ["src/*.spec.ts"],
"include": ["src/*.ts"]
"include": ["src/**/*.ts*"]
}
Loading

0 comments on commit a00ee15

Please sign in to comment.