From 56b031a68a798f2ab9fa98b85e6af9173ba6bbd8 Mon Sep 17 00:00:00 2001 From: Justin Kahn Date: Mon, 15 Jul 2019 17:48:14 +0800 Subject: [PATCH] fix(Collapse): accordian mode --- src/collapse/collapse.jsx | 2 +- test/collapse/index-spec.js | 345 ++++++++++++++++++++++++------------ 2 files changed, 233 insertions(+), 114 deletions(-) diff --git a/src/collapse/collapse.jsx b/src/collapse/collapse.jsx index b98460018f..e62682744c 100644 --- a/src/collapse/collapse.jsx +++ b/src/collapse/collapse.jsx @@ -128,7 +128,7 @@ class Collapse extends React.Component { let isExpanded = false; if (this.props.accordion) { - isExpanded = expandedKeys[0] === key; + isExpanded = String(expandedKeys[0]) === String(key); } else { isExpanded = expandedKeys.some(expandedKey => { if ( diff --git a/test/collapse/index-spec.js b/test/collapse/index-spec.js index a6b64c9bc3..13a30b56b3 100644 --- a/test/collapse/index-spec.js +++ b/test/collapse/index-spec.js @@ -57,120 +57,239 @@ describe('Collapse', () => { }); describe('defaultExpandedKeys', () => { - it('should expand panel with string key', () => { - const wrapper = mount( - - Pannel Content - Pannel Content - Pannel Content - Pannel Content - -
others
-
- ); - const el = wrapper - .find('.next-collapse-panel') - .at(2); - assert(el.hasClass('next-collapse-panel-expanded')); - }); - - it('should expand panel with number key', () => { - const wrapper = mount( - - Pannel Content - Pannel Content - Pannel Content - Pannel Content - -
others
-
- ); - const el = wrapper - .find('.next-collapse-panel') - .at(2); - assert(el.hasClass('next-collapse-panel-expanded')); - }); - - it('should close default expanded string keys', () => { - const wrapper = mount( - - Pannel Content - Pannel Content - Pannel Content - Pannel Content - -
others
-
- ); - wrapper - .find('.next-collapse-panel-title') - .at(2) - .simulate('click'); - assert(wrapper.find('.next-collapse-panel-expanded').length === 0); - }); + describe('default mode', () => { + it('should expand panel with string key', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + const el = wrapper + .find('.next-collapse-panel') + .at(2); + assert(el.hasClass('next-collapse-panel-expanded')); + }); + + it('should expand panel with number key', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + const el = wrapper + .find('.next-collapse-panel') + .at(2); + assert(el.hasClass('next-collapse-panel-expanded')); + }); + + it('should close default expanded string keys', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + wrapper + .find('.next-collapse-panel-title') + .at(2) + .simulate('click'); + assert(wrapper.find('.next-collapse-panel-expanded').length === 0); + }); + + it('should close default expanded number keys', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + wrapper + .find('.next-collapse-panel-title') + .at(2) + .simulate('click'); + assert(wrapper.find('.next-collapse-panel-expanded').length === 0); + }); + + it('should open default expanded datasource using number keys', () => { + const list = [ + { + title: 'Well, hello there', + key: 0, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + { + title: 'Well, hello there', + key: 1, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + ]; + const wrapper = mount(); + const el = wrapper + .find('.next-collapse-panel') + .at(1); + assert(el.hasClass('next-collapse-panel-expanded')); + }); + + it('should close default expanded datasource using number keys on click', () => { + const list = [ + { + title: 'Well, hello there', + key: 0, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + { + title: 'Well, hello there', + key: 1, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + ]; + const wrapper = mount(); + wrapper + .find('.next-collapse-panel-title') + .at(1) + .simulate('click'); + assert(wrapper.find('.next-collapse-panel-expanded').length === 0); + }); + }) - it('should close default expanded number keys', () => { - const wrapper = mount( - - Pannel Content - Pannel Content - Pannel Content - Pannel Content - -
others
-
- ); - wrapper - .find('.next-collapse-panel-title') - .at(2) - .simulate('click'); - assert(wrapper.find('.next-collapse-panel-expanded').length === 0); - }); - - it('should open default expanded datasource using number keys', () => { - const list = [ - { - title: 'Well, hello there', - key: 0, - content: - 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', - }, - { - title: 'Well, hello there', - key: 1, - content: - 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', - }, - ]; - const wrapper = mount(); - const el = wrapper - .find('.next-collapse-panel') - .at(1); - assert(el.hasClass('next-collapse-panel-expanded')); - }); - - it('should close default expanded datasource using number keys on click', () => { - const list = [ - { - title: 'Well, hello there', - key: 0, - content: - 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', - }, - { - title: 'Well, hello there', - key: 1, - content: - 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', - }, - ]; - const wrapper = mount(); - wrapper - .find('.next-collapse-panel-title') - .at(1) - .simulate('click'); - assert(wrapper.find('.next-collapse-panel-expanded').length === 0); - }); + describe('accordian mode', () => { + it('should expand panel with string key', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + const el = wrapper + .find('.next-collapse-panel') + .at(2); + assert(el.hasClass('next-collapse-panel-expanded')); + }); + + it('should expand panel with number key', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + const el = wrapper + .find('.next-collapse-panel') + .at(2); + assert(el.hasClass('next-collapse-panel-expanded')); + }); + + it('should close default expanded string keys', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + wrapper + .find('.next-collapse-panel-title') + .at(2) + .simulate('click'); + assert(wrapper.find('.next-collapse-panel-expanded').length === 0); + }); + + it('should close default expanded number keys', () => { + const wrapper = mount( + + Pannel Content + Pannel Content + Pannel Content + Pannel Content + +
others
+
+ ); + wrapper + .find('.next-collapse-panel-title') + .at(2) + .simulate('click'); + assert(wrapper.find('.next-collapse-panel-expanded').length === 0); + }); + + it('should open default expanded datasource using number keys', () => { + const list = [ + { + title: 'Well, hello there', + key: 0, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + { + title: 'Well, hello there', + key: 1, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + ]; + const wrapper = mount(); + const el = wrapper + .find('.next-collapse-panel') + .at(1); + assert(el.hasClass('next-collapse-panel-expanded')); + }); + + it('should close default expanded datasource using number keys on click', () => { + const list = [ + { + title: 'Well, hello there', + key: 0, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + { + title: 'Well, hello there', + key: 1, + content: + 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', + }, + ]; + const wrapper = mount(); + wrapper + .find('.next-collapse-panel-title') + .at(1) + .simulate('click'); + assert(wrapper.find('.next-collapse-panel-expanded').length === 0); + }); + }) }) describe('event', () => {