airbnb / DeepLinkDispatch

A simple, annotation-based library for making deep link handling better on Android
http://nerds.airbnb.com/deeplinkdispatch/
4.37k stars 407 forks source link

Dynamic Path Segment Matching #274

Closed adellhk closed 4 years ago

adellhk commented 4 years ago

Given:

Then:

The motivation here is that users should be able to declare DeepLinks with a replaceable path segment (or segments) and then replace them at runtime (e.g. based on build type or a configuration flag).

This test covers the happy path of this change (other tests cover unhappy paths):

 public void testPlaceholderSubstitution() {
    Map<String, String> pathVariableReplacements = new HashMap<>();
    pathVariableReplacements.put("replaceable-path-variable", "obamaOs");
    DeepLinkDelegate deepLinkDelegate = new DeepLinkDelegate(new SampleModuleRegistry(),
      new LibraryDeepLinkModuleRegistry(), new BenchmarkDeepLinkModuleRegistry(), pathVariableReplacements);
    assertThat(deepLinkDelegate.supportsUri("https://www.example.com/capnMcCains/bar"), equalTo(false));
    assertThat(deepLinkDelegate.supportsUri("https://www.example.com/obamaOs/bar"), equalTo(true));
  }

./gradlew check test:

Screen Shot 2020-02-12 at 9 24 46 PM