Skip to content

Commit

Permalink
fix: Setup visibility in the router
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleface committed Jan 19, 2022
1 parent c660f77 commit 4d429e7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 136 deletions.
6 changes: 2 additions & 4 deletions packages/cozy-harvest-lib/src/components/AccountModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class AccountModal extends Component {
return (
<>
<KonnectorModalHeader konnector={konnector}>
{showAccountSelection && !konnector.clientSide ? (
{showAccountSelection ? (
<AccountSelectBox
loading={!account}
selectedAccount={account}
Expand Down Expand Up @@ -165,9 +165,7 @@ export class AccountModal extends Component {
account={account}
onAccountDeleted={onDismiss}
addAccount={() => pushHistory('/new')}
showNewAccountButton={
showNewAccountButton && !konnector.clientSide
}
showNewAccountButton={ showNewAccountButton }
/>
</DialogContent>
)}
Expand Down
30 changes: 0 additions & 30 deletions packages/cozy-harvest-lib/src/components/AccountModal.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,6 @@ describe('AccountModal', () => {
expect(component.getElement()).toMatchSnapshot()
})

it('should not display the AccountSelect & Account creation button if the konnector is clientSide', async () => {
const clientSideComponent = shallow(
<AccountModal
konnector={{ clientSide: true }}
t={x => x}
accountId={accountIdMock}
accountsAndTriggers={accountsAndTriggersMock}
pushHistory={mockHistoryPush}
breakpoints={{ isMobile: true }}
onDismiss={jest.fn()}
/>
)
await clientSideComponent.instance().componentDidMount()

fetchAccount.mockResolvedValue({
_id: 'account_2',
name: 'account_2'
})

expect(component.getElement()).toMatchSnapshot()
component.setProps({
accountId: 'account_2'
})

await clientSideComponent
.instance()
.componentDidUpdate({ accountId: accountIdMock })
expect(clientSideComponent.getElement()).toMatchSnapshot()
})

it('should redirect to the correct locations', async () => {
await component.instance().componentDidMount()

Expand Down
2 changes: 2 additions & 0 deletions packages/cozy-harvest-lib/src/components/Routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const Routes = ({ konnectorRoot, konnector, onDismiss, datacardOptions }) => {
accountId={match.params.accountId}
accountsAndTriggers={accountsAndTriggers}
onDismiss={onDismiss}
showNewAccountButton={!konnector.clientSide}
showAccountSelection={!konnector.clientSide}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,105 +177,3 @@ exports[`AccountModal with an account should display the AccountSelect & Content
</ForwardRef(WithStyles)>
</React.Fragment>
`;

exports[`AccountModal with an account should not display the AccountSelect & Account creation button if the konnector is clientSide 1`] = `
<React.Fragment>
<KonnectorModalHeader
konnector={Object {}}
>
<AccountSelectBox
accountsAndTriggers={
Array [
Object {
"account": Object {
"_id": "123",
"name": "account 1",
},
"trigger": Object {
"current_state": Object {},
"id": "triggerid",
},
},
Object {
"account": Object {
"_id": "account_2",
"name": "account_2",
},
"trigger": Object {
"id": "trigger_account2",
},
},
]
}
loading={false}
onChange={[Function]}
onCreate={[Function]}
selectedAccount={
Object {
"_id": "account_2",
"name": "account_2",
}
}
/>
</KonnectorModalHeader>
<ForwardRef(WithStyles)
className="u-p-0"
>
<KonnectorAccountTabs
account={
Object {
"_id": "account_2",
"name": "account_2",
}
}
addAccount={[Function]}
initialTrigger={
Object {
"id": "trigger_account2",
}
}
konnector={Object {}}
onAccountDeleted={[MockFunction]}
showNewAccountButton={true}
/>
</ForwardRef(WithStyles)>
</React.Fragment>
`;

exports[`AccountModal with an account should not display the AccountSelect & Account creation button if the konnector is clientSide 2`] = `
<React.Fragment>
<KonnectorModalHeader
konnector={
Object {
"clientSide": true,
}
}
/>
<ForwardRef(WithStyles)
className="u-p-0"
>
<KonnectorAccountTabs
account={
Object {
"_id": "account_2",
"name": "account_2",
}
}
addAccount={[Function]}
initialTrigger={
Object {
"current_state": Object {},
"id": "triggerid",
}
}
konnector={
Object {
"clientSide": true,
}
}
onAccountDeleted={[MockFunction]}
showNewAccountButton={false}
/>
</ForwardRef(WithStyles)>
</React.Fragment>
`;

0 comments on commit 4d429e7

Please sign in to comment.