ExternalLink.test.tsx 1.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * Licensed 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.
 */

17
import React from 'react';
Ridwan Amode's avatar
Ridwan Amode committed
18
import { render } from '@testing-library/react';
19 20 21 22 23 24 25 26
import faker from 'faker';

import ExternalLink, { ExternalLinkProps } from './ExternalLink';

const defaultProps: ExternalLinkProps = {
  linkText: faker.random.words(),
  to: faker.internet.url(),
  classNames: {
Ridwan Amode's avatar
Ridwan Amode committed
27 28
    icon: faker.random.word(),
    link: faker.random.word()
29 30 31 32
  }
};

describe('<ExternalLink />', () => {
33
  const renderExternalLink = () => render(<ExternalLink {...defaultProps} />);
34
  it('renders without error', () => {
Ridwan Amode's avatar
Ridwan Amode committed
35 36
    const { container } = renderExternalLink();
    expect(() => container).not.toThrow();
37 38 39
  });

  it('applies the passed in classNames', () => {
Ridwan Amode's avatar
Ridwan Amode committed
40
    const { container } = renderExternalLink();
41

42
    expect(
Ridwan Amode's avatar
Ridwan Amode committed
43
      container
44 45 46 47 48 49 50
        .querySelector(`icon-mock`)
        ?.getAttribute('classname')
        ?.includes(defaultProps.classNames?.icon as string)
    ).toBeTruthy();

    expect(
      container.querySelector(`.link.${defaultProps.classNames?.link}`)
51 52 53
    ).toBeTruthy();
  });
});