@ncds/ui-admin 1.8.26-alpha.1 → 1.8.26-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ import path from 'node:path';
2
+ import { compile as compileSass } from 'sass';
3
+ import { describe, expect, it } from 'vitest';
4
+ // :-webkit-autofill 은 jsdom 에서 재현할 수 없으므로, 컴파일된 CSS 에서 상태별 규칙을 검사한다.
5
+ // (assets/scripts/dropdown/__tests__/dropdownPortal.test.ts 와 같은 방식 — 컴포넌트 SCSS 엔트리를 직접 컴파일)
6
+ const INPUT_SCSS_PATH = path.resolve(__dirname, '../../../../../assets/styles/components/input-base/_index.scss');
7
+ const compiledInputCss = compileSass(INPUT_SCSS_PATH).css;
8
+ /** 선택자 → 선언 목록. 같은 선택자가 여러 규칙에 나오면 선언을 이어 붙인다. */
9
+ const parseRules = css => {
10
+ const rules = new Map();
11
+ for (const [, selectorList, body] of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
12
+ const declarations = body.split(';').map(declaration => declaration.trim().replace(/\s+/g, ' ')).filter(Boolean);
13
+ for (const selector of selectorList.split(',').map(selector => selector.trim().replace(/\s+/g, ' '))) {
14
+ rules.set(selector, [...(rules.get(selector) ?? []), ...declarations]);
15
+ }
16
+ }
17
+ return rules;
18
+ };
19
+ const rules = parseRules(compiledInputCss);
20
+ const declarationsOf = selector => rules.get(selector) ?? [];
21
+ const AUTOFILL_PSEUDOS = [':-webkit-autofill', ':-webkit-autofill:hover', ':-webkit-autofill:focus', ':-webkit-autofill:active'];
22
+ const ALLOWED_AUTOFILL_PROPERTIES = ['-webkit-box-shadow', '-webkit-text-fill-color', 'caret-color'];
23
+ describe('Input autofill 스타일 — 기본 상태', () => {
24
+ it.each(AUTOFILL_PSEUDOS)('.ncua-input input%s 는 배경 --base-white, 글자·caret --gray-700 이다', pseudo => {
25
+ // Given: 컴파일된 Input CSS 에서
26
+ // When: 기본 상태 autofill 규칙을 찾으면
27
+ const declarations = declarationsOf(`.ncua-input input${pseudo}`);
28
+ // Then: 배경은 흰색 inset box-shadow, 글자·caret 은 기본 글자색이다
29
+ expect(declarations).toContain('-webkit-box-shadow: 0 0 0 30px var(--base-white) inset !important');
30
+ expect(declarations).toContain('-webkit-text-fill-color: var(--gray-700)');
31
+ expect(declarations).toContain('caret-color: var(--gray-700)');
32
+ });
33
+ });
34
+ describe('Input autofill 스타일 — disabled 상태', () => {
35
+ it.each(AUTOFILL_PSEUDOS)('.ncua-input.is-disabled input%s 는 배경 --gray-50, 글자·caret --gray-300 이다', pseudo => {
36
+ // Given: 컴파일된 Input CSS 에서
37
+ // When: disabled 상태 autofill 규칙을 찾으면
38
+ const declarations = declarationsOf(`.ncua-input.is-disabled input${pseudo}`);
39
+ // Then: 배경·글자색이 기존 disabled 스타일과 같다
40
+ expect(declarations).toContain('-webkit-box-shadow: 0 0 0 30px var(--gray-50) inset !important');
41
+ expect(declarations).toContain('-webkit-text-fill-color: var(--gray-300)');
42
+ expect(declarations).toContain('caret-color: var(--gray-300)');
43
+ });
44
+ });
45
+ describe('Input autofill 스타일 — 규칙 범위 제한', () => {
46
+ const autofillSelectors = () => [...rules.keys()].filter(selector => selector.includes(':-webkit-autofill'));
47
+ it('autofill 규칙은 box-shadow·text-fill-color·caret-color 외 속성을 지정하지 않는다', () => {
48
+ // Given: 모든 autofill 선택자가 존재하는 상태에서 (기본 4 + disabled 4)
49
+ const selectors = autofillSelectors();
50
+ expect(selectors).toHaveLength(AUTOFILL_PSEUDOS.length * 2);
51
+ // When/Then: 각 규칙의 속성은 허용 목록 안에 있다 (값·이벤트에 영향 주는 속성 금지)
52
+ for (const selector of selectors) {
53
+ const properties = declarationsOf(selector).map(declaration => declaration.split(':')[0].trim());
54
+ expect(properties.every(property => ALLOWED_AUTOFILL_PROPERTIES.includes(property))).toBe(true);
55
+ }
56
+ });
57
+ it('autofill 규칙에 하드코딩 색상이 없고 CSS 변수만 쓴다', () => {
58
+ // Given/When: autofill 규칙의 선언을 모으면
59
+ const declarations = autofillSelectors().flatMap(declarationsOf);
60
+ // Then: hex·rgb·색 이름 대신 var(--*) 만 쓴다
61
+ expect(declarations.length).toBeGreaterThan(0);
62
+ for (const declaration of declarations) {
63
+ expect(declaration).not.toMatch(/#[0-9a-f]{3,8}\b|rgba?\(|(?<![-\w])white\b/i);
64
+ expect(declaration).toMatch(/var\(--[a-z0-9-]+\)/);
65
+ }
66
+ });
67
+ it('textarea 에는 autofill 규칙을 적용하지 않는다 (ADR-4)', () => {
68
+ // Given/When: autofill 선택자를 모으면
69
+ // Then: textarea 대상 선택자가 없다 (textarea 자체 box-shadow 를 덮어쓰지 않도록)
70
+ expect(autofillSelectors().some(selector => selector.includes('textarea'))).toBe(false);
71
+ });
72
+ });
73
+ describe('Input 기존 상태 스타일 회귀', () => {
74
+ it('기본 input 글자색은 --gray-700 이다', () => {
75
+ expect(declarationsOf('.ncua-input input')).toContain('color: var(--gray-700)');
76
+ });
77
+ it('disabled input 글자색은 --gray-300 이다', () => {
78
+ expect(declarationsOf('.ncua-input.is-disabled input')).toContain('color: var(--gray-300)');
79
+ });
80
+ });
@@ -0,0 +1,91 @@
1
+ import path from 'node:path';
2
+ import { compile as compileSass } from 'sass';
3
+ import { describe, expect, it } from 'vitest';
4
+ // 배경·그림자·패딩은 jsdom 에서 계산되지 않으므로, 컴파일된 CSS 에서 variant 별 규칙을 검사한다.
5
+ // (input-base/__tests__/inputAutofill.test.ts 와 같은 방식 — 컴포넌트 SCSS 엔트리를 직접 컴파일)
6
+ const PAGE_TITLE_SCSS_PATH = path.resolve(__dirname, '../../../../../assets/styles/components/page-title/_index.scss');
7
+ const compiledPageTitleCss = compileSass(PAGE_TITLE_SCSS_PATH).css;
8
+ /** 선택자 → 선언 목록. 같은 선택자가 여러 규칙에 나오면 선언을 이어 붙인다. */
9
+ const parseRules = css => {
10
+ const rules = new Map();
11
+ for (const [, selectorList, body] of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
12
+ const declarations = body.split(';').map(declaration => declaration.trim().replace(/\s+/g, ' ')).filter(Boolean);
13
+ for (const selector of selectorList.split(',').map(selector => selector.trim().replace(/\s+/g, ' '))) {
14
+ rules.set(selector, [...(rules.get(selector) ?? []), ...declarations]);
15
+ }
16
+ }
17
+ return rules;
18
+ };
19
+ const rules = parseRules(compiledPageTitleCss);
20
+ const declarationsOf = selector => rules.get(selector) ?? [];
21
+ const propertiesOf = selector => declarationsOf(selector).map(declaration => declaration.split(':')[0].trim());
22
+ const ROOT = '.ncua-page-title';
23
+ const FIXED = '.ncua-page-title--fixed';
24
+ const PAGE_HEADER = '.ncua-page-title__page-header';
25
+ const FIXED_PAGE_HEADER = '.ncua-page-title--fixed .ncua-page-title__page-header';
26
+ describe('PageTitle 스타일 — Default (·Detail)', () => {
27
+ it('.ncua-page-title 에 background·box-shadow 가 없다 (투명, 그림자 없음)', () => {
28
+ // Given: 컴파일된 PageTitle CSS 에서
29
+ // When: 루트 규칙의 속성을 모으면
30
+ const properties = propertiesOf(ROOT);
31
+ // Then: 루트 규칙은 존재하지만 배경·그림자를 지정하지 않는다
32
+ expect(properties.length).toBeGreaterThan(0);
33
+ expect(properties).not.toContain('background');
34
+ expect(properties).not.toContain('background-color');
35
+ expect(properties).not.toContain('box-shadow');
36
+ });
37
+ it('.ncua-page-title__page-header 패딩은 32px 40px 0 이다', () => {
38
+ // Given: 컴파일된 PageTitle CSS 에서
39
+ // When: page-header 규칙을 찾으면
40
+ const declarations = declarationsOf(PAGE_HEADER);
41
+ // Then: 위 32px · 좌우 40px · 아래 0 이다
42
+ expect(declarations).toContain('padding: 32px 40px 0');
43
+ expect(declarations).not.toContain('padding: 24px 40px');
44
+ });
45
+ });
46
+ describe('PageTitle 스타일 — Fixed (·Fixed Detail)', () => {
47
+ it('.ncua-page-title--fixed 배경은 --gray-50 이다', () => {
48
+ // Given: 컴파일된 PageTitle CSS 에서
49
+ // When: fixed modifier 규칙을 찾으면
50
+ const declarations = declarationsOf(FIXED);
51
+ // Then: sticky 로 콘텐츠 위에 겹치므로 배경 Gray/50 을 가진다
52
+ expect(declarations).toContain('background: var(--gray-50)');
53
+ });
54
+ it('.ncua-page-title--fixed 하단 border 는 1px solid --gray-100 이다', () => {
55
+ // Given/When: fixed modifier 규칙을 찾으면
56
+ const declarations = declarationsOf(FIXED);
57
+ // Then: 기존 Gray/300 이 아니라 Gray/100 border 를 쓴다
58
+ expect(declarations).toContain('border-bottom: 1px solid var(--gray-100)');
59
+ expect(declarations).not.toContain('border-bottom: 1px solid var(--gray-300)');
60
+ });
61
+ it('.ncua-page-title--fixed 에 box-shadow 가 없다', () => {
62
+ // Given/When: fixed modifier 규칙의 속성을 모으면
63
+ // Then: 그림자를 지정하지 않는다
64
+ expect(propertiesOf(FIXED)).not.toContain('box-shadow');
65
+ });
66
+ it('Fixed 의 page-header 패딩은 12px 40px 로 유지된다', () => {
67
+ // Given/When: fixed 하위 page-header 규칙을 찾으면
68
+ // Then: 기존 Fixed 패딩이 그대로다 (범위 밖)
69
+ expect(declarationsOf(FIXED_PAGE_HEADER)).toContain('padding: 12px 40px');
70
+ });
71
+ it('Fixed sticky 동작(position·top·z-index)은 유지된다', () => {
72
+ // Given/When: fixed modifier 규칙을 찾으면
73
+ const declarations = declarationsOf(FIXED);
74
+ // Then: 기존 sticky 선언이 그대로다
75
+ expect(declarations).toContain('position: sticky');
76
+ expect(declarations).toContain('top: 0');
77
+ expect(declarations).toContain('z-index: 999');
78
+ });
79
+ });
80
+ describe('PageTitle 스타일 — 토큰 사용', () => {
81
+ it('배경·border 색상에 하드코딩 값 없이 CSS 변수만 쓴다 (ADR-4)', () => {
82
+ // Given/When: 루트·fixed 규칙의 배경·border 선언을 모으면
83
+ const colorDeclarations = [...declarationsOf(ROOT), ...declarationsOf(FIXED)].filter(declaration => /^(background|border-bottom)/.test(declaration));
84
+ // Then: hex·rgb·색 이름 대신 var(--*) 만 쓴다
85
+ expect(colorDeclarations.length).toBeGreaterThan(0);
86
+ for (const declaration of colorDeclarations) {
87
+ expect(declaration).not.toMatch(/#[0-9a-f]{3,8}\b|rgba?\(|(?<![-\w])white\b/i);
88
+ expect(declaration).toMatch(/var\(--[a-z0-9-]+\)/);
89
+ }
90
+ });
91
+ });