refactor(aio): rename DocumentContents url
to id
and tidy up (#16139)
Dgeni is now providing the `id` for all the documents to be viewed. So we no longer need to add this to the DocumentContents object. There are some notable changes in the refactoring: `DocumentService`: * The id of the document to render is now obtained from `LocationService.path()`. * The `getFileNotFoundDoc` and `getErrorDoc` methods have been extracted from the `fetchDocument` method. `AppComponent`: * the `pageId` is now computed in a separate `setPageId` method. `AppComponen` spec file: * The `TestHttp` has had the hard coded documents removed and replaced with a function that will generate docs as needed.
This commit is contained in:

committed by
Miško Hevery

parent
d0dcabd700
commit
5e6a3ff6a7
@ -122,23 +122,23 @@ describe('DocViewerComponent', () => {
|
||||
});
|
||||
|
||||
it(('should display nothing when set currentDoc has no content'), () => {
|
||||
component.currentDoc = { title: 'fake title', contents: '', url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents: '', id: 'a/b' };
|
||||
fixture.detectChanges();
|
||||
expect(docViewerEl.innerHTML).toBe('');
|
||||
});
|
||||
|
||||
it(('should display simple static content doc'), () => {
|
||||
const contents = '<p>Howdy, doc viewer</p>';
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
fixture.detectChanges();
|
||||
expect(docViewerEl.innerHTML).toEqual(contents);
|
||||
});
|
||||
|
||||
it(('should display nothing after reset static content doc'), () => {
|
||||
const contents = '<p>Howdy, doc viewer</p>';
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
fixture.detectChanges();
|
||||
component.currentDoc = { title: 'fake title', contents: '', url: 'a/c' };
|
||||
component.currentDoc = { title: 'fake title', contents: '', id: 'a/c' };
|
||||
fixture.detectChanges();
|
||||
expect(docViewerEl.innerHTML).toEqual('');
|
||||
});
|
||||
@ -149,7 +149,7 @@ describe('DocViewerComponent', () => {
|
||||
<p><aio-foo></aio-foo></p>
|
||||
<p>Below Foo</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
fixture.detectChanges();
|
||||
const fooHtml = docViewerEl.querySelector('aio-foo').innerHTML;
|
||||
expect(fooHtml).toContain('Foo Component');
|
||||
@ -165,7 +165,7 @@ describe('DocViewerComponent', () => {
|
||||
</div>
|
||||
<p>Below Foo</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
fixture.detectChanges();
|
||||
const foos = docViewerEl.querySelectorAll('aio-foo');
|
||||
expect(foos.length).toBe(2);
|
||||
@ -177,7 +177,7 @@ describe('DocViewerComponent', () => {
|
||||
<aio-bar></aio-bar>
|
||||
<p>Below Bar</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
fixture.detectChanges();
|
||||
const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
||||
expect(barHtml).toContain('Bar Component');
|
||||
@ -189,7 +189,7 @@ describe('DocViewerComponent', () => {
|
||||
<aio-bar>###bar content###</aio-bar>
|
||||
<p>Below Bar</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
|
||||
// necessary to trigger projection within ngOnInit
|
||||
fixture.detectChanges();
|
||||
@ -207,7 +207,7 @@ describe('DocViewerComponent', () => {
|
||||
<p><aio-foo></aio-foo></p>
|
||||
<p>Bottom</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
|
||||
// necessary to trigger Bar's projection within ngOnInit
|
||||
fixture.detectChanges();
|
||||
@ -230,7 +230,7 @@ describe('DocViewerComponent', () => {
|
||||
<p><aio-foo></aio-foo><p>
|
||||
<p>Bottom</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
|
||||
// necessary to trigger Bar's projection within ngOnInit
|
||||
fixture.detectChanges();
|
||||
@ -254,7 +254,7 @@ describe('DocViewerComponent', () => {
|
||||
<p><aio-foo></aio-foo></p>
|
||||
<p>Bottom</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
|
||||
// necessary to trigger Bar's projection within ngOnInit
|
||||
fixture.detectChanges();
|
||||
@ -282,7 +282,7 @@ describe('DocViewerComponent', () => {
|
||||
<p><aio-baz>---More baz--</aio-baz></p>
|
||||
<p>Bottom</p>
|
||||
`;
|
||||
component.currentDoc = { title: 'fake title', contents, url: 'a/b' };
|
||||
component.currentDoc = { title: 'fake title', contents, id: 'a/b' };
|
||||
|
||||
// necessary to trigger Bar's projection within ngOnInit
|
||||
fixture.detectChanges();
|
||||
|
Reference in New Issue
Block a user