Newer
Older
import { render, screen } from '@testing-library/react'
import React from 'react'
import { BrowserRouter } from 'react-router-dom'
import { SgeStatusWithAccount } from 'tests/__mocks__/fluidStatusData.mock'
import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store'
import SgeConnectView from './SgeConnectView'
jest.mock('components/Content/Content', () => 'mock-content')
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
const mockConnect = jest.fn()
const mockUpdate = jest.fn()
jest.mock('components/Hooks/useKonnectorAuth', () =>
jest.fn(() => [mockConnect, mockUpdate])
)
describe('SgeConnectView component', () => {
beforeEach(() => {
})
it('should be rendered correctly', () => {
<BrowserRouter>
<SgeConnectView />
</BrowserRouter>
it('should be on stepIdentity by default with button disabled', async () => {
render(
<Provider store={store}>
<BrowserRouter>
<SgeConnectView />
</BrowserRouter>
</Provider>
)
expect(
screen.getByText('auth.enedissgegrandlyon.identityTitle')
).toBeInTheDocument()
const prevButton = screen.getByRole('button', {
name: 'profile_type.accessibility.button_previous',
})
const nextButton = screen.getByRole('button', {
name: 'profile_type.accessibility.button_next',
expect(prevButton).toBeDisabled()
expect(nextButton).toBeDisabled()
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
describe('should test methods from useKonnectorAuth hook', () => {
it('should launch account and trigger creation process', async () => {
const store = createMockEcolyoStore({
global: {
...mockGlobalState,
sgeConnect: {
...mockGlobalState.sgeConnect,
shouldLaunchAccount: true,
},
},
})
render(
<Provider store={store}>
<SgeConnectView />
</Provider>
)
expect(mockConnect).toHaveBeenCalled()
})
it('should launch existing account update process', async () => {
const store = createMockEcolyoStore({
global: {
...mockGlobalState,
fluidStatus: [SgeStatusWithAccount],
sgeConnect: {
...mockGlobalState.sgeConnect,
shouldLaunchAccount: true,
},
},
})
render(
<Provider store={store}>
<SgeConnectView />
</Provider>
)
expect(mockUpdate).toHaveBeenCalled()
})
})