diff --git a/jig-core/src/test/js/glossary.test.js b/jig-core/src/test/js/glossary.test.js index f13dd8906..9893b6183 100644 --- a/jig-core/src/test/js/glossary.test.js +++ b/jig-core/src/test/js/glossary.test.js @@ -44,81 +44,83 @@ function setupDocument() { return doc; } -test.describe('glossary.js 絞り込み', () => { - test('種類・説明有無・検索語でフィルタする', () => { - const terms = [ - {title: 'Account', description: 'desc', kind: 'クラス'}, - {title: 'Order', description: '', kind: 'クラス'}, - {title: 'Repo', description: 'data', kind: 'パッケージ'}, - {title: 'Submit', description: 'action', kind: 'メソッド'}, - ]; - const controls = { - showEmptyDescription: {checked: false}, - showPackage: {checked: false}, - showClass: {checked: true}, - showMethod: {checked: true}, - showField: {checked: true}, - searchInput: {value: 'acc'}, - }; - - const result = glossary.getFilteredTerms(terms, controls); - - assert.deepEqual(result, [terms[0]]); +test.describe('glossary.js', () => { + test.describe('絞り込み', () => { + test('種類・説明有無・検索語でフィルタする', () => { + const terms = [ + {title: 'Account', description: 'desc', kind: 'クラス'}, + {title: 'Order', description: '', kind: 'クラス'}, + {title: 'Repo', description: 'data', kind: 'パッケージ'}, + {title: 'Submit', description: 'action', kind: 'メソッド'}, + ]; + const controls = { + showEmptyDescription: {checked: false}, + showPackage: {checked: false}, + showClass: {checked: true}, + showMethod: {checked: true}, + showField: {checked: true}, + searchInput: {value: 'acc'}, + }; + + const result = glossary.getFilteredTerms(terms, controls); + + assert.deepEqual(result, [terms[0]]); + }); }); -}); -test.describe('glossary.js CSV', () => { - test('CSV値はクォートし、改行とダブルクォートを処理する', () => { - const value = '"a"\r\nline'; + test.describe('CSV', () => { + test('CSV値はクォートし、改行とダブルクォートを処理する', () => { + const value = '"a"\r\nline'; - const escaped = glossary.escapeCsvValue(value); + const escaped = glossary.escapeCsvValue(value); - assert.equal(escaped, '"""a""\nline"'); - }); + assert.equal(escaped, '"""a""\nline"'); + }); - test('CSVにヘッダーと行を出力する', () => { - const terms = [ - {simpleText: 'Account', title: '口座', description: 'desc', kind: 'クラス', fqn: 'app.Account'}, - ]; + test('CSVにヘッダーと行を出力する', () => { + const terms = [ + {simpleText: 'Account', title: '口座', description: 'desc', kind: 'クラス', fqn: 'app.Account'}, + ]; - const csv = glossary.buildGlossaryCsv(terms); + const csv = glossary.buildGlossaryCsv(terms); - assert.equal( - csv, - '"用語(英名)","用語","説明","種類","識別子"\r\n' + - '"Account","口座","desc","クラス","app.Account"' - ); + assert.equal( + csv, + '"用語(英名)","用語","説明","種類","識別子"\r\n' + + '"Account","口座","desc","クラス","app.Account"' + ); + }); }); -}); -test.describe('glossary.js データ読み込み', () => { - test('glossary-dataから用語一覧を取得する', () => { - const doc = setupDocument(); - const dataElement = new Element('script'); - dataElement.textContent = JSON.stringify({terms: [{title: 'Account'}]}); - doc.elementsById.set('glossary-data', dataElement); + test.describe('データ読み込み', () => { + test('glossary-dataから用語一覧を取得する', () => { + const doc = setupDocument(); + const dataElement = new Element('script'); + dataElement.textContent = JSON.stringify({terms: [{title: 'Account'}]}); + doc.elementsById.set('glossary-data', dataElement); - const terms = glossary.getGlossaryData(); + const terms = glossary.getGlossaryData(); - assert.equal(terms.length, 1); - assert.equal(terms[0].title, 'Account'); + assert.equal(terms.length, 1); + assert.equal(terms[0].title, 'Account'); + }); }); -}); -test.describe('glossary.js 描画', () => { - test('用語一覧をDOMに描画する', () => { - const doc = setupDocument(); - const list = new Element('div'); - list.innerHTML = 'existing'; - doc.elementsById.set('term-list', list); - - glossary.renderGlossaryTerms([ - {title: 'Account', simpleText: 'Account', fqn: 'app.Account', kind: 'クラス', description: 'desc'}, - {title: 'Order', simpleText: 'Order', fqn: 'app.Order', kind: 'クラス', description: ''}, - ]); - - assert.equal(list.innerHTML, ''); - assert.equal(list.children.length, 1); - assert.equal(list.children[0].children.length, 2); + test.describe('描画', () => { + test('用語一覧をDOMに描画する', () => { + const doc = setupDocument(); + const list = new Element('div'); + list.innerHTML = 'existing'; + doc.elementsById.set('term-list', list); + + glossary.renderGlossaryTerms([ + {title: 'Account', simpleText: 'Account', fqn: 'app.Account', kind: 'クラス', description: 'desc'}, + {title: 'Order', simpleText: 'Order', fqn: 'app.Order', kind: 'クラス', description: ''}, + ]); + + assert.equal(list.innerHTML, ''); + assert.equal(list.children.length, 1); + assert.equal(list.children[0].children.length, 2); + }); }); }); diff --git a/jig-core/src/test/js/insight.test.js b/jig-core/src/test/js/insight.test.js index 51eda8073..48d3e7c93 100644 --- a/jig-core/src/test/js/insight.test.js +++ b/jig-core/src/test/js/insight.test.js @@ -57,144 +57,288 @@ function buildInsightTables(doc) { return {packageTbody, typeTbody, methodTbody}; } -test.describe('insight.js JSON読み込み', () => { - test('データ要素がない場合はnull', () => { - setupDocument(); +test.describe('insight.js', () => { - assert.equal(insight.parseInsightData(), null); - }); - - test('insight-dataからJSONを取得する', () => { - const doc = setupDocument(); - const dataElement = new Element('script'); - dataElement.textContent = JSON.stringify({packages: [{fqn: 'app'}]}); - doc.elementsById.set('insight-data', dataElement); + test.describe('JSON読み込み', () => { - const result = insight.parseInsightData(); + test('データ要素がない場合はnull', () => { - assert.equal(result.packages[0].fqn, 'app'); - }); + setupDocument(); - test('不正なJSONの場合はnullを返す', () => { - const doc = setupDocument(); - const dataElement = new Element('script'); - dataElement.textContent = '{bad json'; - doc.elementsById.set('insight-data', dataElement); - let logged = false; - const originalError = console.error; - console.error = () => { - logged = true; - }; - try { assert.equal(insight.parseInsightData(), null); - assert.equal(logged, true); - } finally { - console.error = originalError; - } - }); -}); -test.describe('insight.js 表示部品', () => { - test('件数表示は対象要素に文字列で書き込む', () => { - const doc = setupDocument(); - const target = new Element('span'); - doc.elementsById.set('package-count', target); + }); - insight.setInsightCount('package-count', 12); - assert.equal(target.textContent, '12'); - }); - test('テーブルセルはテキストとクラス名を設定する', () => { - setupDocument(); - const cell = insight.createCell('Hello', 'number'); + test('insight-dataからJSONを取得する', () => { - assert.equal(cell.tagName, 'td'); - assert.equal(cell.textContent, 'Hello'); - assert.equal(cell.className, 'number'); - }); + const doc = setupDocument(); - test('ズームセルはアイコンを追加する', () => { - setupDocument(); - const cell = insight.createZoomCell(); + const dataElement = new Element('script'); - assert.equal(cell.tagName, 'td'); - assert.equal(cell.children.length, 1); - assert.equal(cell.children[0].tagName, 'i'); - assert.equal(cell.children[0].className, 'zoom'); - }); -}); + dataElement.textContent = JSON.stringify({packages: [{fqn: 'app'}]}); + + doc.elementsById.set('insight-data', dataElement); + + + + const result = insight.parseInsightData(); + + + + assert.equal(result.packages[0].fqn, 'app'); + + }); + + + + test('不正なJSONの場合はnullを返す', () => { + + const doc = setupDocument(); + + const dataElement = new Element('script'); + + dataElement.textContent = '{bad json'; + + doc.elementsById.set('insight-data', dataElement); + + + + let logged = false; + + const originalError = console.error; + + console.error = () => { + + logged = true; + + }; + + + + try { + + assert.equal(insight.parseInsightData(), null); + + assert.equal(logged, true); + + } finally { + + console.error = originalError; + + } + + }); -test.describe('insight.js テーブル描画', () => { - test('パッケージ一覧を描画する', () => { - const doc = setupDocument(); - const {packageTbody} = buildInsightTables(doc); - - insight.renderPackageInsights([ - { - fqn: 'app', - label: 'App', - numberOfTypes: 3, - numberOfMethods: 5, - numberOfUsingTypes: 2, - cyclomaticComplexity: 9, - size: 11, - }, - ]); - - assert.equal(packageTbody.children.length, 1); - const row = packageTbody.children[0]; - assert.equal(row.dataset.fqn, 'app'); - assert.equal(row.children[1].textContent, 'app'); - assert.equal(row.children[2].textContent, 'App'); }); - test('型一覧を描画する', () => { - const doc = setupDocument(); - const {typeTbody} = buildInsightTables(doc); - - insight.renderTypeInsights([ - { - fqn: 'app.Type', - packageFqn: 'app', - label: 'Type', - numberOfMethods: 1, - numberOfUsingTypes: 4, - cyclomaticComplexity: 2, - size: 5, - }, - ]); - - assert.equal(typeTbody.children.length, 1); - const row = typeTbody.children[0]; - assert.equal(row.dataset.fqn, 'app.Type'); - assert.equal(row.dataset.packageFqn, 'app'); + + + test.describe('表示部品', () => { + + test('件数表示は対象要素に文字列で書き込む', () => { + + const doc = setupDocument(); + + const target = new Element('span'); + + doc.elementsById.set('package-count', target); + + + + insight.setInsightCount('package-count', 12); + + + + assert.equal(target.textContent, '12'); + + }); + + + + test('テーブルセルはテキストとクラス名を設定する', () => { + + setupDocument(); + + const cell = insight.createCell('Hello', 'number'); + + + + assert.equal(cell.tagName, 'td'); + + assert.equal(cell.textContent, 'Hello'); + + assert.equal(cell.className, 'number'); + + }); + + + + test('ズームセルはアイコンを追加する', () => { + + setupDocument(); + + const cell = insight.createZoomCell(); + + + + assert.equal(cell.tagName, 'td'); + + assert.equal(cell.children.length, 1); + + assert.equal(cell.children[0].tagName, 'i'); + + assert.equal(cell.children[0].className, 'zoom'); + + }); + }); - test('メソッド一覧を描画する', () => { - const doc = setupDocument(); - const {methodTbody} = buildInsightTables(doc); - - insight.renderMethodInsights([ - { - fqn: 'app.Type#method', - packageFqn: 'app', - typeFqn: 'app.Type', - label: 'method', - cyclomaticComplexity: 1, - numberOfUsingTypes: 1, - numberOfUsingMethods: 2, - numberOfUsingFields: 0, - size: 3, - }, - ]); - - assert.equal(methodTbody.children.length, 1); - const row = methodTbody.children[0]; - assert.equal(row.dataset.fqn, 'app.Type#method'); - assert.equal(row.dataset.packageFqn, 'app'); - assert.equal(row.dataset.typeFqn, 'app.Type'); + + + test.describe('テーブル描画', () => { + + test('パッケージ一覧を描画する', () => { + + const doc = setupDocument(); + + const {packageTbody} = buildInsightTables(doc); + + + + insight.renderPackageInsights([ + + { + + fqn: 'app', + + label: 'App', + + numberOfTypes: 3, + + numberOfMethods: 5, + + numberOfUsingTypes: 2, + + cyclomaticComplexity: 9, + + size: 11, + + }, + + ]); + + + + assert.equal(packageTbody.children.length, 1); + + const row = packageTbody.children[0]; + + assert.equal(row.dataset.fqn, 'app'); + + assert.equal(row.children[1].textContent, 'app'); + + assert.equal(row.children[2].textContent, 'App'); + + }); + + + + test('型一覧を描画する', () => { + + const doc = setupDocument(); + + const {typeTbody} = buildInsightTables(doc); + + + + insight.renderTypeInsights([ + + { + + fqn: 'app.Type', + + packageFqn: 'app', + + label: 'Type', + + numberOfMethods: 1, + + numberOfUsingTypes: 4, + + cyclomaticComplexity: 2, + + size: 5, + + }, + + ]); + + + + assert.equal(typeTbody.children.length, 1); + + const row = typeTbody.children[0]; + + assert.equal(row.dataset.fqn, 'app.Type'); + + assert.equal(row.dataset.packageFqn, 'app'); + + }); + + + + test('メソッド一覧を描画する', () => { + + const doc = setupDocument(); + + const {methodTbody} = buildInsightTables(doc); + + + + insight.renderMethodInsights([ + + { + + fqn: 'app.Type#method', + + packageFqn: 'app', + + typeFqn: 'app.Type', + + label: 'method', + + cyclomaticComplexity: 1, + + numberOfUsingTypes: 1, + + numberOfUsingMethods: 2, + + numberOfUsingFields: 0, + + size: 3, + + }, + + ]); + + + + assert.equal(methodTbody.children.length, 1); + + const row = methodTbody.children[0]; + + assert.equal(row.dataset.fqn, 'app.Type#method'); + + assert.equal(row.dataset.packageFqn, 'app'); + + assert.equal(row.dataset.typeFqn, 'app.Type'); + + }); + }); + }); diff --git a/jig-core/src/test/js/list-output.test.js b/jig-core/src/test/js/list-output.test.js index b35e3ef7d..cfd5e562b 100644 --- a/jig-core/src/test/js/list-output.test.js +++ b/jig-core/src/test/js/list-output.test.js @@ -87,7 +87,7 @@ function setupDocument() { } -test.describe('listOutput', () => { +test.describe('list-output.js', () => { test.describe('CSV', () => { test.describe('escapeCsvValue', () => { test('CSV値はクォートし、改行とダブルクォートを処理する', () => {