-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(extract-selectors): create test suite for
extractSelectors
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { extractSelectors } from "../scripts/extract-selectors"; | ||
|
||
describe("extractSelectors", () => { | ||
test("extracts single class from class attribute", () => { | ||
const result = extractSelectors({ | ||
code: '<div class="test-class"></div>', | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".test-class"]); | ||
}); | ||
|
||
test("extracts multiple classes from class attribute", () => { | ||
const result = extractSelectors({ | ||
code: '<div class="class1 class2 class3"></div>', | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".class1", ".class2", ".class3"]); | ||
}); | ||
|
||
test("extracts class directives", () => { | ||
const result = extractSelectors({ | ||
code: "<div class:active={isActive}></div>", | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".active"]); | ||
}); | ||
|
||
test("extracts global selectors", () => { | ||
const result = extractSelectors({ | ||
code: "<style>:global(div) { color: red; }</style>", | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".div"]); | ||
}); | ||
|
||
test("handles Carbon prefix classes", () => { | ||
const result = extractSelectors({ | ||
code: '<div class="bx--button bx--text"></div>', | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".bx--button", ".bx--text"]); | ||
}); | ||
|
||
test("deduplicates repeated classes", () => { | ||
const result = extractSelectors({ | ||
code: '<div class="test test test"></div>', | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".test"]); | ||
}); | ||
|
||
test("handles mixed scenarios", () => { | ||
const result = extractSelectors({ | ||
code: ` | ||
<div class="regular-class bx--carbon-class"> | ||
<span class:active={isActive}></span> | ||
<style>:global(body) { margin: 0; }</style> | ||
</div> | ||
`, | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([".regular-class", ".bx--carbon-class", ".active"]); | ||
}); | ||
|
||
test("handles empty class attributes", () => { | ||
const result = extractSelectors({ | ||
code: '<div class=""></div>', | ||
filename: "test.svelte", | ||
}); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |