File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -267,17 +267,11 @@ function getScoreClass(score) {
267267 return 'low' ;
268268}
269269
270- // 縮短科目名稱
271- export function shortenName ( name ) {
272- const shortNames = {
273- '英語文' : '英文' ,
274- '公民與社會' : '公民' ,
275- '選修化學-物質與能量' : '化學' ,
276- '選修物理-力學一' : '物理' ,
277- '選修化學' : '化學' ,
278- '選修物理' : '物理'
279- } ;
280- return shortNames [ name ] || name ;
270+ // 縮短科目名稱(僅保留 '-' 前的文字)
271+ export function shortenName ( name = '' ) {
272+ const cleanedName = cleanSubjectName ( String ( name ) ) ;
273+ const [ baseName ] = cleanedName . split ( '-' ) ;
274+ return baseName . trim ( ) || cleanedName ;
281275}
282276
283277// 生成五標表格
Original file line number Diff line number Diff line change @@ -17,13 +17,14 @@ describe('dashboard.js', () => {
1717 } ) ;
1818
1919 describe ( 'shortenName' , ( ) => {
20- it ( 'should shorten known subjects ' , ( ) => {
21- assert . equal ( shortenName ( '英語文 ' ) , '英文 ' ) ;
22- assert . equal ( shortenName ( '選修化學-物質與能量 ' ) , '化學 ' ) ;
20+ it ( 'should keep only the text before hyphen ' , ( ) => {
21+ assert . equal ( shortenName ( '選修化學-物質構造與反應速率 ' ) , '選修化學 ' ) ;
22+ assert . equal ( shortenName ( '選修物理-力學二與熱學 ' ) , '選修物理 ' ) ;
2323 } ) ;
2424
25- it ( 'should return original name if unknown ' , ( ) => {
25+ it ( 'should return original name when no hyphen exists ' , ( ) => {
2626 assert . equal ( shortenName ( '數學A' ) , '數學A' ) ;
27+ assert . equal ( shortenName ( '英語文' ) , '英語文' ) ;
2728 } ) ;
2829 } ) ;
2930} ) ;
You can’t perform that action at this time.
0 commit comments