select.spec.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // form.spec.js created with Cypress
  2. //
  3. // Start writing your Cypress tests below!
  4. // If you're unfamiliar with how Cypress works,
  5. // check out the link below and learn how to write your first test:
  6. // https://on.cypress.io/writing-first-test
  7. /**
  8. * why use `.then`?
  9. * @see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Return-Values
  10. */
  11. describe('Select', () => {
  12. it('option hover, change active', () => {
  13. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single');
  14. cy.get('.semi-select').eq(0).click();
  15. // hover can change active index
  16. cy.get('.semi-select-option').eq(5).trigger('mouseover');
  17. cy.get('.semi-select-option-focused .semi-select-option-text').eq(0).should('have.text', 'wym');
  18. // press downArrow to test it
  19. cy.get('input').eq(0).type('{downArrow}');
  20. cy.get('.semi-select-option-focused .semi-select-option-text').eq(0).should('have.text', 'opts');
  21. });
  22. it('keyboard-enter, select choose option', { keystrokeDelay: 0 }, () => {
  23. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single');
  24. cy.get('.semi-select').eq(0).click();
  25. cy.get('input').eq(0).type('o');
  26. cy.get('input').eq(0).type('{downArrow}');
  27. cy.get('input').eq(0).type('{downArrow}');
  28. cy.get('input').eq(0).type('{enter}');
  29. cy.get('.semi-select-selection-text').eq(0).should('have.text', 'opt1');
  30. });
  31. it('clickOutSide, should hide', () => {
  32. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single', {
  33. onBeforeLoad(win) {
  34. cy.stub(win.console, 'log').as('consoleLog');
  35. },
  36. });
  37. cy.get('.semi-select').eq(0).click();
  38. // should show now
  39. cy.get('.semi-select-option-list').should('exist');
  40. // should hide after click empty area
  41. cy.get('h5').eq(0).click();
  42. cy.get('.semi-select-option-list').should('not.exist');
  43. cy.get('@consoleLog').should('be.calledWith', 'onBlur');
  44. });
  45. it('emptyContent=null', () => {
  46. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--empty-content');
  47. // when emptyContent = null, The dropdown list will not be displayed
  48. // so element(which class has semi-popover-wrapper) show have 0px height;
  49. cy.get('.semi-popover-wrapper').eq(0).should('have.css', 'height', '0px');
  50. });
  51. it('autoClearSearchValue false + remote + optionList update async', () => {
  52. cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--auto-clear-search-value');
  53. cy.get('.remote-select').eq(0).click();
  54. cy.get('.semi-select-option').eq(0).click();
  55. cy.get('.remote-select .semi-input').eq(0).type('123');
  56. cy.wait(500);
  57. cy.get('.semi-select-option').should('have.text', 'Design');
  58. });
  59. // it('should trigger onSearch when click x icon', () => {
  60. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-filter-single');
  61. // cy.get('.semi-select').eq(0).click();
  62. // cy.get('.semi-select-option').eq(0).click();
  63. // cy.get('.semi-select').eq(0).click();
  64. // cy.get('.semi-select-clear').eq(0).click();
  65. // cy.get('.semi-select-input .semi-input').should('have.value', '');
  66. // });
  67. // it('should trigger onBlur and onSearch', () => {
  68. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--use-form-api-set-value-update-array');
  69. // });
  70. // it('keyboard-skip disabled option when press up/down', () => {
  71. // });
  72. // it('optionList scroll, should trigger onListScroll', () => {
  73. // cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/form--use-form-api-set-value-update-array');
  74. // });
  75. });