refactor(docs-infra): make archive redirection tests DRY (#30894)
PR Close #30894
This commit is contained in:
parent
5193acb0a3
commit
93af1f8456
@ -809,106 +809,54 @@ describe('AppComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('archive redirection', () => {
|
describe('archive redirection', () => {
|
||||||
it('should redirect to `docs` if deployment mode is `archive` and not at a docs page', () => {
|
const redirectionPerMode: {[mode: string]: boolean} = {
|
||||||
createTestingModule('', 'archive');
|
archive: true,
|
||||||
initializeTest(false);
|
next: false,
|
||||||
expect(TestBed.get(LocationService).replace).toHaveBeenCalledWith('docs');
|
stable: false,
|
||||||
|
};
|
||||||
|
|
||||||
createTestingModule('resources', 'archive');
|
Object.keys(redirectionPerMode).forEach(mode => {
|
||||||
initializeTest(false);
|
const doRedirect = redirectionPerMode[mode];
|
||||||
expect(TestBed.get(LocationService).replace).toHaveBeenCalledWith('docs');
|
const description =
|
||||||
|
`should ${doRedirect ? '' : 'not '}redirect to 'docs' if deployment mode is '${mode}' ` +
|
||||||
|
'and at a marketing page';
|
||||||
|
const verifyNoRedirection = () => expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
||||||
|
const verifyRedirection = () => expect(TestBed.get(LocationService).replace).toHaveBeenCalledWith('docs');
|
||||||
|
const verifyPossibleRedirection = doRedirect ? verifyRedirection : verifyNoRedirection;
|
||||||
|
|
||||||
createTestingModule('guide/aot-compiler', 'archive');
|
it(description, () => {
|
||||||
initializeTest(false);
|
createTestingModule('', mode);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
initializeTest(false);
|
||||||
|
verifyPossibleRedirection();
|
||||||
|
|
||||||
createTestingModule('tutorial', 'archive');
|
createTestingModule('resources', mode);
|
||||||
initializeTest(false);
|
initializeTest(false);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
verifyPossibleRedirection();
|
||||||
|
|
||||||
createTestingModule('tutorial/toh-pt1', 'archive');
|
createTestingModule('guide/aot-compiler', mode);
|
||||||
initializeTest(false);
|
initializeTest(false);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
verifyNoRedirection();
|
||||||
|
|
||||||
createTestingModule('docs', 'archive');
|
createTestingModule('tutorial', mode);
|
||||||
initializeTest(false);
|
initializeTest(false);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
verifyNoRedirection();
|
||||||
|
|
||||||
createTestingModule('api', 'archive');
|
createTestingModule('tutorial/toh-pt1', mode);
|
||||||
initializeTest(false);
|
initializeTest(false);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
verifyNoRedirection();
|
||||||
|
|
||||||
createTestingModule('api/core/getPlatform', 'archive');
|
createTestingModule('docs', mode);
|
||||||
initializeTest(false);
|
initializeTest(false);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
verifyNoRedirection();
|
||||||
});
|
|
||||||
|
|
||||||
it('should not redirect if deployment mode is `next`', () => {
|
createTestingModule('api', mode);
|
||||||
createTestingModule('', 'next');
|
initializeTest(false);
|
||||||
initializeTest(false);
|
verifyNoRedirection();
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('resources', 'next');
|
createTestingModule('api/core/getPlatform', mode);
|
||||||
initializeTest(false);
|
initializeTest(false);
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
verifyNoRedirection();
|
||||||
|
});
|
||||||
createTestingModule('guide/aot-compiler', 'next');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('tutorial', 'next');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('tutorial/toh-pt1', 'next');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('docs', 'next');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('api', 'next');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('api/core/getPlatform', 'next');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not redirect to `docs` if deployment mode is `stable`', () => {
|
|
||||||
createTestingModule('', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('resources', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('guide/aot-compiler', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('tutorial', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('tutorial/toh-pt1', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('docs', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('api', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
createTestingModule('api/core/getPlatform', 'stable');
|
|
||||||
initializeTest(false);
|
|
||||||
expect(TestBed.get(LocationService).replace).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user