Skip to content

Commit

Permalink
refactor: apply PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Sep 20, 2024
1 parent dc6366c commit 68f3e7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
29 changes: 17 additions & 12 deletions src/itemLogin/ItemLoginAuthorization.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,39 @@ import Card from '@/Card/Card.js';
import ItemLoginAuthorization from './ItemLoginAuthorization.js';
import { FORBIDDEN_TEXT } from './constants.js';

const meta: Meta<typeof ItemLoginAuthorization> = {
const item = PackedDocumentItemFactory();
const meta = {
title: 'Actions/ItemLoginAuthorization',
component: ItemLoginAuthorization,

argTypes: {
signIn: { action: 'onRedirect' },
},
args: {
signIn: () => {},
itemId: item.id,

children: <Card alt='card' name='card' />,
},
};
} satisfies Meta<typeof ItemLoginAuthorization>;

export default meta;

type Story = StoryObj<typeof ItemLoginAuthorization>;
type Story = StoryObj<typeof meta>;

export const Authorized: Story = {
export const Authorized = {
args: {
currentAccount: { id: 'member', name: 'member' } as CompleteMember,
item: PackedDocumentItemFactory(),
item,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

expect(canvas.getByText('card')).toBeVisible();
},
};
export const LogInForm: Story = {
} satisfies Story;

export const LogInForm = {
args: {
itemLoginSchemaType: ItemLoginSchemaType.Username,
},
Expand All @@ -49,9 +54,9 @@ export const LogInForm: Story = {

expect(canvas.getByText('Sign In')).toBeVisible();
},
};
} satisfies Story;

export const Loading: Story = {
export const Loading = {
args: {
isLoading: true,
},
Expand All @@ -60,9 +65,9 @@ export const Loading: Story = {

expect(canvas.getByRole('progressbar')).toBeVisible();
},
};
} satisfies Story;

export const Forbidden: Story = {
export const Forbidden = {
args: {
currentAccount: { id: 'member', name: 'member' } as CompleteMember,
},
Expand All @@ -71,4 +76,4 @@ export const Forbidden: Story = {

expect(canvas.getByText(FORBIDDEN_TEXT)).toBeVisible();
},
};
} satisfies Story;
1 change: 0 additions & 1 deletion src/itemLogin/ItemLoginAuthorization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const ItemLoginAuthorization = ({
children,
}: ItemLoginAuthorizationProps): ReactNode => {
if (isLoading) {
// get item login if the user is not authenticated and the item is empty
return <CustomInitialLoader />;
}

Expand Down
22 changes: 13 additions & 9 deletions src/itemLogin/ItemLoginScreen.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import type { Meta, StoryObj } from '@storybook/react';
import { expect, fn } from '@storybook/test';
import { userEvent, within } from '@storybook/testing-library';

import { ItemLoginSchemaType } from '@graasp/sdk';
import { ItemLoginSchemaType, PackedDocumentItemFactory } from '@graasp/sdk';

import { TABLE_CATEGORIES } from '../utils/storybook.js';
import ItemLoginScreen from './ItemLoginScreen.js';
import { FORBIDDEN_TEXT } from './constants.js';

const meta: Meta<typeof ItemLoginScreen> = {
const item = PackedDocumentItemFactory();
const meta = {
title: 'Actions/ItemLogin/ItemLoginScreen',
component: ItemLoginScreen,

args: {
signIn: fn(),
itemId: item.id,
},
argTypes: {
passwordInputId: {
Expand All @@ -33,11 +35,11 @@ const meta: Meta<typeof ItemLoginScreen> = {
},
signIn: { action: 'signin' },
},
};
} satisfies Meta<typeof ItemLoginScreen>;

export default meta;

type Story = StoryObj<typeof ItemLoginScreen>;
type Story = StoryObj<typeof meta>;

export const ItemLoginUsernameAndPassword: Story = {
args: {
Expand All @@ -55,7 +57,7 @@ export const ItemLoginUsernameAndPassword: Story = {

expect(args.signIn).toHaveBeenCalled();
},
};
} satisfies Story;

export const ItemLoginUsername: Story = {
args: {
Expand All @@ -72,13 +74,15 @@ export const ItemLoginUsername: Story = {

expect(args.signIn).toHaveBeenCalled();
},
};
} satisfies Story;

export const Forbidden: Story = {
args: {},
export const Forbidden = {
args: {
itemId: item.id,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await expect(canvas.getByText(FORBIDDEN_TEXT)).toBeInTheDocument();
},
};
} satisfies Story;
2 changes: 1 addition & 1 deletion src/itemLogin/ItemLoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type ItemLoginScreenProps = {
/**
* item login schema object
*/
itemLoginSchemaType: ItemLoginSchemaType;
itemLoginSchemaType?: ItemLoginSchemaType;
signIn: (args: { itemId: string } & SignInPropertiesType) => void;
/**
* content to display when the user doesn't have access
Expand Down

0 comments on commit 68f3e7d

Please sign in to comment.