mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-31 18:39:51 +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,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Dog/properties/packSize",
|
||||
|
@ -563,6 +564,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Dog/properties/type",
|
||||
|
@ -821,6 +823,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Dog",
|
||||
|
@ -1141,6 +1144,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Cat/properties/type",
|
||||
|
@ -1424,6 +1428,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Cat/properties/packSize",
|
||||
|
@ -1678,6 +1683,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Cat",
|
||||
|
@ -1957,6 +1963,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Pet",
|
||||
|
@ -2266,6 +2273,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Dog/properties/packSize",
|
||||
|
@ -2537,6 +2545,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Dog/properties/type",
|
||||
|
@ -2795,6 +2804,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
},
|
||||
"unstable_ignoreMimeParameters": false,
|
||||
"untrustedSpec": false,
|
||||
"userQueryParamToNavigate": false,
|
||||
},
|
||||
"pattern": undefined,
|
||||
"pointer": "#/components/schemas/Dog",
|
||||
|
|
|
@ -94,6 +94,6 @@ export class HistoryService {
|
|||
}
|
||||
|
||||
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', () => {
|
||||
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', () => {
|
||||
const history = new HistoryService(options);
|
||||
expect(typeof history).not.toBe('function');
|
||||
expect(history.subscribe).toBeDefined();
|
||||
});
|
||||
|
||||
test('History subscribe', () => {
|
||||
const fn = jest.fn();
|
||||
const history = new HistoryService(options);
|
||||
history.subscribe(fn);
|
||||
history.emit();
|
||||
expect(fn).toHaveBeenCalled();
|
||||
|
@ -15,6 +34,7 @@ describe('History service', () => {
|
|||
|
||||
test('History subscribe should return unsubscribe function', () => {
|
||||
const fn = jest.fn();
|
||||
const history = new HistoryService(options);
|
||||
const unsubscribe = history.subscribe(fn);
|
||||
history.emit();
|
||||
expect(fn).toHaveBeenCalled();
|
||||
|
@ -23,16 +43,44 @@ describe('History service', () => {
|
|||
expect(fn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('currentId should return correct id', () => {
|
||||
window.location.hash = '#testid';
|
||||
expect(history.currentId).toEqual('testid');
|
||||
describe('History with config property: `userQueryParamToNavigate` false', () => {
|
||||
test('currentId should return correct id', () => {
|
||||
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', () => {
|
||||
expect(history.linkForId('testid')).toEqual('#testid');
|
||||
});
|
||||
describe('History with config property: `userQueryParamToNavigate` true', () => {
|
||||
const overrideOptions = new RedocNormalizedOptions({
|
||||
userQueryParamToNavigate: true,
|
||||
});
|
||||
|
||||
test('should return empty link for empty id', () => {
|
||||
expect(history.linkForId('')).toEqual('');
|
||||
test('currentId should return correct id', () => {
|
||||
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