case-layout.js 1.1 KB
const _ = require('lodash');
const config = require('../config.json');


module.exports.getCases = () => {
  const cases = config.cases[global.TEST_PLATFORM];

  _.each(cases, c => {
    c.scenes = _.filter(c.scenes, s => s.driverFn);
  })
  return _.filter(cases, c => c.scenes.length);
};

module.exports.addScene = (sceneObj) => {
  const cases = config.cases[global.TEST_PLATFORM];
  let hasCase = false;

  _.each(cases, c => {
    _.each(c.scenes, (scene, inx) => {
      if (sceneObj.scene === scene) {
        hasCase = true;
        if (!c.config) {
          c.config = {
            caps: sceneObj.caps,
            serverConfig: sceneObj.serverConfig
          };
        }
        c.scenes[inx] = {
          scene,
          title: sceneObj.title,
          driverFn: sceneObj.driverFn
        }
      }
    });
  });

  if (!hasCase) {
    cases.push({
      name: sceneObj.scene,
      config: {
        caps: sceneObj.caps,
        serverConfig: sceneObj.serverConfig
      },
      scenes: [{
        scene: sceneObj.scene,
        title: sceneObj.title,
        driverFn: sceneObj.driverFn
      }]
    })
  }

}