Skip to content

Commit

Permalink
Use eslint to force exclusive tests outta here
Browse files Browse the repository at this point in the history
  • Loading branch information
Auroratide committed Feb 18, 2024
1 parent 7921154 commit de41159
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 52 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ module.exports = {
"plugin:svelte/recommended",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
plugins: ["@typescript-eslint", "mocha"],
rules: {
"indent": ["error", "tab"],
"indent": ["error", "tab", { "SwitchCase": 1 }],
"quotes": ["error", "double"],
"comma-dangle": ["error", "always-multiline"],
"semi": ["error", "never"],
"@typescript-eslint/no-non-null-assertion": "off",
"svelte/no-at-html-tags": "off",
"no-console": ["error"],
"mocha/no-skipped-tests": "warn",
"mocha/no-exclusive-tests": "error",
},
parserOptions: {
sourceType: "module",
Expand Down
16 changes: 15 additions & 1 deletion components/flip-card/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("flip-card", () => {
})

describe("focus", () => {
it.only("skip button on non-visible side", async () => {
it("skip button on non-visible side", async () => {
const container = await fixture(`
<div>
<button id="start">Start</button>
Expand Down Expand Up @@ -195,6 +195,13 @@ const pressTab = () => {
if (index > -1) {
const nextElement = tabOrder[index + 1] || tabOrder[0]
nextElement.focus()
} else {
const allNodes = getAllNodes()
const index = allNodes.indexOf(document.activeElement)
if (index > -1) {
const nextElement = allNodes.slice(index + 1).find((node) => tabOrder.includes(node))
nextElement?.focus()
}
}
}

Expand Down Expand Up @@ -222,3 +229,10 @@ const isInteractive = (element) => {
!element.inert
)
}

const getAllNodes = (node = document.body, nodes = []) => {
nodes.push(node)
nodes.push(...(Array.from(node.childNodes ?? []).map((node) => getAllNodes(node, nodes))))

return nodes.filter((node) => node?.nodeType === Node.ELEMENT_NODE)
}
98 changes: 49 additions & 49 deletions components/toggle-switch/src/toggle-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ export class ToggleSwitchElement extends HTMLElement {
static defaultElementName = "toggle-switch"

static html = `
<span part="track">
<span part="slider"></span>
</span>
`
<span part="track">
<span part="slider"></span>
</span>
`

static css = `
:host {
display: inline-block;
width: 2em;
height: 1em;
cursor: pointer;
}
span {
box-sizing: border-box;
display: inline-block;
line-height: 1;
}
[part="track"] {
width: 100%;
height: 100%;
background-color: #dddddd;
text-align: left;
transition: all 0.256s;
}
[part="slider"] {
width: 50%;
height: 100%;
background-color: #777777;
transition: all 0.256s;
vertical-align: text-top;
}
:host([checked]) [part="slider"] {
transform: translateX(100%);
}
:host([disabled]) {
cursor: not-allowed;
opacity: 0.5;
}
`
:host {
display: inline-block;
width: 2em;
height: 1em;
cursor: pointer;
}
span {
box-sizing: border-box;
display: inline-block;
line-height: 1;
}
[part="track"] {
width: 100%;
height: 100%;
background-color: #dddddd;
text-align: left;
transition: all 0.256s;
}
[part="slider"] {
width: 50%;
height: 100%;
background-color: #777777;
transition: all 0.256s;
vertical-align: text-top;
}
:host([checked]) [part="slider"] {
transform: translateX(100%);
}
:host([disabled]) {
cursor: not-allowed;
opacity: 0.5;
}
`

static formAssociated = true

Expand Down Expand Up @@ -104,13 +104,13 @@ export class ToggleSwitchElement extends HTMLElement {

#onKeyDown = (e) => {
switch(e.key) {
case " ":
case "Enter":
e.preventDefault()
this.toggle()
break
default:
break
case " ":
case "Enter":
e.preventDefault()
this.toggle()
break
default:
break
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@typescript-eslint/parser": "^6.21.0",
"commander": "^9.5.0",
"eslint": "^8.56.0",
"eslint-plugin-mocha": "^10.3.0",
"eslint-plugin-svelte": "^2.35.1",
"fs-extra": "^10.1.0",
"npm-run-all": "^4.1.5"
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de41159

Please sign in to comment.