Skip to content

Commit

Permalink
chore: remove '@testing-library/preact-hook' dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaiir committed May 7, 2024
1 parent f28ffa1 commit 46e4258
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 171 deletions.
30 changes: 2 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
"@bpmn-io/form-js": "^1.8.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@testing-library/preact": "^3.0.0",
"@testing-library/preact-hooks": "^1.1.0",
"@testing-library/preact": "^3.2.3",
"axe-core": "^4.8.2",
"babel-loader": "^9.1.3",
"babel-plugin-istanbul": "^6.1.1",
Expand Down
282 changes: 141 additions & 141 deletions test/spec/hooks/useLayoutState.spec.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,141 @@
import {
act,
renderHook
} from '@testing-library/preact-hooks';

import {
html
} from 'diagram-js/lib/ui';

import {
get,
set
} from 'min-dash';

import {
useLayoutState
} from '../../../src/hooks/useLayoutState';

import {
LayoutContext
} from '../../../src/context/LayoutContext';

const noop = () => {};


describe('hooks/useLayoutState', function() {

it('should get from layout context', function() {

// given
const layout = {
a: {
b: 'foo'
}
};

const getLayoutForKey = (path) => get(layout, path);

const path = [ 'a', 'b' ];

const wrapper = createLayout({
getLayoutForKey,
layout
});

// when
const { result } = renderHook(() => useLayoutState(path), { wrapper });

const value = result.current[0];

// then
expect(value).to.eql('foo');
});


it('should get default value', function() {

// given
const layout = {};

const getLayoutForKey = (path, defaultValue) => get(layout, path, defaultValue);

const path = [ 'a', 'b' ];

const wrapper = createLayout({
getLayoutForKey
});

// when
const { result } = renderHook(() => useLayoutState(path, 'default'), { wrapper });

const [ value ] = result.current;

// then
expect(value).to.equal('default');
});


it('should set to layout context', function() {

// given
const layout = {
a: {
b: 'foo'
}
};

const setLayoutForKey = (path, value) => set(layout, path, value);

const path = [ 'a', 'b' ];

const wrapper = createLayout({
setLayoutForKey,
layout
});

const { result } = renderHook(() => useLayoutState(path), { wrapper });

const [ , setState ] = result.current;

const newValue = 'newValue';

// when
act(() => {
setState(newValue);
});

const [ value ] = result.current;

// then
expect(value).to.eql(newValue);
expect(layout).to.eql({
a: {
b: newValue
}
});
});

});


// helper ////////////////////

function createLayout(props = {}) {
const {
layout = {},
getLayoutForKey = noop,
setLayoutForKey = noop
} = props;

const context = {
layout,
getLayoutForKey,
setLayoutForKey
};

return ({ children }) => html`
<${LayoutContext.Provider} value=${context}>
${children}
</${LayoutContext.Provider}>`;
}
import {
act,
renderHook
} from '@testing-library/preact';

import {
html
} from 'diagram-js/lib/ui';

import {
get,
set
} from 'min-dash';

import {
useLayoutState
} from '../../../src/hooks/useLayoutState';

import {
LayoutContext
} from '../../../src/context/LayoutContext';

const noop = () => {};


describe('hooks/useLayoutState', function() {

it('should get from layout context', function() {

// given
const layout = {
a: {
b: 'foo'
}
};

const getLayoutForKey = (path) => get(layout, path);

const path = [ 'a', 'b' ];

const wrapper = createLayout({
getLayoutForKey,
layout
});

// when
const { result } = renderHook(() => useLayoutState(path), { wrapper });

const value = result.current[0];

// then
expect(value).to.eql('foo');
});


it('should get default value', function() {

// given
const layout = {};

const getLayoutForKey = (path, defaultValue) => get(layout, path, defaultValue);

const path = [ 'a', 'b' ];

const wrapper = createLayout({
getLayoutForKey
});

// when
const { result } = renderHook(() => useLayoutState(path, 'default'), { wrapper });

const [ value ] = result.current;

// then
expect(value).to.equal('default');
});


it('should set to layout context', function() {

// given
const layout = {
a: {
b: 'foo'
}
};

const setLayoutForKey = (path, value) => set(layout, path, value);

const path = [ 'a', 'b' ];

const wrapper = createLayout({
setLayoutForKey,
layout
});

const { result } = renderHook(() => useLayoutState(path), { wrapper });

const [ , setState ] = result.current;

const newValue = 'newValue';

// when
act(() => {
setState(newValue);
});

const [ value ] = result.current;

// then
expect(value).to.eql(newValue);
expect(layout).to.eql({
a: {
b: newValue
}
});
});

});


// helper ////////////////////

function createLayout(props = {}) {
const {
layout = {},
getLayoutForKey = noop,
setLayoutForKey = noop
} = props;

const context = {
layout,
getLayoutForKey,
setLayoutForKey
};

return ({ children }) => html`
<${LayoutContext.Provider} value=${context}>
${children}
</${LayoutContext.Provider}>`;
}

0 comments on commit 46e4258

Please sign in to comment.