-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/elastic/kibana into alert…
…ing/default-es-index-schema
- Loading branch information
Showing
35 changed files
with
313 additions
and
4,477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
x-pack/plugins/security_solution/public/common/components/line_clamp/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { mount } from 'enzyme'; | ||
import { repeat } from 'lodash/fp'; | ||
import React from 'react'; | ||
|
||
import { LineClamp } from '.'; | ||
|
||
describe('LineClamp', () => { | ||
const message = repeat(1000, 'abcdefghij '); // 10 characters, with a trailing space | ||
|
||
describe('no overflow', () => { | ||
test('it does NOT render the expanded line clamp when isOverflow is falsy', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="expanded-line-clamp"]').exists()).toBe(false); | ||
}); | ||
|
||
test('it does NOT render the styled line clamp expanded when isOverflow is falsy', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="styled-line-clamp"]').exists()).toBe(false); | ||
}); | ||
|
||
test('it renders the default line clamp when isOverflow is falsy', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="default-line-clamp"]').first().text()).toBe(message); | ||
}); | ||
|
||
test('it does NOT render the `Read More` button when isOverflow is falsy', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="summary-view-readmore"]').exists()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('overflow', () => { | ||
const clientHeight = 400; | ||
const scrollHeight = clientHeight + 100; // scrollHeight is > clientHeight | ||
|
||
beforeAll(() => { | ||
Object.defineProperty(HTMLElement.prototype, 'clientHeight', { | ||
configurable: true, | ||
value: clientHeight, | ||
}); | ||
|
||
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', { | ||
configurable: true, | ||
value: scrollHeight, | ||
}); | ||
}); | ||
|
||
test('it does NOT render the expanded line clamp by default when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="expanded-line-clamp"]').exists()).toBe(false); | ||
}); | ||
|
||
test('it renders the styled line clamp when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="styled-line-clamp"]').first().text()).toBe(message); | ||
}); | ||
|
||
test('it does NOT render the default line clamp when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="default-line-clamp"]').exists()).toBe(false); | ||
}); | ||
|
||
test('it renders the `Read More` button with the expected (default) text when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
expect(wrapper.find('[data-test-subj="summary-view-readmore"]').first().text()).toBe( | ||
'Read More' | ||
); | ||
}); | ||
|
||
describe('clicking the Read More button', () => { | ||
test('it displays the `Read Less` button text after the user clicks the `Read More` button when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(wrapper.find('[data-test-subj="summary-view-readmore"]').first().text()).toBe( | ||
'Read Less' | ||
); | ||
}); | ||
|
||
test('it renders the expanded content after the user clicks the `Read More` button when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(wrapper.find('[data-test-subj="expanded-line-clamp"]').first().text()).toBe(message); | ||
}); | ||
}); | ||
|
||
test('it renders the expanded content with a max-height of one third the view height when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(wrapper.find('[data-test-subj="expanded-line-clamp"]').first()).toHaveStyleRule( | ||
'max-height', | ||
'33vh' | ||
); | ||
}); | ||
|
||
test('it automatically vertically scrolls the content when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(wrapper.find('[data-test-subj="expanded-line-clamp"]').first()).toHaveStyleRule( | ||
'overflow-y', | ||
'auto' | ||
); | ||
}); | ||
|
||
test('it does NOT render the styled line clamp after the user clicks the `Read More` button when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(wrapper.find('[data-test-subj="styled-line-clamp"]').exists()).toBe(false); | ||
}); | ||
|
||
test('it does NOT render the default line clamp after the user clicks the `Read More` button when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); | ||
|
||
expect(wrapper.find('[data-test-subj="default-line-clamp"]').exists()).toBe(false); | ||
}); | ||
|
||
test('it once again displays the `Read More` button text after the user clicks the `Read Less` when isOverflow is true', () => { | ||
const wrapper = mount(<LineClamp content={message} />); | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); // 1st toggle | ||
|
||
wrapper.find('[data-test-subj="summary-view-readmore"]').first().simulate('click'); | ||
wrapper.update(); // 2nd toggle | ||
|
||
expect(wrapper.find('[data-test-subj="summary-view-readmore"]').first().text()).toBe( | ||
'Read More' // after the 2nd toggle, the button once-again says `Read More` | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.