-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: useCheckPublishCompleted.spec.ts with renderHook()
- Loading branch information
1 parent
935bf8e
commit 68ed323
Showing
2 changed files
with
53 additions
and
108 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
tests/component/sections/dataset/useCheckPublishCompleted.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { DatasetRepository } from '../../../../src/dataset/domain/repositories/DatasetRepository' | ||
import { renderHook } from '@testing-library/react' | ||
import useCheckPublishCompleted from '../../../../src/sections/dataset/useCheckPublishCompleted' | ||
import { DatasetMother } from '../../dataset/domain/models/DatasetMother' | ||
import { DatasetMockRepository } from '../../../../src/stories/dataset/DatasetMockRepository' | ||
|
||
describe('useCheckPublishCompleted Hook', () => { | ||
beforeEach(() => { | ||
const datasetRepository: DatasetRepository = {} as DatasetRepository | ||
datasetRepository.getLocks = cy.stub().resolves([]) | ||
}) | ||
it('should not set publishCompleted if publishInProgress is false', () => { | ||
const datasetRepository: DatasetRepository = {} as DatasetRepository | ||
const { result } = renderHook(() => | ||
useCheckPublishCompleted(false, DatasetMother.create(), datasetRepository) | ||
) | ||
cy.wait(3000).then(() => { | ||
cy.wrap(result.current).should('equal', false) | ||
}) | ||
}) | ||
it('should set publishCompleted to true when no locks are found initially', () => { | ||
const datasetRepository: DatasetRepository = {} as DatasetRepository | ||
datasetRepository.getLocks = cy.stub().resolves([]) | ||
|
||
const { result } = renderHook(() => | ||
useCheckPublishCompleted(true, DatasetMother.create(), datasetRepository) | ||
) | ||
cy.wait(3000).then(() => { | ||
cy.wrap(result.current).should('equal', true) | ||
}) | ||
}) | ||
|
||
it('should set publishCompleted to true after polling finds no locks', () => { | ||
const datasetRepository: DatasetMockRepository = new DatasetMockRepository() | ||
|
||
cy.stub(datasetRepository, 'getLocks') | ||
.resolves([{}]) | ||
.onFirstCall() | ||
.resolves([]) | ||
.callsFake(() => Promise.resolve([])) | ||
|
||
const { result } = renderHook(() => | ||
useCheckPublishCompleted(true, DatasetMother.create(), datasetRepository) | ||
) | ||
|
||
cy.wrap(result.current).should('equal', false) | ||
cy.wait(3000).then(() => { | ||
cy.wrap(result.current).should('equal', true) | ||
}) | ||
}) | ||
}) |
108 changes: 0 additions & 108 deletions
108
tests/component/sections/dataset/usePollDatasetLocks.spec.tsx
This file was deleted.
Oops, something went wrong.