Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MisRob committed Oct 14, 2023
1 parent 6d4f765 commit 5792f59
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions jest.conf/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as AphroditeNoImportant from 'aphrodite/no-important';
import Vue from 'vue';
import VueRouter from 'vue-router';
import VueIntl from 'vue-intl';
import VueCompositionAPI from '@vue/composition-api';
import KThemePlugin from '../lib/KThemePlugin';

global.beforeEach(() => {
Expand All @@ -26,6 +27,7 @@ global.afterEach(() => {

// Register Vue plugins and components
Vue.use(VueRouter);
Vue.use(VueCompositionAPI);
Vue.use(KThemePlugin);
Vue.use(VueIntl);

Expand Down
30 changes: 30 additions & 0 deletions lib/composables/useKShow/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import useKShow from "../index";

const { show } = useKShow()

// https://github.com/jestjs/jest/issues/11607
describe('useKShow', () => {
beforeAll(() => {
jest.useFakeTimers('legacy');
})
afterAll(() => {
jest.useRealTimers()
})

it('TODO', () => {
let isShowed = show('show-1', true, 5000)
expect(isShowed).toBe(true)

jest.advanceTimersByTime(1000);
isShowed = show('show-1', false, 5000)
expect(isShowed).toBe(true)

jest.advanceTimersByTime(2000);
isShowed = show('show-1', false, 5000)
expect(isShowed).toBe(true)

jest.advanceTimersByTime(3000);
isShowed = show('show-1', false, 5000)
expect(isShowed).toBe(false)
})
})
6 changes: 5 additions & 1 deletion lib/composables/useKShow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function useKShow() {
}

function _freezeItem(key) {
console.log('_freezeItem')
const item = itemsMap[key];
item.isFrozen.value = true;
item.timeoutId = setTimeout(() => {
Expand Down Expand Up @@ -63,7 +64,7 @@ export default function useKShow() {
return shouldShow;
}
itemsMap[key] = {
shouldShow,
shouldShow: false,
minVisibleTime,
isFrozen: ref(false),
timeoutId: null,
Expand All @@ -74,6 +75,8 @@ export default function useKShow() {
const previousShouldShow = item.shouldShow;
const previousMinVisibleTime = item.minVisibleTime;

console.log('previousShouldShow', previousShouldShow)
console.log('shouldShow', shouldShow)
if (previousShouldShow !== shouldShow) {
item.shouldShow = shouldShow;
// freeze when changing from false to true
Expand All @@ -92,6 +95,7 @@ export default function useKShow() {
_freezeItem(key);
}

console.log(item.isFrozen.value)
return shouldShow || item.isFrozen.value;
}

Expand Down

0 comments on commit 5792f59

Please sign in to comment.