<commit_before>require 'test_helper'

class LevelsHelperTest < ActionView::TestCase
  include LocaleHelper

  setup do
    @maze_data = {:game_id=>25, :user_id => 1, :name=>"__bob4", :level_num=>"custom", :skin=>"birds", :instructions=>"sdfdfs"}
    @level = Maze.create(@maze_data)
  end

  test "should parse maze level with non string array" do
    @level.properties["maze"] = [[0, 0], [2, 3]]
    options = blockly_options
    assert (options[:level]["map"].is_a? Array), "Maze is not an array"

    @level.properties["maze"] = @level.properties["maze"].to_s
    options = blockly_options
    assert (options[:level]["map"].is_a? Array), "Maze is not an array"
  end

  test "non-custom level displays localized instruction after locale switch" do
    DEFAULT_LOCALE = 'en-us'
    NEW_LOCALE = 'es-es'
    @level.game.name = 'maze'
    @level.level_num = '2_2'

    I18n.locale = DEFAULT_LOCALE
    options = blockly_options
    assert_equal I18n.t("data.level.instructions.#{@level.game.name}_#{@level.level_num}", locale: DEFAULT_LOCALE), options[:level]['instructions']

    I18n.locale = NEW_LOCALE
    options = blockly_options
    assert_equal I18n.t("data.level.instructions.#{@level.game.name}_#{@level.level_num}", locale: NEW_LOCALE), options[:level]['instructions']
    I18n.locale = DEFAULT_LOCALE
  end

  test "custom level displays english instruction" do
    DEFAULT_LOCALE = 'en-us'
    @level.name = 'frozen line'

    I18n.locale = DEFAULT_LOCALE
    options = blockly_options    
    assert_equal @level.instructions, options[:level]['instructions']
  end

  test "custom level displays localized instruction if exists" do
    DEFAULT_LOCALE = 'en-us'
    NEW_LOCALE = 'es-es'
    
    I18n.locale = NEW_LOCALE
    @level.name = 'frozen line'<commit_msg>update test for legacy level instructions<commit_after>require 'test_helper'

class LevelsHelperTest < ActionView::TestCase
  include LocaleHelper

  setup do
    @maze_data = {:game_id=>25, :user_id => 1, :name=>"__bob4", :level_num=>"custom", :skin=>"birds", :instructions=>"sdfdfs"}
    @level = Maze.create(@maze_data)
  end

  test "should parse maze level with non string array" do
    @level.properties["maze"] = [[0, 0], [2, 3]]
    options = blockly_options
    assert (options[:level]["map"].is_a? Array), "Maze is not an array"

    @level.properties["maze"] = @level.properties["maze"].to_s
    options = blockly_options
    assert (options[:level]["map"].is_a? Array), "Maze is not an array"
  end

  test "non-custom level displays localized instruction after locale switch" do
    DEFAULT_LOCALE = 'en-us'
    NEW_LOCALE = 'es-es'
    @level.instructions = nil
    @level.level_num = '2_2'

    I18n.locale = DEFAULT_LOCALE
    options = blockly_options
    assert_equal I18n.t('data.level.instructions.maze_2_2', locale: DEFAULT_LOCALE), options[:level]['instructions']

    I18n.locale = NEW_LOCALE
    options = blockly_options
    assert_equal I18n.t('data.level.instructions.maze_2_2', locale: NEW_LOCALE), options[:level]['instructions']
    I18n.locale = DEFAULT_LOCALE
  end

  test "custom level displays english instruction" do
    DEFAULT_LOCALE = 'en-us'
    @level.name = 'frozen line'

    I18n.locale = DEFAULT_LOCALE
    options = blockly_options    
    assert_equal @level.instructions, options[:level]['instructions']
  end

  test "custom level displays localized instruction if exists" do
    DEFAULT_LOCALE = 'en-us'
    NEW_LOCALE = 'es-es'
    
    I18n.locale = NEW_LOCALE
    @level.name = 'frozen line'
{'fraction_non_alphanumeric': 0.12918796138557637, 'fraction_numerical': 0.014764338444065871, 'mean_word_length': 4.069064748201439, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991172', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1169, 'n_words': 274}