function runplan()

in example/src/screens/TestPlan.tsx [281:370]


  function runplan() {
    const plandata = parse(testPlan);
    Object.keys(plandata).forEach((name) => {
      const lname = name.toLowerCase();
      const value = plandata[name];
      switch (lname) {
        case 'url':
          if (typeof value === 'string') {
            planState.url = value;
          } else {
            // throw error with example input
          }
          break;
        case 'inputs':
          if (Array.isArray(value)) {
            const newInputs: PlanInput[] = [];

            value.forEach((input) => {
              if (typeof input === 'string') {
                const template = InputTemplates[input];
                if (template) {
                  newInputs.push({ name: input, ...template });
                }
              } else {
                Object.entries(input).forEach(([prop, data]) => {
                  const template = InputTemplates[prop];
                  if (template) {
                    planState.props[prop] = data;
                    newInputs.push({ name: prop, ...template });
                  }
                });
              }
            });

            planState.inputs = newInputs;
          } else {
            // throw error with example input
          }
          break;
        case 'events':
          if (Array.isArray(value)) {
            const newEvents = new Set<string>();

            value.forEach((event) => {
              if (typeof event === 'string') {
                newEvents.add(event);
              } else {
                // throw error with example input
              }
            });

            planState.events = newEvents;
          } else {
            // throw error with example input
          }
          break;
        case 'prefetch':
          if (Array.isArray(value)) {
            const newPrefetchurls: string[] = [];
            value.forEach((input) => {
              if (typeof input === 'string') {
                newPrefetchurls.push(input);
                planState.prefetchsources[input] =
                  playerRef.current?.preload(input);
              } else {
                // throw error with example input
              }
            });

            planState.prefetchurls = newPrefetchurls;
            planState.inputs.push({
              name: 'prefetch',
              type: PlanInputType.Action,
              icon: 'web',
              args: [PlanInputActionArg.Prefetch],
            });
          } else {
            // throw error with example input
          }
          break;
        default:
          console.info(lname, plandata[name]);
          break;
      }
    });

    if (!planState.url) {
      planState.url = defaultUrl;
    }
  }