Skip to content

Commit

Permalink
fix connection spec tests, rename: social->primary, web3->secondary, …
Browse files Browse the repository at this point in the history
…secondary->extra, and add tests from feedback
  • Loading branch information
kuruk-mm committed Nov 20, 2024
1 parent 2f5e741 commit 4155925
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions src/components/Connection/Connection.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render } from '@testing-library/react'
import { Connection } from './Connection'
import { EXTRA_TEST_ID, PRIMARY_TEST_ID, SHOW_MORE_BUTTON_TEST_ID } from './constants'
import { EXTRA_TEST_ID, PRIMARY_TEST_ID, SECONDARY_TEST_ID, SHOW_MORE_BUTTON_TEST_ID } from './constants'
import { ConnectionOptionType, ConnectionProps } from './Connection.types'

function renderConnection(props: Partial<ConnectionProps>) {
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('when rendering the component', () => {
let connectionOptions: ConnectionProps['connectionOptions']
let onConnect: jest.Mock

describe('and there are social options', () => {
describe('and there are primary, secondary and extra options', () => {
beforeEach(() => {
onConnect = jest.fn()
connectionOptions = {
Expand All @@ -44,9 +44,10 @@ describe('when rendering the component', () => {
screen = renderConnection({ connectionOptions, onConnect })
})

it('should render the primary social option', () => {
it('should render the primary and secondary option', () => {
const { getByTestId } = screen
expect(getByTestId(PRIMARY_TEST_ID)).toBeInTheDocument()
expect(getByTestId(SECONDARY_TEST_ID)).toBeInTheDocument()
})

it('should call the onConnect method prop when clicking the button', () => {
Expand All @@ -55,7 +56,7 @@ describe('when rendering the component', () => {
expect(onConnect).toHaveBeenCalledWith(ConnectionOptionType.GOOGLE)
})

it('should render all the secondary options', () => {
it('should render all the extra options', () => {
const { getByTestId } = screen
act(() => {
fireEvent.click(getByTestId(SHOW_MORE_BUTTON_TEST_ID))
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('when rendering the component', () => {
})
})

describe('and there are web3 options', () => {
describe('and there are is not secondary options', () => {
beforeEach(() => {
onConnect = jest.fn()
connectionOptions = {
Expand All @@ -140,12 +141,17 @@ describe('when rendering the component', () => {
screen = renderConnection({ connectionOptions, onConnect })
})

it('should render the primary social option', () => {
it('should render the primary option', () => {
const { getByTestId } = screen
expect(getByTestId(PRIMARY_TEST_ID)).toBeInTheDocument()
})

it('should render all the secondary options', () => {
it('should not render the secondary', () => {
const { queryByTestId } = screen
expect(queryByTestId(SECONDARY_TEST_ID)).not.toBeInTheDocument()
})

it('should render all the extra options', () => {
const { getByTestId } = screen
act(() => {
fireEvent.click(getByTestId(SHOW_MORE_BUTTON_TEST_ID))
Expand All @@ -167,7 +173,31 @@ describe('when rendering the component', () => {
})
})

describe('and there are no web3 nor social secondary options', () => {
describe('and there are primary, but not secondary nor extra options', () => {
beforeEach(() => {
connectionOptions = {
primary: ConnectionOptionType.METAMASK
}
screen = renderConnection({ connectionOptions })
})

it('should render the primary', () => {
const { queryByTestId } = screen
expect(queryByTestId(PRIMARY_TEST_ID)).toBeInTheDocument()
})

it('should not render the secondary', () => {
const { queryByTestId } = screen
expect(queryByTestId(SECONDARY_TEST_ID)).not.toBeInTheDocument()
})

it('should not render the more options button', () => {
const { queryByTestId } = screen
expect(queryByTestId(SHOW_MORE_BUTTON_TEST_ID)).not.toBeInTheDocument()
})
})

describe('and there are no primary nor secondary nor extra options', () => {
beforeEach(() => {
connectionOptions = undefined
screen = renderConnection({ connectionOptions })
Expand Down

0 comments on commit 4155925

Please sign in to comment.