mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
[web] add disconnected state to offline indicator (#35378)
GitOrigin-RevId: 692dc16cee738a8b05353717044a4063c3dd8e8a
This commit is contained in:
+51
-3
@@ -1,19 +1,47 @@
|
||||
import OfflineIndicator from '@/features/ide-react/components/toolbar/offline-indicator'
|
||||
import { IdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
||||
|
||||
const mount = ({
|
||||
isOffline = false,
|
||||
outOfSync = false,
|
||||
}: {
|
||||
isOffline?: boolean
|
||||
outOfSync?: boolean
|
||||
} = {}) => {
|
||||
cy.mount(
|
||||
<IdeReactContext.Provider
|
||||
value={{
|
||||
projectId: '',
|
||||
eventEmitter: {} as any,
|
||||
startedFreeTrial: false,
|
||||
setStartedFreeTrial: () => {},
|
||||
reportError: () => {},
|
||||
projectJoined: true,
|
||||
permissionsLevel: 'readAndWrite',
|
||||
setPermissionsLevel: () => {},
|
||||
outOfSync,
|
||||
setOutOfSync: () => {},
|
||||
}}
|
||||
>
|
||||
<OfflineIndicator isOffline={isOffline} />
|
||||
</IdeReactContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
describe('<OfflineIndicator />', function () {
|
||||
it('renders an empty live region when online', function () {
|
||||
cy.mount(<OfflineIndicator isOffline={false} />)
|
||||
mount({ isOffline: false })
|
||||
cy.findByText('You’re offline').should('not.exist')
|
||||
cy.findByRole('status').should('be.empty')
|
||||
})
|
||||
|
||||
it('shows the offline indicator when offline', function () {
|
||||
cy.mount(<OfflineIndicator isOffline />)
|
||||
mount({ isOffline: true })
|
||||
cy.findAllByText('You’re offline').first().should('be.visible')
|
||||
})
|
||||
|
||||
it('announces the offline status to screen readers via a live region', function () {
|
||||
cy.mount(<OfflineIndicator isOffline />)
|
||||
mount({ isOffline: true })
|
||||
cy.findByRole('status').within(() => {
|
||||
cy.findByText('You’re offline').should('exist')
|
||||
cy.findByText(
|
||||
@@ -21,4 +49,24 @@ describe('<OfflineIndicator />', function () {
|
||||
).should('exist')
|
||||
})
|
||||
})
|
||||
|
||||
it('shows "Disconnected" without a tooltip when out of sync', function () {
|
||||
mount({ isOffline: true, outOfSync: true })
|
||||
cy.findAllByText('Disconnected')
|
||||
.first()
|
||||
.should('be.visible')
|
||||
.trigger('mouseover')
|
||||
cy.get('#tooltip-offline-indicator-tooltip').should('not.exist')
|
||||
cy.findByText('You’re offline').should('not.exist')
|
||||
})
|
||||
|
||||
it('announces "Disconnected" to screen readers when out of sync', function () {
|
||||
mount({ isOffline: true, outOfSync: true })
|
||||
cy.findByRole('status').within(() => {
|
||||
cy.findByText('Disconnected').should('exist')
|
||||
cy.findByText(
|
||||
'Your changes are saved in the browser. We’ll sync your work when you’re back online.'
|
||||
).should('not.exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user