Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: remove sheet specific methods #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ export {renewSession, onSessionRenewed, logout} from './src/sessions';

export {showAppRating} from './src/app-rating';

export {
bottomSheet,
bottomSheetSingleSelector,
bottomSheetActionSelector,
bottomSheetInfo,
} from './src/bottom-sheet';
export {bottomSheet} from './src/bottom-sheet';
export type {
SheetRowItem,
SheetActionItem,
Expand Down
289 changes: 40 additions & 249 deletions src/__tests__/bottom-sheet-test.ts
Original file line number Diff line number Diff line change
@@ -1,186 +1,39 @@
import {
bottomSheetActions,
bottomSheetActionSelector,
bottomSheetInfo,
bottomSheetSingleSelector,
SheetActionItem,
SheetInfoItem,
} from '../bottom-sheet';
import {bottomSheet} from '../bottom-sheet';
import {createFakeAndroidPostMessage} from './fake-post-message';

import type {SheetRowItem} from '../bottom-sheet';

test('single selection', (done) => {
test('bottomSheet', (done) => {
const title = 'any title';
const subtitle = 'any subtitle';
const description = 'any description';
const selectedId = 'item-0';
const items: Array<SheetRowItem> = [
{
id: 'item-0',
title: 'item 0 title',
description: 'item 0 description',
icon: {
url: 'https://example.com/icon.png',
urlDark: 'https://example.com/dark-icon.png',
},
},
{
id: 'item-1',
title: 'item 1 title',
description: 'item 1 description',
},
{
id: 'item-2',
title: 'item 2 title',
description: 'item 2 description',
},
];

createFakeAndroidPostMessage({
checkMessage: (message) => {
expect(message.type).toBe('SHEET');
expect(message.payload).toEqual({
title,
subtitle,
description,
content: [
{
id: 'list-0',
type: 'LIST',
listType: 'SINGLE_SELECTION',
autoSubmit: true,
selectedIds: [selectedId],
items,
},
],
});
},
getResponse: (message) => ({
type: message.type,
id: message.id,
payload: {
action: 'SUBMIT',
result: [
{
id: 'list-0',
selectedIds: ['item-2'],
},
],
},
}),
});

bottomSheetSingleSelector({
title,
subtitle,
description,
selectedId,
items,
}).then((res) => {
expect(res).toEqual({action: 'SUBMIT', selectedId: 'item-2'});
done();
});
});

test('actions', (done) => {
const title = 'any title';
const subtitle = 'any subtitle';
const description = 'any description';
const items: Array<SheetActionItem> = [
{
id: 'item-0',
title: 'item 0 title',
icon: {
url: 'https://example.com/icon.png',
urlDark: 'https://example.com/dark-icon.png',
},
},
{
id: 'item-1',
title: 'item 1 title',
style: 'normal',
},
const content = [
{
id: 'item-2',
title: 'item 2 title',
style: 'destructive',
},
];

createFakeAndroidPostMessage({
checkMessage: (message) => {
expect(message.type).toBe('SHEET');
expect(message.payload).toEqual({
title,
subtitle,
description,
content: [
{
id: 'list-0',
type: 'LIST',
listType: 'ACTIONS',
autoSubmit: true,
selectedIds: [],
items,
},
],
});
},
getResponse: (message) => ({
type: message.type,
id: message.id,
payload: {
action: 'SUBMIT',
result: [
{
id: 'list-0',
selectedIds: ['item-2'],
id: 'list-0',
type: 'LIST' as const,
listType: 'SINGLE_SELECTION' as const,
autoSubmit: true,
selectedIds: [selectedId],
items: [
{
id: 'item-0',
title: 'item 0 title',
description: 'item 0 description',
icon: {
url: 'https://example.com/icon.png',
urlDark: 'https://example.com/dark-icon.png',
},
],
},
}),
});

bottomSheetActionSelector({
title,
subtitle,
description,
items,
}).then((res) => {
expect(res).toEqual({action: 'SUBMIT', selectedId: 'item-2'});
done();
});
});

test('informative', (done) => {
const title = 'any title';
const subtitle = 'any subtitle';
const description = 'any description';
const items: Array<SheetInfoItem> = [
{
id: 'item-0',
title: 'item 0 title',
icon: {
url: 'https://example.com/icon.png',
urlDark: 'https://example.com/dark-icon.png',
type: 'regular',
},
},
{
id: 'item-1',
title: 'item 1 title',
icon: {
type: 'small',
url: 'https://example.com/icon.png',
},
},
{
id: 'item-2',
title: 'item 2 title',
icon: {
type: 'bullet',
},
},
{
id: 'item-1',
title: 'item 1 title',
description: 'item 1 description',
},
{
id: 'item-2',
title: 'item 2 title',
description: 'item 2 description',
},
],
},
];

Expand All @@ -191,16 +44,7 @@ test('informative', (done) => {
title,
subtitle,
description,
content: [
{
id: 'list-0',
type: 'LIST',
listType: 'INFORMATIVE',
autoSubmit: false,
selectedIds: [],
items,
},
],
content,
});
},
getResponse: (message) => ({
Expand All @@ -218,74 +62,21 @@ test('informative', (done) => {
}),
});

bottomSheetInfo({
title,
subtitle,
description,
items,
}).then((res) => {
expect(res).toBe(undefined);
done();
});
});

test('actions', (done) => {
const title = 'any title';
const subtitle = 'any subtitle';
const description = 'any description';
const button = {
text: 'button text',
};
const link = {
text: 'link text',
chevron: true,
};
const secondaryButton = {
text: 'secondary button text',
};

createFakeAndroidPostMessage({
checkMessage: (message) => {
expect(message.type).toBe('SHEET');
expect(message.payload).toEqual({
title,
subtitle,
description,
content: [
{
id: 'bottom-actions-0',
type: 'BOTTOM_ACTIONS',
button,
link,
secondaryButton,
},
],
});
},
getResponse: (message) => ({
type: message.type,
id: message.id,
payload: {
action: 'SUBMIT',
result: [
{
id: 'bottom-actions-0',
selectedIds: ['PRIMARY'],
},
],
},
}),
});

bottomSheetActions({
bottomSheet({
title,
subtitle,
description,
button,
secondaryButton,
link,
content,
}).then((res) => {
expect(res).toEqual({action: 'PRIMARY'});
expect(res).toEqual({
action: 'SUBMIT',
result: [
{
id: 'list-0',
selectedIds: ['item-2'],
},
],
});
done();
});
});
Loading
Loading