import * as React from 'react';
import { render, screen } from '@testing-library/react';
import InternalLink from '../index';
const localStorageMock = jest.spyOn(
require('../../../utils/parseLocalStorage'),
'parseLocalStorage'
);
localStorageMock.mockReturnValue({
platform: 'js',
integration: 'js',
framework: 'js'
});
describe('InternalLink', () => {
it('should render the InternalLink component', async () => {
render(Internal Link);
const linkNode = await screen.findByText('Internal Link');
expect(linkNode).toBeInTheDocument();
});
it('should add the platform to the link', async () => {
const href = '/lib/libFile';
render(Internal Link);
const linkNode = await screen.findByText('Internal Link');
const linkHref = linkNode.href;
expect(linkHref).toContain('/q/platform/js');
});
it('should add the integration to the link', async () => {
const href = '/start/startFile';
render(Internal Link);
const linkNode = await screen.findByText('Internal Link');
const linkHref = linkNode.href;
expect(linkHref).toContain('/q/integration/js');
});
it('should add the framework to the link', async () => {
const href = '/ui/uiFile';
render(Internal Link);
const linkNode = await screen.findByText('Internal Link');
const linkHref = linkNode.href;
expect(linkHref).toContain('/q/framework/js');
});
it('should not change the href if the platform already exists', async () => {
const href = '/lib/libFile/q/platform/js';
render(Internal Link);
const expectedHref = `http://localhost${href}`;
const linkNode = await screen.findByText('Internal Link');
const linkHref = linkNode.href;
expect(linkHref).toEqual(expectedHref);
});
});