-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: test the deploy app flow (#252)
- Loading branch information
1 parent
f6b52c0
commit 27e2ff8
Showing
24 changed files
with
472 additions
and
142 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
110 changes: 110 additions & 0 deletions
110
src/features/app-interfaces/components/create-app-interface-dialog-body.test.tsx
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,110 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest' | ||
import { executeComponentTest } from '@/tests/test-component' | ||
import SampleSixAppSpec from '@/tests/test-app-specs/sample-six.arc32.json' | ||
import { fireEvent, getByLabelText, getByText, render, waitFor } from '@/tests/testing-library' | ||
import { Arc32AppSpec } from '../data/types' | ||
import { deployAppLabel, deployButtonLabel } from '@/features/app-interfaces/components/labels' | ||
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing' | ||
import { CreateAppInterfaceDialogBody } from '@/features/app-interfaces/components/create-app-interface-dialog-body' | ||
import { selectOption } from '@/tests/utils/select-option' | ||
import { setWalletAddressAndSigner } from '@/tests/utils/set-wallet-address-and-signer' | ||
|
||
describe('create-app-interface-dialog-body', () => { | ||
const localnet = algorandFixture() | ||
beforeEach(localnet.beforeEach, 10e6) | ||
afterEach(() => { | ||
vitest.clearAllMocks() | ||
}) | ||
|
||
describe('when deploying an app spec that requires template parameters', () => { | ||
const appSpec = SampleSixAppSpec as Arc32AppSpec | ||
|
||
beforeEach(async () => { | ||
await setWalletAddressAndSigner(localnet) | ||
}) | ||
|
||
it('succeeds when all fields have been correctly supplied', () => { | ||
return executeComponentTest( | ||
() => { | ||
return render(<CreateAppInterfaceDialogBody onSuccess={() => {}} />) | ||
}, | ||
async (component, user) => { | ||
const appSpecFileInput = await component.findByLabelText(/JSON app spec file/) | ||
await user.upload(appSpecFileInput, new File([JSON.stringify(appSpec)], 'app.json', { type: 'application/json' })) | ||
|
||
const deployAppButton = await waitFor(() => { | ||
const button = component.getByRole('button', { name: deployAppLabel }) | ||
expect(button).toBeDefined() | ||
expect(button).not.toBeDisabled() | ||
return button! | ||
}) | ||
await user.click(deployAppButton) | ||
|
||
const versionInput = await waitFor(() => { | ||
const input = component.getByLabelText(/Version/) | ||
expect(input).toBeDefined() | ||
return input! | ||
}) | ||
fireEvent.input(versionInput, { | ||
target: { value: '1.0.0' }, | ||
}) | ||
|
||
await selectOption(component.container, user, /On Update/, 'Fail') | ||
await selectOption(component.container, user, /On Schema Break/, 'Fail') | ||
|
||
const someStringTemplateParamDiv = await findParentDiv(component.container, 'SOME_STRING') | ||
await selectOption(someStringTemplateParamDiv, user, /Type/, 'String') | ||
const someStringInput = getByLabelText(someStringTemplateParamDiv, /Value/) | ||
fireEvent.input(someStringInput, { | ||
target: { value: 'some-string' }, | ||
}) | ||
|
||
const someBytesTemplateParamDiv = await findParentDiv(component.container, 'SOME_BYTES') | ||
await selectOption(someBytesTemplateParamDiv, user, /Type/, 'Uint8Array') | ||
const someBytesInput = getByLabelText(someBytesTemplateParamDiv!, /Value/) | ||
fireEvent.input(someBytesInput, { | ||
target: { value: 'AQIDBA==' }, | ||
}) | ||
|
||
const someNumberTemplateParamDiv = await findParentDiv(component.container, 'SOME_NUMBER') | ||
await selectOption(someNumberTemplateParamDiv, user, /Type/, 'Number') | ||
const someNumberInput = getByLabelText(someNumberTemplateParamDiv!, /Value/) | ||
fireEvent.input(someNumberInput, { | ||
target: { value: '3' }, | ||
}) | ||
|
||
const deployButton = await waitFor(() => { | ||
const button = component.queryByRole('button', { name: deployButtonLabel }) | ||
expect(button).toBeDefined() | ||
return button! | ||
}) | ||
await user.click(deployButton) | ||
|
||
await waitFor(() => { | ||
const requiredValidationMessages = component.queryAllByText('Required') | ||
expect(requiredValidationMessages.length).toBe(0) | ||
}) | ||
|
||
await waitFor(() => { | ||
const errorMessage = component.queryByRole('alert', { name: 'error-message' }) | ||
expect(errorMessage).toBeNull() | ||
}) | ||
|
||
await waitFor(() => { | ||
const input = component.getByLabelText(/Application ID/) | ||
expect(input).toBeDefined() | ||
expect(input).toHaveValue() | ||
return input! | ||
}) | ||
} | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
const findParentDiv = async (component: HTMLElement, label: string) => { | ||
return await waitFor(() => { | ||
const div = getByText(component, label) | ||
return div.parentElement! | ||
}) | ||
} |
68 changes: 68 additions & 0 deletions
68
src/features/app-interfaces/components/create-app-interface-form.test.tsx
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,68 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi, vitest } from 'vitest' | ||
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing' | ||
import SampleSixAppSpec from '@/tests/test-app-specs/sample-six.arc32.json' | ||
import { Arc32AppSpec } from '@/features/app-interfaces/data/types' | ||
import { executeComponentTest } from '@/tests/test-component' | ||
import { render, waitFor } from '@/tests/testing-library' | ||
import { CreateAppInterfaceForm } from '@/features/app-interfaces/components/create-app-interface-form' | ||
import { deployAppLabel } from '@/features/app-interfaces/components/labels' | ||
import { setWalletAddressAndSigner } from '@/tests/utils/set-wallet-address-and-signer' | ||
import { useWallet } from '@txnlab/use-wallet' | ||
|
||
describe('create-app-interface-form', () => { | ||
const appSpec = SampleSixAppSpec as Arc32AppSpec | ||
|
||
const localnet = algorandFixture() | ||
beforeEach(localnet.beforeEach, 10e6) | ||
afterEach(() => { | ||
vitest.clearAllMocks() | ||
}) | ||
|
||
describe('when a wallet is connected', () => { | ||
beforeEach(async () => { | ||
await setWalletAddressAndSigner(localnet) | ||
}) | ||
|
||
it('the button to deploy the app is enabled', () => { | ||
return executeComponentTest( | ||
() => { | ||
return render(<CreateAppInterfaceForm appSpec={appSpec} appSpecFile={new File([], 'app.json')} onSuccess={() => {}} />) | ||
}, | ||
async (component) => { | ||
await waitFor(() => { | ||
const deployAppButton = component.getByRole('button', { name: deployAppLabel }) | ||
expect(deployAppButton).toBeEnabled() | ||
}) | ||
} | ||
) | ||
}) | ||
}) | ||
|
||
describe('when a wallet is not connected', () => { | ||
beforeEach(async () => { | ||
const original = await vi.importActual<{ useWallet: () => ReturnType<typeof useWallet> }>('@txnlab/use-wallet') | ||
vi.mocked(useWallet).mockImplementation(() => { | ||
return { | ||
...original.useWallet(), | ||
activeAddress: undefined, | ||
isActive: false, | ||
isReady: true, | ||
} | ||
}) | ||
}) | ||
|
||
it('the button to deploy the app is disabled', () => { | ||
return executeComponentTest( | ||
() => { | ||
return render(<CreateAppInterfaceForm appSpec={appSpec} appSpecFile={new File([], 'app.json')} onSuccess={() => {}} />) | ||
}, | ||
async (component) => { | ||
await waitFor(() => { | ||
const deployAppButton = component.getByRole('button', { name: deployAppLabel }) | ||
expect(deployAppButton).toBeDisabled() | ||
}) | ||
} | ||
) | ||
}) | ||
}) | ||
}) |
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
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.