浏览代码

Remove cypress and update bootstrap-table

zhixin 5 年之前
父节点
当前提交
cc5a2387c5
共有 4 个文件被更改,包括 92 次插入154 次删除
  1. 0 21
      cypress/plugins/index.js
  2. 0 25
      cypress/support/commands.js
  3. 0 20
      cypress/support/index.js
  4. 92 88
      src/bootstrap-table.js

+ 0 - 21
cypress/plugins/index.js

@@ -1,21 +0,0 @@
-/// <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
-}

+ 0 - 25
cypress/support/commands.js

@@ -1,25 +0,0 @@
-// ***********************************************
-// 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) => { ... })

+ 0 - 20
cypress/support/index.js

@@ -1,20 +0,0 @@
-// ***********************************************************
-// 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')

+ 92 - 88
src/bootstrap-table.js

@@ -527,108 +527,108 @@ class BootstrapTable {
   }
 
   initToolbar () {
+    const opts = this.options
     let html = []
     let timeoutId = 0
     let $keepOpen
     let switchableCount = 0
-    const opts = this.options
 
     if (this.$toolbar.find('.bs-bars').children().length) {
-      $('body').append($(this.options.toolbar))
+      $('body').append($(opts.toolbar))
     }
     this.$toolbar.html('')
 
-    if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
-      $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', this.constants.classes.pull, this.options.toolbarAlign))
+    if (typeof opts.toolbar === 'string' || typeof opts.toolbar === 'object') {
+      $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', this.constants.classes.pull, opts.toolbarAlign))
         .appendTo(this.$toolbar)
-        .append($(this.options.toolbar))
+        .append($(opts.toolbar))
     }
 
     // showColumns, showToggle, showRefresh
     html = [`<div class="${[
       'columns',
-      `columns-${this.options.buttonsAlign}`,
+      `columns-${opts.buttonsAlign}`,
       this.constants.classes.buttonsGroup,
-      `${this.constants.classes.pull}-${this.options.buttonsAlign}`
+      `${this.constants.classes.pull}-${opts.buttonsAlign}`
     ].join(' ')}">`]
 
-    if (typeof this.options.icons === 'string') {
-      this.options.icons = Utils.calculateObjectValue(null, this.options.icons)
+    if (typeof opts.icons === 'string') {
+      opts.icons = Utils.calculateObjectValue(null, opts.icons)
     }
 
-    if (typeof this.options.buttonsOrder === 'string') {
-      this.options.buttonsOrder = this.options.buttonsOrder.replace(/\[|\]| |'/g, '').toLowerCase().split(',')
+    if (typeof opts.buttonsOrder === 'string') {
+      opts.buttonsOrder = opts.buttonsOrder.replace(/\[|\]| |'/g, '').toLowerCase().split(',')
     }
 
     this.buttons = Object.assign(this.buttons, {
       paginationSwitch: {
-        'text': this.options.formatPaginationSwitchUp(),
-        'icon': this.options.icons.paginationSwitchDown,
-        'render': false,
-        'event': this.togglePagination,
-        'attributes': {
-          'aria-label': this.options.formatPaginationSwitch(),
-          'title': this.options.formatPaginationSwitch()
+        text: opts.pagination ? opts.formatPaginationSwitchUp() : opts.formatPaginationSwitchDown(),
+        icon: opts.pagination ? opts.icons.paginationSwitchDown : opts.icons.paginationSwitchUp,
+        render: false,
+        event: this.togglePagination,
+        attributes: {
+          'aria-label': opts.formatPaginationSwitch(),
+          title: opts.formatPaginationSwitch()
         }
       },
       refresh: {
-        'text': this.options.formatRefresh(),
-        'icon': this.options.icons.refresh,
-        'render': false,
-        'event': 'this.refresh',
-        'attributes': {
-          'aria-label': this.options.formatRefresh(),
-          'title': this.options.formatRefresh()
+        text: opts.formatRefresh(),
+        icon: opts.icons.refresh,
+        render: false,
+        event: this.refresh,
+        attributes: {
+          'aria-label': opts.formatRefresh(),
+          title: opts.formatRefresh()
         }
       },
       toggle: {
-        'text': this.options.formatToggle(),
-        'icon': this.options.icons.toggleOff,
-        'render': false,
-        'event': this.toggleView,
-        'attributes': {
-          'aria-label': this.options.formatToggleOn(),
-          'title': this.options.formatToggleOn()
+        text: opts.formatToggle(),
+        icon: opts.icons.toggleOff,
+        render: false,
+        event: this.toggleView,
+        attributes: {
+          'aria-label': opts.formatToggleOn(),
+          title: opts.formatToggleOn()
         }
       },
       fullscreen: {
-        'text': this.options.formatFullscreen(),
-        'icon': this.options.icons.fullscreen,
-        'render': false,
-        'event': this.toggleFullscreen,
-        'attributes': {
-          'aria-label': this.options.formatFullscreen(),
-          'title': this.options.formatFullscreen()
+        text: opts.formatFullscreen(),
+        icon: opts.icons.fullscreen,
+        render: false,
+        event: this.toggleFullscreen,
+        attributes: {
+          'aria-label': opts.formatFullscreen(),
+          title: opts.formatFullscreen()
         }
       },
       columns: {
-        'render': false,
-        'html': (() => {
+        render: false,
+        html: (() => {
           const html = []
-          html.push(`<div class="keep-open ${this.constants.classes.buttonsDropdown}" title="${this.options.formatColumns()}">
+          html.push(`<div class="keep-open ${this.constants.classes.buttonsDropdown}" title="${opts.formatColumns()}">
             <button class="${this.constants.buttonsClass} dropdown-toggle" type="button" data-toggle="dropdown"
-            aria-label="Columns" title="${this.options.formatColumns()}">
-            ${this.options.showButtonIcons ? Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.columns) : ''}
-            ${this.options.showButtonText ? this.options.formatColumns() : ''}
+            aria-label="Columns" title="${opts.formatColumns()}">
+            ${opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.columns) : ''}
+            ${opts.showButtonText ? opts.formatColumns() : ''}
             ${this.constants.html.dropdownCaret}
             </button>
             ${this.constants.html.toolbarDropdown[0]}`)
 
-          if (this.options.showColumnsSearch) {
+          if (opts.showColumnsSearch) {
             html.push(
               Utils.sprintf(this.constants.html.toolbarDropdownItem,
-                Utils.sprintf('<input type="text" class="%s" name="columnsSearch" placeholder="%s" autocomplete="off">', this.constants.classes.input, this.options.formatSearch())
+                Utils.sprintf('<input type="text" class="%s" name="columnsSearch" placeholder="%s" autocomplete="off">', this.constants.classes.input, opts.formatSearch())
               )
             )
             html.push(this.constants.html.toolbarDropdownSeparator)
           }
 
-          if (this.options.showColumnsToggleAll) {
+          if (opts.showColumnsToggleAll) {
             const allFieldsVisible = this.getVisibleColumns().length === this.columns.filter(column => !this.isSelectionColumn(column)).length
             html.push(
               Utils.sprintf(this.constants.html.toolbarDropdownItem,
                 Utils.sprintf('<input type="checkbox" class="toggle-all" %s> <span>%s</span>',
-                  allFieldsVisible ? 'checked="checked"' : '', this.options.formatColumnsToggleAll())
+                  allFieldsVisible ? 'checked="checked"' : '', opts.formatColumnsToggleAll())
               )
             )
 
@@ -647,12 +647,12 @@ class BootstrapTable {
               return
             }
 
-            if (this.options.cardView && !column.cardVisible) {
+            if (opts.cardView && !column.cardVisible) {
               return
             }
 
             const checked = column.visible ? ' checked="checked"' : ''
-            const disabled = (visibleColumns <= this.options.minimumCountColumns) && checked ? ' disabled="disabled"' : ''
+            const disabled = (visibleColumns <= opts.minimumCountColumns) && checked ? ' disabled="disabled"' : ''
             if (column.switchable) {
               html.push(Utils.sprintf(this.constants.html.toolbarDropdownItem,
                 Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s%s> <span>%s</span>',
@@ -670,26 +670,25 @@ class BootstrapTable {
     for (const [buttonName, buttonConfig] of Object.entries(this.buttons)) {
       let buttonHtml
       if (buttonConfig.hasOwnProperty('html')) {
-        buttonHtml = Utils.calculateObjectValue(this.options, buttonConfig.html)
+        buttonHtml = Utils.calculateObjectValue(opts, buttonConfig.html)
       } else {
         buttonHtml = `<button class="${this.constants.buttonsClass}" type="button" name="${buttonName}"`
 
         if (buttonConfig.hasOwnProperty('attributes')) {
           for (const [attributeName, value] of Object.entries(buttonConfig.attributes)) {
-            const attributeValue = Utils.calculateObjectValue(this.options, value)
-            buttonHtml += ` ${attributeName}="${attributeValue}"`
+            buttonHtml += ` ${attributeName}="${Utils.calculateObjectValue(opts, value)}"`
           }
         }
 
         buttonHtml += '>'
 
-        if (this.options.showButtonIcons && buttonConfig.hasOwnProperty('icon')) {
-          const icon = Utils.calculateObjectValue(this.options, buttonConfig.icon)
-          buttonHtml += Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon) + ' '
+        if (opts.showButtonIcons && buttonConfig.hasOwnProperty('icon')) {
+          const icon = Utils.calculateObjectValue(opts, buttonConfig.icon)
+          buttonHtml += Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, icon) + ' '
         }
 
-        if (this.options.showButtonText && buttonConfig.hasOwnProperty('text')) {
-          buttonHtml += Utils.calculateObjectValue(this.options, buttonConfig.text)
+        if (opts.showButtonText && buttonConfig.hasOwnProperty('text')) {
+          buttonHtml += Utils.calculateObjectValue(opts, buttonConfig.text)
         }
 
         buttonHtml += '</button>'
@@ -697,19 +696,24 @@ class BootstrapTable {
 
       buttonsHtml[buttonName] = buttonHtml
       const optionName = `show${buttonName.charAt(0).toUpperCase()}${buttonName.substring(1)}`
-      const showOption = this.options[optionName]
-      if ((!buttonConfig.hasOwnProperty('render') || buttonConfig.hasOwnProperty('render') && buttonConfig.render) && (showOption === undefined || showOption === true)) {
-        this.options[optionName] = true
+      const showOption = opts[optionName]
+      if ((
+        !buttonConfig.hasOwnProperty('render') ||
+        buttonConfig.hasOwnProperty('render') &&
+        buttonConfig.render) &&
+        (showOption === undefined || showOption === true)
+      ) {
+        opts[optionName] = true
       }
 
-      if (!this.options.buttonsOrder.includes(buttonName)) {
-        this.options.buttonsOrder.push(buttonName)
+      if (!opts.buttonsOrder.includes(buttonName)) {
+        opts.buttonsOrder.push(buttonName)
       }
     }
 
     // Adding the button html to the final toolbar html when the showOption is true
-    for (const button of this.options.buttonsOrder) {
-      const showOption = this.options[`show${button.charAt(0).toUpperCase()}${button.substring(1)}`]
+    for (const button of opts.buttonsOrder) {
+      const showOption = opts[`show${button.charAt(0).toUpperCase()}${button.substring(1)}`]
       if (showOption) {
         html.push(buttonsHtml[button])
       }
@@ -741,12 +745,12 @@ class BootstrapTable {
       }
     }
 
-    if (this.options.showColumns) {
+    if (opts.showColumns) {
       $keepOpen = this.$toolbar.find('.keep-open')
       const $checkboxes = $keepOpen.find('input[type="checkbox"]:not(".toggle-all")')
       const $toggleAll = $keepOpen.find('input[type="checkbox"].toggle-all')
 
-      if (switchableCount <= this.options.minimumCountColumns) {
+      if (switchableCount <= opts.minimumCountColumns) {
         $keepOpen.find('input').prop('disabled', true)
       }
 
@@ -766,7 +770,7 @@ class BootstrapTable {
         this._toggleAllColumns($(currentTarget).prop('checked'))
       })
 
-      if (this.options.showColumnsSearch) {
+      if (opts.showColumnsSearch) {
         const $columnsSearch = $keepOpen.find('[name="columnsSearch"]')
         const $listItems = $keepOpen.find('.dropdown-item-marker')
         $columnsSearch.on('keyup paste change', ({currentTarget}) => {
@@ -804,36 +808,36 @@ class BootstrapTable {
     // Fix #4516: this.showSearchClearButton is for extensions
     if (
       (opts.search || this.showSearchClearButton)
-      && typeof this.options.searchSelector !== 'string'
+      && typeof opts.searchSelector !== 'string'
     ) {
       html = []
       const showSearchButton = Utils.sprintf(this.constants.html.searchButton,
         this.constants.buttonsClass,
-        this.options.formatSearch(),
-        this.options.showButtonIcons ? Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.search) : '',
-        this.options.showButtonText ? this.options.formatSearch() : ''
+        opts.formatSearch(),
+        opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.search) : '',
+        opts.showButtonText ? opts.formatSearch() : ''
       )
       const showSearchClearButton = Utils.sprintf(this.constants.html.searchClearButton,
         this.constants.buttonsClass,
-        this.options.formatClearSearch(),
-        this.options.showButtonIcons ? Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.clearSearch) : '',
-        this.options.showButtonText ? this.options.formatClearSearch() : ''
+        opts.formatClearSearch(),
+        opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.clearSearch) : '',
+        opts.showButtonText ? opts.formatClearSearch() : ''
       )
       const searchInputHtml = `<input class="${this.constants.classes.input}
-        ${Utils.sprintf(' %s%s', this.constants.classes.inputPrefix, this.options.iconSize)}
-        search-input" type="search" placeholder="${this.options.formatSearch()}" autocomplete="off">`
+        ${Utils.sprintf(' %s%s', this.constants.classes.inputPrefix, opts.iconSize)}
+        search-input" type="search" placeholder="${opts.formatSearch()}" autocomplete="off">`
       let searchInputFinalHtml = searchInputHtml
 
-      if (this.options.showSearchButton || this.options.showSearchClearButton) {
-        const buttonsHtml = (this.options.showSearchButton ? showSearchButton : '') +
-          (this.options.showSearchClearButton ? showSearchClearButton : '')
+      if (opts.showSearchButton || opts.showSearchClearButton) {
+        const buttonsHtml = (opts.showSearchButton ? showSearchButton : '') +
+          (opts.showSearchClearButton ? showSearchClearButton : '')
 
-        searchInputFinalHtml = this.options.search ? Utils.sprintf(this.constants.html.inputGroup,
+        searchInputFinalHtml = opts.search ? Utils.sprintf(this.constants.html.inputGroup,
           searchInputHtml, buttonsHtml) : buttonsHtml
       }
 
       html.push(Utils.sprintf(`
-        <div class="${this.constants.classes.pull}-${this.options.searchAlign} search ${this.constants.classes.inputGroup}">
+        <div class="${this.constants.classes.pull}-${opts.searchAlign} search ${this.constants.classes.inputGroup}">
           %s
         </div>
       `, searchInputFinalHtml))
@@ -845,7 +849,7 @@ class BootstrapTable {
           clearTimeout(timeoutId) // doesn't matter if it's 0
           timeoutId = setTimeout(() => {
             this.onSearch({currentTarget: $searchInput})
-          }, this.options.searchTimeOut)
+          }, opts.searchTimeOut)
         })
 
         if (opts.searchOnEnterKey) {
@@ -855,12 +859,12 @@ class BootstrapTable {
         handleInputEvent($searchInput)
       }
 
-      if (this.options.showSearchClearButton) {
+      if (opts.showSearchClearButton) {
         this.$toolbar.find('.search button[name=clearSearch]').click(() => {
           this.resetSearch()
         })
       }
-    } else if (typeof this.options.searchSelector === 'string') {
+    } else if (typeof opts.searchSelector === 'string') {
       const $searchInput = Utils.getSearchInput(this)
       handleInputEvent($searchInput)
     }
@@ -1950,10 +1954,10 @@ class BootstrapTable {
   trigger (_name, ...args) {
     const name = `${_name}.bs.table`
     this.options[BootstrapTable.EVENTS[name]](...[...args, this])
-    this.$el.trigger($.Event(name, {sender: this}), args)
+    this.$el.trigger($.Event(name, { sender: this }), args)
 
     this.options.onAll(name, ...[...args, this])
-    this.$el.trigger($.Event('all.bs.table', {sender: this}), [name, args])
+    this.$el.trigger($.Event('all.bs.table', { sender: this }), [name, args])
   }
 
   resetHeader () {