2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2016-10-25 19:44:32 -04:00
|
|
|
import React from 'react';
|
|
|
|
import SyntaxHighlighter from 'react-syntax-highlighter';
|
2016-10-26 14:09:27 -04:00
|
|
|
import { mount, shallow } from 'enzyme';
|
2017-04-13 18:04:09 -04:00
|
|
|
|
2020-05-07 17:18:10 -04:00
|
|
|
import HighlightedSql from 'src/SqlLab/components/HighlightedSql';
|
|
|
|
import ModalTrigger from 'src/components/ModalTrigger';
|
2016-10-25 19:44:32 -04:00
|
|
|
|
|
|
|
describe('HighlightedSql', () => {
|
2019-11-27 17:02:48 -05:00
|
|
|
const sql =
|
|
|
|
"SELECT * FROM test WHERE something='fkldasjfklajdslfkjadlskfjkldasjfkladsjfkdjsa'";
|
2016-10-25 19:44:32 -04:00
|
|
|
it('renders with props', () => {
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(React.isValidElement(<HighlightedSql sql={sql} />)).toBe(true);
|
2016-10-25 19:44:32 -04:00
|
|
|
});
|
2016-10-26 14:09:27 -04:00
|
|
|
it('renders a ModalTrigger', () => {
|
2016-10-25 19:44:32 -04:00
|
|
|
const wrapper = shallow(<HighlightedSql sql={sql} />);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(ModalTrigger)).toExist();
|
2016-10-25 19:44:32 -04:00
|
|
|
});
|
2016-10-26 14:09:27 -04:00
|
|
|
it('renders a ModalTrigger while using shrink', () => {
|
2016-10-25 19:44:32 -04:00
|
|
|
const wrapper = shallow(<HighlightedSql sql={sql} shrink maxWidth={20} />);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(ModalTrigger)).toExist();
|
2016-10-26 14:09:27 -04:00
|
|
|
});
|
|
|
|
it('renders two SyntaxHighlighter in modal', () => {
|
|
|
|
const wrapper = mount(
|
2019-11-27 17:02:48 -05:00
|
|
|
<HighlightedSql
|
|
|
|
sql={sql}
|
|
|
|
rawSql="SELECT * FORM foo"
|
|
|
|
shrink
|
|
|
|
maxWidth={5}
|
|
|
|
/>,
|
|
|
|
);
|
2016-12-20 01:33:55 -05:00
|
|
|
const pre = wrapper.find('pre');
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(pre).toHaveLength(1);
|
2016-12-20 01:33:55 -05:00
|
|
|
pre.simulate('click');
|
2017-08-28 19:16:52 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
const modalBody = mount(wrapper.state().modalBody);
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(modalBody.find(SyntaxHighlighter)).toHaveLength(2);
|
2017-08-28 19:16:52 -04:00
|
|
|
}, 10);
|
2016-10-25 19:44:32 -04:00
|
|
|
});
|
|
|
|
});
|