lib/lookbook/entities/preview_entity.rb in lookbook-2.0.0.beta.4 vs lib/lookbook/entities/preview_entity.rb in lookbook-2.0.0.beta.5
- old
+ new
@@ -171,14 +171,34 @@
end
protected
def load_scenarios
- return scenario_entities unless code_object.groups.any?
+ code_object.groups.any? ? grouped_scenario_entities : scenario_entities
+ end
- scenario_entities.group_by(&:group).flat_map do |group_name, grouped_scenarios|
- group_name.nil? ? grouped_scenarios : ScenarioGroupEntity.new(group_name.presence || label.pluralize, grouped_scenarios, self)
+ def grouped_scenario_entities
+ scenarios = []
+ scenario_entities.each.with_index(1) do |entity, i|
+ if entity.group.nil?
+ entity.default_priority = i
+ scenarios << entity
+ else
+ group_name = entity.group.presence || entity.parent.name.pluralize
+ group = scenarios.find do |s|
+ s.is_a?(ScenarioGroupEntity) && s.name == Utils.name(group_name)
+ end
+
+ if group
+ group.add_scenario(entity)
+ else
+ group = ScenarioGroupEntity.new(group_name, [entity], self)
+ group.default_priority = i
+ scenarios << group
+ end
+ end
end
+ scenarios
end
def scenario_entities
public_methods = preview_class.public_instance_methods(false)
method_objects = code_object.meths.select { |m| public_methods.include?(m.name) }