File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 11export const constructChangesetUrl = ( task ) => {
22 if (
33 process . env . REACT_APP_CHANGESET_URL === "enabled" &&
4+ task ?. parent ?. id &&
45 task . parent . changesetUrl
56 ) {
67 return ` ${ window . location . origin } /browse/challenges/${ task . parent . id } ` ;
Original file line number Diff line number Diff line change 1+ import { constructChangesetUrl } from "./constructChangesetUrl" ;
2+
3+ describe ( "constructChangesetUrl" , ( ) => {
4+ const cachedEnv = process . env ;
5+
6+ beforeEach ( ( ) => {
7+ jest . resetModules ( ) ;
8+ process . env = { ...cachedEnv , REACT_APP_CHANGESET_URL : "enabled" } ;
9+ } ) ;
10+
11+ afterAll ( ( ) => {
12+ process . env = cachedEnv ;
13+ } ) ;
14+
15+ it ( "returns empty string if no task is provided" , ( ) => {
16+ expect ( constructChangesetUrl ( ) ) . toBe ( "" ) ;
17+ } ) ;
18+
19+ it ( "returns empty string if env variabled is disabled" , ( ) => {
20+ process . env . REACT_APP_CHANGESET_URL = "disabled" ;
21+ const task = { parent : { changesetUrl : true , id : 1 } } ;
22+ expect ( constructChangesetUrl ( task ) ) . toBe ( "" ) ;
23+ } ) ;
24+
25+ it ( "returns empty string changesetUrl is false" , ( ) => {
26+ const task = { parent : { changesetUrl : false , id : 1 } } ;
27+ expect ( constructChangesetUrl ( task ) ) . toBe ( "" ) ;
28+ } ) ;
29+
30+ it ( "returns correct url if changesetUrl is true" , ( ) => {
31+ const task = { parent : { changesetUrl : true , id : 1 } } ;
32+ expect ( constructChangesetUrl ( task ) ) . toBe (
33+ " http://localhost/browse/challenges/1"
34+ ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments