{"size": 1561, "ext": "js", "max_stars_repo_path": "packages/core/tests/postActivity/asyncReceive.test.js", "max_stars_repo_name": "schgressive/BotFramework-WebChat", "max_stars_repo_stars_event_min_datetime": "2019-03-05T02:21:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-05T02:21:09.000Z", "max_issues_repo_path": "packages/core/tests/postActivity/asyncReceive.test.js", "max_issues_repo_name": "schgressive/BotFramework-WebChat", "max_issues_repo_issues_event_min_datetime": "2021-03-02T01:33:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T23:28:07.000Z", "max_forks_repo_path": "packages/core/tests/postActivity/asyncReceive.test.js", "max_forks_repo_name": "schgressive/BotFramework-WebChat", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 9, "max_forks_count": null, "avg_line_length": 30.6078431373, "max_line_length": 106, "alphanum_fraction": 0.6899423447}
import createFacility from '../createFacility';

import { POST_ACTIVITY } from '../../src/actions/postActivity';
import * as ActivityClientState from '../../src/constants/ActivityClientState';

test('Post activity success', async () => {
  // 1. postActivity
  // 2. new incoming activity
  // 3. look for incoming activity
  // 4. complete postActivity
  // 5. look for posted activity

  const { actions, directLine, store } = await createFacility();

  // Clear out actions
  actions.splice(0);

  store.dispatch({
    type: POST_ACTIVITY,
    payload: {
      activity: {
        type: 'message',
        text: 'Outgoing'
      }
    }
  });

  await 0;
  expect(directLine.pendingPosts).toHaveProperty('length', 1);
  expect(store.getState().activities[0]).toHaveProperty('channelData.state', ActivityClientState.SENDING);

  // Receive an activity while a message is pending to post
  directLine.activity.next({
    id: 'bot:1',
    text: 'Incoming',
    type: 'message'
  });

  await 0;
  expect(store.getState().activities).toHaveProperty('length', 2);
  expect(store.getState().activities[0]).toHaveProperty('channelData.state', ActivityClientState.SENDING);
  expect(store.getState().activities[0]).toHaveProperty('text', 'Outgoing');
  expect(store.getState().activities[1]).toHaveProperty('id', 'bot:1');

  directLine.pendingPosts[0].complete('user:1');
  await 0;

  expect(store.getState().activities[0]).toHaveProperty('channelData.state', ActivityClientState.SENT);
  expect(store.getState().activities[0]).toHaveProperty('id', 'user:1');
});
