-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(x-emitters): simplify return type
- Loading branch information
1 parent
875a6e2
commit 01645ee
Showing
5 changed files
with
1,834 additions
and
2,453 deletions.
There are no files selected for viewing
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
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
67 changes: 17 additions & 50 deletions
67
packages/x-components/src/components/__tests__/auto-progress-bar.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 |
---|---|---|
@@ -1,74 +1,41 @@ | ||
import { mount, Wrapper } from '@vue/test-utils'; | ||
import { mount } from '@vue/test-utils'; | ||
import { getDataTestSelector } from '../../__tests__/utils'; | ||
import AutoProgressBar from '../auto-progress-bar.vue'; | ||
|
||
function renderAutoProgressBar({ | ||
template = '<AutoProgressBar :durationInSeconds="durationInSeconds" :isLoading="isLoading"/>', | ||
durationInSeconds = 1, | ||
isLoading = true | ||
}: RenderBaseAutoProgressBarOptions = {}): RenderAutoProgressBarAPI { | ||
const wrapper = mount( | ||
{ | ||
components: { AutoProgressBar }, | ||
template | ||
}, | ||
{ | ||
data() { | ||
return { | ||
durationInSeconds, | ||
isLoading | ||
}; | ||
} | ||
} | ||
); | ||
function render({ durationInSeconds = 1, isLoading = true } = {}) { | ||
const wrapper = mount({ | ||
components: { AutoProgressBar }, | ||
data: () => ({ durationInSeconds, isLoading }), | ||
template: '<AutoProgressBar :durationInSeconds="durationInSeconds" :isLoading="isLoading"/>' | ||
}); | ||
|
||
return { | ||
wrapper | ||
wrapper, | ||
getProgressBarEl: () => wrapper.find(getDataTestSelector('progress-bar')), | ||
getProgressBarLineEl: () => wrapper.find(getDataTestSelector('progress-bar-line')) | ||
}; | ||
} | ||
|
||
describe('testing AutoProgressBar component', () => { | ||
it('renders a progress bar component', () => { | ||
const { wrapper } = renderAutoProgressBar(); | ||
const { getProgressBarEl } = render(); | ||
|
||
expect(wrapper.find(getDataTestSelector('progress-bar')).exists()).toBe(true); | ||
expect(getProgressBarEl().exists()).toBe(true); | ||
}); | ||
|
||
it("doesn't render a progress bar component when is not loading", async () => { | ||
const { wrapper } = renderAutoProgressBar(); | ||
const { wrapper, getProgressBarEl } = render(); | ||
|
||
expect(wrapper.find(getDataTestSelector('progress-bar')).exists()).toBe(true); | ||
expect(getProgressBarEl().exists()).toBe(true); | ||
|
||
await wrapper.setData({ isLoading: false }); | ||
|
||
expect(wrapper.find(getDataTestSelector('progress-bar')).exists()).toBe(false); | ||
expect(getProgressBarEl().exists()).toBe(false); | ||
}); | ||
|
||
it('render a progress bar component with an animation', () => { | ||
const { wrapper } = renderAutoProgressBar({ durationInSeconds: 2.5 }); | ||
const { getProgressBarLineEl } = render({ durationInSeconds: 2.5 }); | ||
|
||
expect(wrapper.find(getDataTestSelector('progress-bar-line')).attributes().style).toBe( | ||
'animation-duration: 2.5s;' | ||
); | ||
expect(getProgressBarLineEl().attributes().style).toBe('animation-duration: 2.5s;'); | ||
}); | ||
}); | ||
|
||
/** | ||
* Options to configure how the progress bar component should be rendered. | ||
*/ | ||
interface RenderBaseAutoProgressBarOptions { | ||
/** The template to render.*/ | ||
template?: string; | ||
/** The duration in seconds of the animation. */ | ||
durationInSeconds?: number; | ||
/** A flag indicating if the progress bar is loading. */ | ||
isLoading?: boolean; | ||
} | ||
|
||
/** | ||
* Options to configure how the progress bar component should be rendered. | ||
*/ | ||
interface RenderAutoProgressBarAPI { | ||
/** The wrapper for the progress bar component. */ | ||
wrapper: Wrapper<Vue>; | ||
} |
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
Oops, something went wrong.