mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
tests: add standalone component test
This commit is contained in:
parent
deffdc548e
commit
83af48112c
|
@ -1,7 +1,7 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { renderToString } from 'react-dom/server';
|
import { renderToString } from 'react-dom/server';
|
||||||
import { Redoc, createStore } from '../';
|
import { Redoc, createStore } from '../';
|
||||||
var yaml = require('yaml-js');
|
import * as yaml from 'yaml-js';
|
||||||
|
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
21
src/__tests__/standalone.test.tsx
Normal file
21
src/__tests__/standalone.test.tsx
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import { mount } from 'enzyme';
|
||||||
|
import * as yaml from 'yaml-js';
|
||||||
|
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
|
// import { filterPropsDeep } from '../../../utils/test-utils';
|
||||||
|
|
||||||
|
import { RedocStandalone, Loading, StoreProvider, ErrorBoundary } from '../components/';
|
||||||
|
|
||||||
|
describe('Components', () => {
|
||||||
|
describe('RedocStandalone', () => {
|
||||||
|
test('should show loading first', () => {
|
||||||
|
const spec = yaml.load(readFileSync(resolve(__dirname, '../../demo/openapi.yaml')));
|
||||||
|
|
||||||
|
let inst = mount(<RedocStandalone spec={spec} options={{}} />);
|
||||||
|
expect(inst.find(Loading)).toHaveLength(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -4,6 +4,7 @@ export * from './Redoc/Redoc';
|
||||||
export * from './Schema/';
|
export * from './Schema/';
|
||||||
export * from './SearchBox/SearchBox';
|
export * from './SearchBox/SearchBox';
|
||||||
export * from './Operation/Operation';
|
export * from './Operation/Operation';
|
||||||
|
export * from './Loading/Loading';
|
||||||
export * from './RedocStandalone';
|
export * from './RedocStandalone';
|
||||||
|
|
||||||
export * from './ErrorBoundary';
|
export * from './ErrorBoundary';
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
const markSpy = jest.fn();
|
const mockMark = jest.fn();
|
||||||
const unmarkSpy = jest.fn();
|
const mockUnmark = jest.fn();
|
||||||
|
|
||||||
class FakeMark {
|
jest.mock('mark.js', () => () => ({
|
||||||
mark = markSpy;
|
mark: mockMark,
|
||||||
unmark = unmarkSpy;
|
unmark: mockUnmark,
|
||||||
}
|
}));
|
||||||
|
|
||||||
jest.mock('mark.js', () => FakeMark);
|
|
||||||
|
|
||||||
import { MarkerService } from '../MarkerService';
|
import { MarkerService } from '../MarkerService';
|
||||||
|
|
||||||
|
@ -16,8 +14,8 @@ describe('Marker service', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
marker = new MarkerService();
|
marker = new MarkerService();
|
||||||
markSpy.mockClear();
|
mockMark.mockClear();
|
||||||
unmarkSpy.mockClear();
|
mockUnmark.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add element to Map', () => {
|
test('add element to Map', () => {
|
||||||
|
@ -42,7 +40,7 @@ describe('Marker service', () => {
|
||||||
|
|
||||||
marker.addOnly([element, e2, e3]);
|
marker.addOnly([element, e2, e3]);
|
||||||
|
|
||||||
expect(unmarkSpy).toHaveBeenCalledTimes(1);
|
expect(mockUnmark).toHaveBeenCalledTimes(1);
|
||||||
expect(marker.map.size).toEqual(3);
|
expect(marker.map.size).toEqual(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -55,8 +53,8 @@ describe('Marker service', () => {
|
||||||
|
|
||||||
marker.unmark();
|
marker.unmark();
|
||||||
|
|
||||||
expect(unmarkSpy).toHaveBeenCalledTimes(3);
|
expect(mockUnmark).toHaveBeenCalledTimes(3);
|
||||||
expect(markSpy).not.toHaveBeenCalled();
|
expect(mockMark).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
test('clearAll: should unmark and remove all elements', () => {
|
test('clearAll: should unmark and remove all elements', () => {
|
||||||
const e1 = document.createElement('span');
|
const e1 = document.createElement('span');
|
||||||
|
@ -67,8 +65,8 @@ describe('Marker service', () => {
|
||||||
|
|
||||||
marker.clearAll();
|
marker.clearAll();
|
||||||
|
|
||||||
expect(unmarkSpy).toHaveBeenCalledTimes(3);
|
expect(mockUnmark).toHaveBeenCalledTimes(3);
|
||||||
expect(markSpy).not.toHaveBeenCalled();
|
expect(mockMark).not.toHaveBeenCalled();
|
||||||
expect(marker.map.size).toEqual(0);
|
expect(marker.map.size).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -81,9 +79,9 @@ describe('Marker service', () => {
|
||||||
|
|
||||||
marker.mark('test');
|
marker.mark('test');
|
||||||
|
|
||||||
expect(unmarkSpy).toHaveBeenCalledTimes(3);
|
expect(mockUnmark).toHaveBeenCalledTimes(3);
|
||||||
expect(markSpy).toHaveBeenCalledTimes(3);
|
expect(mockMark).toHaveBeenCalledTimes(3);
|
||||||
expect(markSpy).toHaveBeenCalledWith('test');
|
expect(mockMark).toHaveBeenCalledWith('test');
|
||||||
expect(marker.map.size).toEqual(3);
|
expect(marker.map.size).toEqual(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -91,13 +89,13 @@ describe('Marker service', () => {
|
||||||
marker.add(element);
|
marker.add(element);
|
||||||
marker.mark();
|
marker.mark();
|
||||||
|
|
||||||
expect(markSpy).not.toHaveBeenCalled();
|
expect(mockMark).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
test('mark: should save previous marked term and use it if no term is provided', () => {
|
test('mark: should save previous marked term and use it if no term is provided', () => {
|
||||||
marker.add(element);
|
marker.add(element);
|
||||||
marker.mark('test');
|
marker.mark('test');
|
||||||
marker.mark();
|
marker.mark();
|
||||||
|
|
||||||
expect(markSpy).toHaveBeenLastCalledWith('test');
|
expect(mockMark).toHaveBeenLastCalledWith('test');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user