Commit 38d57ea9 authored by Guilherme Gazzo's avatar Guilherme Gazzo Committed by Guilherme Gazzo
Browse files

fix: UiKit - conditional block

parents 4c049ef7 ba15e368
......@@ -180,7 +180,6 @@ const conditionsMatch = (conditions: Conditions = undefined, filters: Conditiona
if (!conditions) {
return false;
}
if (Array.isArray(filters.engine) && !filters.engine.includes(conditions.engine)) {
return false;
}
......@@ -189,8 +188,8 @@ const conditionsMatch = (conditions: Conditions = undefined, filters: Conditiona
};
const createSurfaceRenderer = <T>(allowedBlockTypes?: ElementType[]) =>
(parser: IParser<T>) =>
(blocks: unknown, conditions?: Conditions): any => {
(parser: IParser<T>, conditions?: Conditions) =>
(blocks: unknown): any => {
if (!Array.isArray(blocks)) {
return [];
}
......@@ -338,3 +337,5 @@ export {
};
export * from './blocks';
console.log(`ui-kit version: ${ process.env.VERSION }`);
......@@ -196,6 +196,10 @@ class TestParser extends UiKitParserMessage {
const parser = new TestParser();
const parse = uiKitMessage(parser);
const conditionalParse = uiKitMessage(parser, {
engine: 'rocket.chat',
});
describe('divider', () => {
it('renders', () => {
const payload = [
......@@ -1343,9 +1347,7 @@ it('evaluates conditional block', () => {
expect(parse(blocks)).toStrictEqual([]);
expect(parse(blocks, {
engine: 'rocket.chat',
})).toStrictEqual([
expect(conditionalParse(blocks)).toStrictEqual([
{
component: 'section',
props: {
......
......@@ -223,6 +223,10 @@ class TestParser extends UiKitParserModal {
const parser = new TestParser();
const parse = uiKitModal(parser);
const conditionalParse = uiKitModal(parser, {
engine: 'rocket.chat',
});
describe('divider', () => {
it('renders', () => {
const payload = [
......@@ -1694,9 +1698,7 @@ it('evaluates conditional block', () => {
expect(parse(blocks)).toStrictEqual([]);
expect(parse(blocks, {
engine: 'rocket.chat',
})).toStrictEqual([
expect(conditionalParse(blocks)).toStrictEqual([
{
component: 'section',
props: {
......
......@@ -27,6 +27,10 @@ class TestParser extends UiKitParserText {
const parser = new TestParser();
const parse = uiKitText(parser);
const conditionalParse = uiKitText(parser, {
engine: 'rocket.chat',
});
it('renders plain_text', () => {
const payload = [
{
......@@ -125,9 +129,7 @@ it('evaluates conditional block', () => {
expect(parse(blocks)).toStrictEqual([]);
expect(parse(blocks, {
engine: 'rocket.chat',
})).toStrictEqual([
expect(conditionalParse(blocks)).toStrictEqual([
{
component: 'text',
props: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment