marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.89k stars 5.24k forks source link

How to unit test my CreateField component? #8246

Closed ayushdevelop closed 2 years ago

ayushdevelop commented 2 years ago

I am trying to test my CreateField component as I am fetching the data from an api to show in <SelectInput>?

What steps should I follow to test for ensuring if the data populates as options of SelectInput ?

This is my code


const StandupCreate = () => {
  const [channelList, setChannelList] = useState([]);

  useEffect(() => {
    const fetchChannelList = async () => {
      try {
        const data = await fetchChannels();

        const channels = await data.data.data;

        setChannelList(channels);
      } catch (error) {
        throw error;
      }
    };

    fetchChannelList();
  }, []);

  return (
    <Create>
      <SimpleForm>
        <TextInput source="title" />
        <TextInput source="question 1" fullWidth />
        <TextInput source="question 2" fullWidth />
        <TextInput source="question 3" fullWidth />
        <TextInput source="question 4" fullWidth />
        <SelectInput
          source="channel"
          choices={channelList}
        />
        <CheckboxGroupInput source="members" choices={channelMembers} />
        <TimeInput source="time" />
      </SimpleForm>
    </Create>
  );
};
slax57 commented 2 years ago

Hi, and thanks for your question. As explained in the react-admin contributing guide, we use the GitHub issues for bugs and feature requests only.

For support question ("How To", usage advice, or troubleshooting your own code), you have three options:

So I'm closing this issue, and inviting you to ask your question in one of the support channels above.

ayushdevelop commented 2 years ago

hey @slax57 thank you for the response but it seems like the discord invite link has expired, can you please share with me a new invitation link?

slax57 commented 2 years ago

Nice catch! Sure here is a new one (with no expiry this time :sweat_smile: ): https://discord.gg/B4G7AEQ3jm

ayushdevelop commented 2 years ago

Thankyou @slax57 for the quick response.