-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
856 additions
and
290 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
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
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
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
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
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,56 @@ | ||
import PeriodicTable from '$lib/PeriodicTable.svelte' | ||
import { beforeEach, describe, expect, test } from 'vitest' | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = `` | ||
}) | ||
|
||
async function sleep(ms = 1) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} | ||
|
||
describe(`PeriodicTable`, () => { | ||
test(`renders element tiles`, async () => { | ||
new PeriodicTable({ target: document.body }) | ||
|
||
const element_tiles = document.querySelectorAll(`.element-tile`) | ||
expect(element_tiles.length).toBe(118) | ||
}) | ||
|
||
test(`has no text content when symbols, names and numbers are disabled`, async () => { | ||
new PeriodicTable({ | ||
target: document.body, | ||
props: { | ||
show_symbols: false, | ||
show_names: false, | ||
show_numbers: false, | ||
// style: `width: 500px; height: 100px;`, | ||
}, | ||
}) | ||
|
||
const ptable = document.querySelector(`.periodic-table`) | ||
|
||
expect(ptable?.textContent?.trim()).toBe(``) | ||
|
||
// make sure empty tiles are still rendered | ||
const symbol_tiles = document.querySelectorAll(`.element-tile`) | ||
expect(symbol_tiles.length).toBe(118) | ||
}) | ||
|
||
test(`hovered element tile has border`, async () => { | ||
new PeriodicTable({ target: document.body }) | ||
|
||
const element_tile = document.querySelector(`.element-tile`) | ||
if (!element_tile) { | ||
throw new Error(`No element tile found`) | ||
} | ||
|
||
element_tile?.dispatchEvent(new MouseEvent(`mouseenter`)) | ||
await sleep() | ||
expect([...element_tile.classList]).toContain(`active`) | ||
|
||
element_tile?.dispatchEvent(new MouseEvent(`mouseleave`)) | ||
await sleep() | ||
expect([...element_tile.classList]).not.toContain(`active`) | ||
}) | ||
}) |
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
Oops, something went wrong.