-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make initial camera_position responsive to crystal size
rename prop zoom -> initial_zoom add props min_zoom, max_zoom, orbit_controls add button to download structure as JSON
- Loading branch information
Showing
3 changed files
with
75 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
import { Structure } from '$lib' | ||
import { structures } from '$site' | ||
import { tick } from 'svelte' | ||
import { describe, expect, test } from 'vitest' | ||
import { describe, expect, test, vi } from 'vitest' | ||
import { doc_query } from '.' | ||
|
||
const structure = structures[0] | ||
|
||
describe(`Structure`, () => { | ||
test(`open control panel when clicking toggle button`, async () => { | ||
new Structure({ | ||
target: document.body, | ||
props: { structure: structures[0] }, | ||
}) | ||
new Structure({ target: document.body, props: { structure } }) | ||
|
||
doc_query<HTMLButtonElement>(`button.controls-toggle`).click() | ||
await tick() | ||
|
||
const form = doc_query<HTMLDivElement>(`div.controls form`) | ||
expect(form).not.toBe(null) | ||
}) | ||
|
||
test(`reset view button should reset zoom`, async () => { | ||
const component = new Structure({ | ||
test(`JSON file download when clicking download button`, async () => { | ||
window.URL.createObjectURL = vi.fn() | ||
|
||
new Structure({ | ||
target: document.body, | ||
props: { structure: structures[0] }, | ||
props: { structure }, | ||
}) | ||
const spy = vi.spyOn(document.body, `appendChild`) | ||
|
||
component.zoom = 0.5 | ||
doc_query<HTMLButtonElement>( | ||
`button[title='Download Structure as JSON']` | ||
).click() | ||
await tick() | ||
|
||
expect(component.zoom).toBe(0.5) | ||
doc_query<HTMLButtonElement>(`button.reset-camera`).click() | ||
expect(window.URL.createObjectURL).toHaveBeenCalledOnce() | ||
expect(window.URL.createObjectURL).toHaveBeenCalledWith(expect.any(Blob)) | ||
expect(spy).toHaveBeenCalledOnce() | ||
expect(spy).toHaveBeenCalledWith(expect.any(HTMLAnchorElement)) | ||
|
||
expect(component.zoom).toBe(1 / 50) | ||
spy.mockRestore() | ||
// @ts-expect-error - function is mocked | ||
window.URL.createObjectURL.mockRestore() | ||
}) | ||
}) |