-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1234 from rainlanguage/2025-02-04-bindings-fix-ra…
…inlang-component Add component to show rainlang and fix scenario binding update function
- Loading branch information
Showing
7 changed files
with
188 additions
and
56 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
34 changes: 34 additions & 0 deletions
34
packages/ui-components/src/__tests__/ComposedRainlangModal.test.ts
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,34 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { render, fireEvent, waitFor } from '@testing-library/svelte'; | ||
import ComposedRainlangModal from '../lib/components/deployment/ComposedRainlangModal.svelte'; | ||
|
||
vi.mock('svelte-codemirror-editor', async () => { | ||
const mockCodeMirror = (await import('../lib/__mocks__/MockComponent.svelte')).default; | ||
return { default: mockCodeMirror }; | ||
}); | ||
|
||
describe('ComposedRainlangModal', () => { | ||
let composeRainlangMock: ReturnType<typeof vi.fn>; | ||
|
||
beforeEach(() => { | ||
composeRainlangMock = vi.fn(() => Promise.resolve('mocked rainlang text')); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should open modal and display rainlang text when button is clicked', async () => { | ||
const { getByText, getByTestId } = render(ComposedRainlangModal, { | ||
props: { | ||
composeRainlang: composeRainlangMock, | ||
codeMirrorStyles: {} | ||
} | ||
}); | ||
|
||
const button = getByText('Show Rainlang'); | ||
await fireEvent.click(button); | ||
|
||
await waitFor(() => { | ||
expect(composeRainlangMock).toHaveBeenCalled(); | ||
expect(getByTestId('modal')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/ui-components/src/lib/components/deployment/ComposedRainlangModal.svelte
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,40 @@ | ||
<script lang="ts"> | ||
import CodeMirror from 'svelte-codemirror-editor'; | ||
import { RainlangLR } from 'codemirror-rainlang'; | ||
import { lightCodeMirrorTheme } from '../../utils/codeMirrorThemes'; | ||
import { Button, Modal } from 'flowbite-svelte'; | ||
export let composeRainlang: () => Promise<string | undefined>; | ||
export let codeMirrorStyles = {}; | ||
let rainlangText: string | null = null; | ||
let open = false; | ||
async function generateRainlang() { | ||
const rainlang = await composeRainlang(); | ||
if (rainlang) { | ||
rainlangText = rainlang; | ||
open = true; | ||
} | ||
} | ||
</script> | ||
|
||
<Button size="lg" on:click={generateRainlang}>Show Rainlang</Button> | ||
|
||
<Modal size="xl" class="bg-opacity-90 backdrop-blur-sm" bind:open data-testid="modal"> | ||
<div data-testid="modal-content"> | ||
<CodeMirror | ||
value={rainlangText} | ||
extensions={[RainlangLR]} | ||
theme={lightCodeMirrorTheme} | ||
readonly={true} | ||
styles={{ | ||
'&': { | ||
height: '70vh', | ||
width: '70vw' | ||
}, | ||
...codeMirrorStyles | ||
}} | ||
/> | ||
</div> | ||
</Modal> |
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