diff --git a/tests/formatters.codesearch.test.js b/tests/formatters.codesearch.test.js index 919bed611..53179ba0b 100644 --- a/tests/formatters.codesearch.test.js +++ b/tests/formatters.codesearch.test.js @@ -2,11 +2,17 @@ import { getCodeSearchLink } from "../src/formatters/codesearch"; describe("Searchfox links for firefox-desktop", () => { it("works as expected", () => { - expect(getCodeSearchLink("firefox_desktop", "test.metric_name")).toBe( + expect( + getCodeSearchLink("test.metric_name", "firefox_desktop", { + source_url: "https://foo.bar", + }) + ).toBe( "https://searchfox.org/mozilla-central/search?q=test.metric_name|test.metricName|Test.metricName|test.metric_name|test::metric_name®exp=true" ); expect( - getCodeSearchLink("firefox_desktop", "test_category.test_name") + getCodeSearchLink("test_category.test_name", "firefox_desktop", { + source_url: "https://foo.bar", + }) ).toBe( "https://searchfox.org/mozilla-central/search?q=test_category.test_name|testCategory.testName|TestCategory.testName|test_category.test_name|test_category::test_name®exp=true" ); @@ -15,18 +21,46 @@ describe("Searchfox links for firefox-desktop", () => { describe("Searchfox links for applications in mozilla-mobile", () => { it("works as expected", () => { - expect(getCodeSearchLink("fenix", "test.metric_name")).toBe( + expect( + getCodeSearchLink("test.metric_name", "fenix", { + source_url: "https://foo.bar", + }) + ).toBe( "https://searchfox.org/mozilla-mobile/search?q=test.metric_name|test.metricName|Test.metricName|test.metric_name|test::metric_name&path=fenix®exp=true" ); - expect(getCodeSearchLink("fenix", "test_category.test_name")).toBe( + expect( + getCodeSearchLink("test_category.test_name", "fenix", { + source_url: "https://foo.bar", + }) + ).toBe( "https://searchfox.org/mozilla-mobile/search?q=test_category.test_name|testCategory.testName|TestCategory.testName|test_category.test_name|test_category::test_name&path=fenix®exp=true" ); + expect( + getCodeSearchLink("test_category.test_name", "fenix", { + source_url: + "https://github.com/mozilla/application-services/foo/bar/metrics.yaml", + }) + ).toBe( + "https://searchfox.org/mozilla-mobile/search?q=test_category.test_name|testCategory.testName|TestCategory.testName|test_category.test_name|test_category::test_name&path=application-services®exp=true" + ); + expect( + getCodeSearchLink("test_category.test_name", "firefox_ios", { + source_url: + "https://github.com/mozilla/application-services/foo/bar/metrics.yaml", + }) + ).toBe( + "https://searchfox.org/mozilla-mobile/search?q=test_category.test_name|testCategory.testName|TestCategory.testName|test_category.test_name|test_category::test_name&path=application-services®exp=true" + ); }); }); describe("returns Sourcegraph link if the application is not indexed on Searchfox", () => { it("works as expected", () => { - expect(getCodeSearchLink("mozregression", "usage.bad_date")).toBe( + expect( + getCodeSearchLink("usage.bad_date", "mozregression", { + source_url: "https://foo.bar", + }) + ).toBe( "https://sourcegraph.com/search?q=repo:%5Egithub%5C.com%5C/%5BMm%5Dozilla%28.*%29%5C/mozregression%24+usage.bad_date|usage.badDate|Usage.badDate|usage.bad_date|usage::bad_date&patternType=regexp" ); }); @@ -34,6 +68,8 @@ describe("returns Sourcegraph link if the application is not indexed on Searchfo describe("returns undefined if the application cannot be indexed", () => { it("works as expected", () => { - expect(getCodeSearchLink("foo", "test.metric")).toBeUndefined(); + expect( + getCodeSearchLink("test.metric", "foo", { source_url: "https://foo.bar" }) + ).toBeUndefined(); }); });