| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | const path = require('path'); | 
					
						
							|  |  |  | const { expect } = require('chai'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { createNavigationNode } = require('./create-navigation-node'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('fcc-create-nav-data', () => { | 
					
						
							|  |  |  |   describe('create-vanigation-node', () => { | 
					
						
							|  |  |  |     const mockNode = { | 
					
						
							|  |  |  |       internal: { | 
					
						
							|  |  |  |         content: | 
					
						
							|  |  |  |           '---\ntitle: File Writing\n---\n## File Writing\n\nThis is a stub.' + | 
					
						
							| 
									
										
										
										
											2019-02-19 15:19:49 +05:30
										 |  |  |           " <a href='https://github.com/freeCodeCamp/guides/tree/master/src/" + | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |           "pages/php/functions/files/writing/index.md' target='_blank' " + | 
					
						
							|  |  |  |           "rel='nofollow'>Help our community expand it</a>.\n\n<a href=" + | 
					
						
							| 
									
										
										
										
											2019-02-19 15:19:49 +05:30
										 |  |  |           "'https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md' " + | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |           "target='_blank' rel='nofollow'>This quick style guide will help " + | 
					
						
							|  |  |  |           'ensure your pull request gets accepted</a>.\n\n<!-- The article ' + | 
					
						
							|  |  |  |           'goes here, in GitHub-flavored Markdown. Feel free to add YouTube ' + | 
					
						
							|  |  |  |           'videos, images, and CodePen/JSBin embeds  -->\n\n#### More ' + | 
					
						
							|  |  |  |           'Information:\n<!-- Please add any articles you think might be ' + | 
					
						
							|  |  |  |           'helpful to read before writing the article -->\n' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       frontmatter: { | 
					
						
							|  |  |  |         title: 'File Writing' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       fileAbsolutePath: path.resolve( | 
					
						
							|  |  |  |         __dirname, | 
					
						
							| 
									
										
										
										
											2018-10-23 14:18:46 +01:00
										 |  |  |         '../../../mock-guide/english/php/functions/files/file-writing/index.md' | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  |       ) | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = createNavigationNode(mockNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should return an object', () => { | 
					
						
							|  |  |  |       expect(result).to.be.an('object'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('node.children should be an array', () => { | 
					
						
							|  |  |  |       expect(result.categoryChildren).to.be.an('array'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('node.dashedName should equal the containing folder name', () => { | 
					
						
							|  |  |  |       expect(result.dashedName).equal('file-writing'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-16 08:20:53 +00:00
										 |  |  |     it( | 
					
						
							|  |  |  |       'node.path should equal the file path from pagesDir, ' + | 
					
						
							|  |  |  |         'prefixed with `/guide`', | 
					
						
							|  |  |  |       () => { | 
					
						
							|  |  |  |         expect(result.path).to.equal('/guide/php/functions/files/file-writing'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-16 08:20:53 +00:00
										 |  |  |     it( | 
					
						
							|  |  |  |       'node.parentPath should equal the path of the parent page, ' + | 
					
						
							|  |  |  |         'prefixed with `/guide`', | 
					
						
							|  |  |  |       () => { | 
					
						
							|  |  |  |         expect(result.parentPath).to.equal('/guide/php/functions/files'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2018-10-04 14:47:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('node.title should equal srcNode.frontmatter.title', () => { | 
					
						
							|  |  |  |       expect(result.title).to.equal(mockNode.frontmatter.title); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('node.isStubbed should be a boolean', () => { | 
					
						
							|  |  |  |       expect(result.isStubbed).to.be.a('boolean'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('node.isStubbed should be true for a stubbed article', () => { | 
					
						
							|  |  |  |       expect(result.isStubbed).to.equal(true); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('node.isStubbed should be false for a non-stubbed article', () => { | 
					
						
							|  |  |  |       const notAStub = { | 
					
						
							|  |  |  |         ...mockNode, | 
					
						
							|  |  |  |         internal: { | 
					
						
							|  |  |  |           content: 'this is not a stub article. Infact, it is very informative' | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       const result = createNavigationNode(notAStub); | 
					
						
							|  |  |  |       expect(result.isStubbed).to.equal(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |