Skip to content

Commit

Permalink
Merge pull request #2089 from oasisprotocol/mz/e2e
Browse files Browse the repository at this point in the history
Override API in e2e tests to allow quick backend switch
  • Loading branch information
buberdds authored Nov 18, 2024
2 parents 67dfd2c + 721afa4 commit 59a84ea
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions .changelog/2089.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Override API in e2e tests to allow quick backend switch
1 change: 1 addition & 0 deletions playwright/utils/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from '../../src/vendors/oasisscan/index'

export async function mockApi(context: BrowserContext | Page, balance: number) {
await context.addInitScript(() => ((window as any).REACT_APP_BACKEND = 'oasisscan'))
await context.route('**/chain/account/info/*', route => {
route.fulfill({
body: JSON.stringify({
Expand Down
6 changes: 0 additions & 6 deletions src/app/components/Footer/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ describe('<Footer />', () => {
)
})

it('should render backend label', () => {
renderComponent(store, 'large')

expect(screen.getByText(/Oasis Scan API/)).toBeInTheDocument()
})

it('should render mobile version of footer', () => {
renderComponent(store, 'small')

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/AccountPage/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('<AccountPage />', () => {
}),
)
const page = renderPage(store, ['/account/oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk'])
expect(page.container).toHaveTextContent('Oasis Scan API appears to be down')
expect(page.container).toHaveTextContent(/API appears to be down/)
const balance = await screen.findByTestId('account-balance-total')
expect(balance).toHaveTextContent('-')
const balanceSummary = await screen.findByTestId('account-balance-summary')
Expand Down
26 changes: 18 additions & 8 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
declare namespace NodeJS {
export interface ProcessEnv {
REACT_APP_BACKEND: 'oasismonitor' | 'oasisscan' | 'oasisscanV2' | 'nexus'
REACT_APP_TRANSAK_URL: string
REACT_APP_TRANSAK_PARTNER_ID: string
REACT_APP_LOCALNET: '1' | undefined
REACT_APP_E2E_TEST: '1' | undefined
NODE_ENV: 'development' | 'production' | 'test'
type Backend = 'oasismonitor' | 'oasisscan' | 'oasisscanV2' | 'nexus'

declare global {
namespace NodeJS {
export interface ProcessEnv {
REACT_APP_BACKEND: Backend
REACT_APP_TRANSAK_URL: string
REACT_APP_TRANSAK_PARTNER_ID: string
REACT_APP_LOCALNET: '1' | undefined
REACT_APP_E2E_TEST: '1' | undefined
NODE_ENV: 'development' | 'production' | 'test'
}
}

interface Window {
REACT_APP_BACKEND: Backend
}
}

export {}
5 changes: 4 additions & 1 deletion src/vendors/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ const backendNameToApi = {
[BackendAPIs.Nexus]: getNexusAPIs,
}

export const backend = () => process.env.REACT_APP_BACKEND || BackendAPIs.OasisMonitor
export const backend = () =>
(process.env.REACT_APP_E2E_TEST && window.REACT_APP_BACKEND) ||
process.env.REACT_APP_BACKEND ||
BackendAPIs.OasisMonitor
export const backendApi = backendNameToApi[backend()]

0 comments on commit 59a84ea

Please sign in to comment.