{"size": 2428, "ext": "js", "max_stars_repo_path": "__tests__/utils/reference/getReferences.test.js", "max_stars_repo_name": "jacoblapworth/style-dictionary", "max_stars_repo_stars_event_min_datetime": "2021-08-02T20:06:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-02T20:06:43.000Z", "max_issues_repo_path": "__tests__/utils/reference/getReferences.test.js", "max_issues_repo_name": "jjbert18/style-dictionary", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "__tests__/utils/reference/getReferences.test.js", "max_forks_repo_name": "jjbert18/style-dictionary", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.7341772152, "max_line_length": 119, "alphanum_fraction": 0.6013179572}
/*
 * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

// `.getReferences` is bound to a dictionary object, so to test it we will
// create a dictionary object and then call `.getReferences` on it.
const createDictionary = require('../../../lib/utils/createDictionary');

const properties = {
  color: {
    red: { value: "#f00" },
    danger: { value: "{color.red.value}" }
  },
  size: {
    border: { value: "2px" }
  },
  border: {
    primary: {
      // getReferences should work on objects like this:
      value: {
        color: "{color.red.value}",
        width: "{size.border.value}",
        style: "solid"
      }
    },
    secondary: {
      // getReferences should work on interpolated values like this:
      value: "{size.border.value} solid {color.red.value}"
    }
  }
}

const dictionary = createDictionary({ properties });

describe('utils', () => {
  describe('reference', () => {
    describe('getReferences()', () => {
      it(`should return an empty array if the value has no references`, () => {
        expect(dictionary.getReferences(properties.color.red.value)).toEqual([]);
      });

      it(`should work with a single reference`, () => {
        expect(dictionary.getReferences(properties.color.danger.value)).toEqual(
          expect.arrayContaining([
            {value: "#f00"}
          ])
        );
      });

      it(`should work with object values`, () => {
        expect(dictionary.getReferences(properties.border.primary.value)).toEqual(
          expect.arrayContaining([
            {value: "2px"},
            {value: "#f00"}
          ])
        );
      });

      it(`should work with interpolated values`, () => {
        expect(dictionary.getReferences(properties.border.secondary.value)).toEqual(
          expect.arrayContaining([
            {value: "2px"},
            {value: "#f00"}
          ])
        );
      });
    });
  });
});
