mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-01 19:00:21 +03:00
test(): Update tests cases
This commit is contained in:
parent
a16e633159
commit
dd6299b612
|
@ -292,6 +292,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Dog/properties/packSize",
|
"pointer": "#/components/schemas/Dog/properties/packSize",
|
||||||
|
@ -563,6 +564,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Dog/properties/type",
|
"pointer": "#/components/schemas/Dog/properties/type",
|
||||||
|
@ -821,6 +823,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Dog",
|
"pointer": "#/components/schemas/Dog",
|
||||||
|
@ -1141,6 +1144,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Cat/properties/type",
|
"pointer": "#/components/schemas/Cat/properties/type",
|
||||||
|
@ -1424,6 +1428,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Cat/properties/packSize",
|
"pointer": "#/components/schemas/Cat/properties/packSize",
|
||||||
|
@ -1678,6 +1683,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Cat",
|
"pointer": "#/components/schemas/Cat",
|
||||||
|
@ -1957,6 +1963,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Pet",
|
"pointer": "#/components/schemas/Pet",
|
||||||
|
@ -2266,6 +2273,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Dog/properties/packSize",
|
"pointer": "#/components/schemas/Dog/properties/packSize",
|
||||||
|
@ -2537,6 +2545,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Dog/properties/type",
|
"pointer": "#/components/schemas/Dog/properties/type",
|
||||||
|
@ -2795,6 +2804,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"unstable_ignoreMimeParameters": false,
|
"unstable_ignoreMimeParameters": false,
|
||||||
"untrustedSpec": false,
|
"untrustedSpec": false,
|
||||||
|
"userQueryParamToNavigate": false,
|
||||||
},
|
},
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
"pointer": "#/components/schemas/Dog",
|
"pointer": "#/components/schemas/Dog",
|
||||||
|
|
|
@ -94,6 +94,6 @@ export class HistoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getHrefSplitCharacter(): string {
|
private getHrefSplitCharacter(): string {
|
||||||
return this.shouldQueryParamNavigationBeUsed() ? '?redoc' : '#';
|
return this.shouldQueryParamNavigationBeUsed() ? '?redoc=' : '#';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,32 @@
|
||||||
import { history } from '../HistoryService';
|
import { HistoryService } from '../HistoryService';
|
||||||
|
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
|
||||||
|
|
||||||
|
const options = new RedocNormalizedOptions({});
|
||||||
|
|
||||||
describe('History service', () => {
|
describe('History service', () => {
|
||||||
|
function mockWindowLocationForSearch(): void {
|
||||||
|
const mockResponse = jest.fn();
|
||||||
|
Object.defineProperty(window, 'location', {
|
||||||
|
value: {
|
||||||
|
hash: {
|
||||||
|
endsWith: mockResponse,
|
||||||
|
includes: mockResponse,
|
||||||
|
},
|
||||||
|
assign: mockResponse,
|
||||||
|
},
|
||||||
|
writable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test('should be an instance', () => {
|
test('should be an instance', () => {
|
||||||
|
const history = new HistoryService(options);
|
||||||
expect(typeof history).not.toBe('function');
|
expect(typeof history).not.toBe('function');
|
||||||
expect(history.subscribe).toBeDefined();
|
expect(history.subscribe).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('History subscribe', () => {
|
test('History subscribe', () => {
|
||||||
const fn = jest.fn();
|
const fn = jest.fn();
|
||||||
|
const history = new HistoryService(options);
|
||||||
history.subscribe(fn);
|
history.subscribe(fn);
|
||||||
history.emit();
|
history.emit();
|
||||||
expect(fn).toHaveBeenCalled();
|
expect(fn).toHaveBeenCalled();
|
||||||
|
@ -15,6 +34,7 @@ describe('History service', () => {
|
||||||
|
|
||||||
test('History subscribe should return unsubscribe function', () => {
|
test('History subscribe should return unsubscribe function', () => {
|
||||||
const fn = jest.fn();
|
const fn = jest.fn();
|
||||||
|
const history = new HistoryService(options);
|
||||||
const unsubscribe = history.subscribe(fn);
|
const unsubscribe = history.subscribe(fn);
|
||||||
history.emit();
|
history.emit();
|
||||||
expect(fn).toHaveBeenCalled();
|
expect(fn).toHaveBeenCalled();
|
||||||
|
@ -23,16 +43,44 @@ describe('History service', () => {
|
||||||
expect(fn).toHaveBeenCalledTimes(1);
|
expect(fn).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('currentId should return correct id', () => {
|
describe('History with config property: `userQueryParamToNavigate` false', () => {
|
||||||
window.location.hash = '#testid';
|
test('currentId should return correct id', () => {
|
||||||
expect(history.currentId).toEqual('testid');
|
window.location.hash = '#testid';
|
||||||
|
const history = new HistoryService(options);
|
||||||
|
expect(history.currentId).toEqual('testid');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return correct link for id', () => {
|
||||||
|
const history = new HistoryService(options);
|
||||||
|
expect(history.linkForId('testid')).toEqual('#testid');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return empty link for empty id', () => {
|
||||||
|
const history = new HistoryService(options);
|
||||||
|
expect(history.linkForId('')).toEqual('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return correct link for id', () => {
|
describe('History with config property: `userQueryParamToNavigate` true', () => {
|
||||||
expect(history.linkForId('testid')).toEqual('#testid');
|
const overrideOptions = new RedocNormalizedOptions({
|
||||||
});
|
userQueryParamToNavigate: true,
|
||||||
|
});
|
||||||
|
|
||||||
test('should return empty link for empty id', () => {
|
test('currentId should return correct id', () => {
|
||||||
expect(history.linkForId('')).toEqual('');
|
mockWindowLocationForSearch();
|
||||||
|
window.location.search = '?redoc=testid';
|
||||||
|
const history = new HistoryService(overrideOptions);
|
||||||
|
expect(history.currentId).toEqual('testid');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return correct link for id', () => {
|
||||||
|
const history = new HistoryService(overrideOptions);
|
||||||
|
expect(history.linkForId('testid')).toEqual('?redoc=testid');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return empty link for empty id', () => {
|
||||||
|
const history = new HistoryService(overrideOptions);
|
||||||
|
expect(history.linkForId('')).toEqual('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user