浏览代码

Merge pull request #5528 from wenzhixin/feature/cypress-test

Feature/cypress test
Dustin Utecht 4 年之前
父节点
当前提交
fb6bc0c8d1

+ 19 - 0
.travis.yml

@@ -9,12 +9,31 @@ jobs:
       node_js:
         - 12
       name: "Lint src and check docs"
+      cache:
+        npm: true
+        directories:
+          - ~/.cache
       script:
         - cd tools
         - git clone --depth=1 https://github.com/wenzhixin/bootstrap-table-examples
         - npm run pre-commit
       if: branch != master AND type = pull_request
 
+    - stage: test
+      language: node_js
+      node_js:
+        - 12
+      name: "Cypress Test"
+      cache:
+        npm: true
+        directories:
+          - ~/.cache
+      script:
+        - git clone --depth=1 https://github.com/wenzhixin/bootstrap-table-examples cypress/html
+        - npm run css:build:src
+        - npm run test
+      if: branch != master AND type = pull_request
+
     - stage: deploy
       name: "Deploy docs"
       language: ruby

+ 4 - 0
cypress.json

@@ -0,0 +1,4 @@
+{
+    "video": false,
+    "screenshot": false
+}

+ 2 - 0
cypress/.gitignore

@@ -0,0 +1,2 @@
+html
+screenshots

+ 27 - 0
cypress/common/options.js

@@ -0,0 +1,27 @@
+module.exports = (theme = '') => {
+  const baseUrl = require('./utils')(theme, 'options')
+
+  describe('Welcome Test', () => {
+    it('Test Custom AJAX', () => {
+      cy.visit(`${baseUrl}table-ajax.html`)
+        .get('.fixed-table-pagination >.pagination-detail').should('have.length', 1)
+        .get('.fixed-table-pagination > .pagination').should('have.length', 1)
+        .get('span.pagination-info').should('contain', '800')
+    })
+
+    it('Test AJAX Options', () => {
+      cy.visit(`${baseUrl}ajax-options.html`)
+        .intercept('GET', '**/json/data1.json').as('ajax')
+        .wait('@ajax')
+        .should(({ request }) => {
+          expect(request.headers).to.have.property('custom-auth-token')
+            .and.eq('custom-auth-token')
+        })
+    })
+
+    it('Test Basic Columns', () => {
+      cy.visit(`${baseUrl}basic-columns.html`)
+        .get('.fixed-table-toolbar .columns').should('exist')
+    })
+  })
+}

+ 4 - 0
cypress/common/utils.js

@@ -0,0 +1,4 @@
+module.exports = (theme, dir) => {
+  return theme ? `./cypress/html/for-test-${theme}.html?url=${dir}/` :
+    `./cypress/html/for-test.html?url=${dir}/`
+}

+ 96 - 0
cypress/common/welcome.js

@@ -0,0 +1,96 @@
+module.exports = (theme = '') => {
+  const baseUrl = require('./utils')(theme, 'welcomes')
+
+  describe('Welcome Test', () => {
+    it('Test From HTML', () => {
+      cy.visit(`${baseUrl}from-html.html`)
+        .get('.bootstrap-table').should('exist')
+        .get('.fixed-table-toolbar > .columns').should('exist')
+        .get('.fixed-table-toolbar > .search').should('exist')
+    })
+
+    it('Test From Data', () => {
+      cy.visit(`${baseUrl}from-data.html`)
+        .get('div.bootstrap-table tbody tr').should('have.length', 6)
+    })
+
+    it('Test From URL', () => {
+      cy.visit(`${baseUrl}from-url.html`)
+        .get('div.bootstrap-table tbody tr').should('have.length', 21)
+    })
+
+    it('Test No Data', () => {
+      cy.visit(`${baseUrl}no-data.html`)
+        .get('div.bootstrap-table').should('exist')
+        .get('tr.no-records-found').should('be.visible')
+    })
+
+    it('Test Modal Table', () => {
+      const html = theme ? `modal-table-${theme}.html` : 'modal-table.html'
+
+      cy.visit(`${baseUrl}${html}`)
+        .get('#button').wait(200).click()
+        .get('.bootstrap-table').should('be.visible')
+        .get('.fixed-table-container').should('have.css', 'height', '345px')
+        .invoke('css', 'padding-bottom').then(str => parseInt(str)).should('be.greaterThan', 0)
+    })
+
+    it('Test Group Columns', () => {
+      cy.visit(`${baseUrl}group-columns.html`)
+        .get('.fixed-table-body thead tr:eq(0) th:eq(0)')
+        .should('have.attr', 'colspan', '2')
+
+      cy.get('.fixed-table-body  thead tr:eq(0) th:eq(1)')
+        .should('have.attr', 'rowspan', '2')
+
+      cy.get('.columns .keep-open > button').click()
+
+      if (theme === 'materialize') {
+        cy.get('.columns input[data-field="name"]').parent().click()
+          .get('.columns input[data-field="price"]').parent().click()
+      } else {
+        cy.get('.columns input[data-field="name"]').click()
+          .get('.columns input[data-field="price"]').click()
+      }
+
+      cy.get('.fixed-table-body thead tr').should('have.length', 1)
+    })
+
+    it('Test Sub Table', () => {
+      cy.visit(`${baseUrl}sub-table.html`)
+        .get('a.detail-icon').click()
+        .get('tr.detail-view a.detail-icon').click()
+        .get('.bootstrap-table').should('have.length', 3)
+    })
+
+    it('Test Multiple Table', () => {
+      cy.visit(`${baseUrl}multiple-table.html`)
+        .get('.bootstrap-table').should('have.length', 4)
+    })
+
+    it('Test Flat Json', () => {
+      cy.visit(`${baseUrl}flat-json.html`)
+        .get('.bootstrap-table tr[data-index="0"] td:eq(1)').should('contain', 768)
+    })
+
+    it('Test Large data', () => {
+      cy.visit(`${baseUrl}large-data.html`)
+        .get('.bootstrap-table').should('exist')
+        .get('#load').click()
+        .get('#total').should('contain', '10000')
+
+      cy.get('#append').click()
+        .get('#total').should('contain', '20000')
+
+      cy.get('#table tr[data-index]').should('have.length', 200)
+    })
+
+    it('Test Vue Component', () => {
+      cy.visit(`${baseUrl}vue-component.html`)
+        .get('.bootstrap-table').should('exist')
+        .get('.fixed-table-toolbar > .columns').should('exist')
+        .get('.fixed-table-toolbar > .search').should('exist')
+        .get('.bootstrap-table tr[data-index]').should('have.length', 6)
+    })
+  })
+}

+ 5 - 0
cypress/fixtures/example.json

@@ -0,0 +1,5 @@
+{
+  "name": "Using fixtures to represent data",
+  "email": "hello@cypress.io",
+  "body": "Fixtures are a great way to mock data for responses to routes"
+}

+ 1 - 0
cypress/integration/options/bootstrap3.js

@@ -0,0 +1 @@
+require('../../common/options')('bootstrap3')

+ 1 - 0
cypress/integration/options/bootstrap5.js

@@ -0,0 +1 @@
+require('../../common/options')('bootstrap5')

+ 1 - 0
cypress/integration/options/bulma.js

@@ -0,0 +1 @@
+require('../../common/options')('bulma')

+ 1 - 0
cypress/integration/options/foundation.js

@@ -0,0 +1 @@
+require('../../common/options')('foundation')

+ 1 - 0
cypress/integration/options/index.js

@@ -0,0 +1 @@
+require('../../common/options')()

+ 1 - 0
cypress/integration/options/materialize.js

@@ -0,0 +1 @@
+require('../../common/options')('materialize')

+ 1 - 0
cypress/integration/options/semantic.js

@@ -0,0 +1 @@
+require('../../common/options')('semantic')

+ 1 - 0
cypress/integration/welcome/bootstrap3.js

@@ -0,0 +1 @@
+require('../../common/welcome')('bootstrap3')

+ 1 - 0
cypress/integration/welcome/bootstrap5.js

@@ -0,0 +1 @@
+require('../../common/welcome')('bootstrap5')

+ 1 - 0
cypress/integration/welcome/bulma.js

@@ -0,0 +1 @@
+require('../../common/welcome')('bulma')

+ 1 - 0
cypress/integration/welcome/foundation.js

@@ -0,0 +1 @@
+require('../../common/welcome')('foundation')

+ 1 - 0
cypress/integration/welcome/index.js

@@ -0,0 +1 @@
+require('../../common/welcome')()

+ 1 - 0
cypress/integration/welcome/materialize.js

@@ -0,0 +1 @@
+require('../../common/welcome')('materialize')

+ 1 - 0
cypress/integration/welcome/semantic.js

@@ -0,0 +1 @@
+require('../../common/welcome')('semantic')

+ 21 - 0
cypress/plugins/index.js

@@ -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 - 0
cypress/support/commands.js

@@ -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 - 0
cypress/support/index.js

@@ -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')

+ 2 - 0
package.json

@@ -15,6 +15,7 @@
     "clean-css-cli": "^5.0.1",
     "core-js": "^3.1.4",
     "cross-env": "^7.0.2",
+    "cypress": "^8.6.0",
     "eslint": "^8.0.1",
     "esm": "^3.2.25",
     "foreach-cli": "^1.8.1",
@@ -40,6 +41,7 @@
     "lint:js": "eslint src",
     "lint:css": "stylelint src/**/*.scss",
     "lint": "run-s lint:*",
+    "test": "cypress run --headless",
     "docs:check:api": "cd tools && node check-api.js",
     "docs:check:locale": "cd tools && node check-locale.js",
     "docs:check": "run-s docs:check:*",