|
1 | 1 | import {
|
2 |
| - decodeUrl, commonUrls as defaultCommonUrls, getCommonUrls, |
3 |
| - getHostType, getSlugIfNeeded, IGristUrlState, parseFirstUrlPart |
| 2 | + decodeUrl, getHostType, getSlugIfNeeded, IGristUrlState, parseFirstUrlPart |
4 | 3 | } from 'app/common/gristUrls';
|
5 | 4 | import {assert} from 'chai';
|
6 | 5 | import Sinon from 'sinon';
|
@@ -166,94 +165,4 @@ describe('gristUrls', function() {
|
166 | 165 | assert.strictEqual(getSlugIfNeeded({id, urlId, name: "S&P500 is ~$4,894.16"}), 'SandP500-is-dollar489416');
|
167 | 166 | });
|
168 | 167 | });
|
169 |
| - |
170 |
| - describe('getCommonUrls', function () { |
171 |
| - it('should return the default URLs', function () { |
172 |
| - const commonUrls = getCommonUrls(); |
173 |
| - assert.isObject(commonUrls); |
174 |
| - assert.equal(commonUrls.help, "https://support.getgrist.com"); |
175 |
| - }); |
176 |
| - |
177 |
| - describe("with GRIST_CUSTOM_COMMON_URLS env var set", function () { |
178 |
| - it('should return the values set by the GRIST_CUSTOM_COMMON_URLS env var', function () { |
179 |
| - const customHelpCenterUrl = "http://custom.helpcenter"; |
180 |
| - sandbox.define(process.env, 'GRIST_CUSTOM_COMMON_URLS', |
181 |
| - `{"help": "${customHelpCenterUrl}"}`); |
182 |
| - const commonUrls = getCommonUrls(); |
183 |
| - assert.isObject(commonUrls); |
184 |
| - assert.equal(commonUrls.help, customHelpCenterUrl); |
185 |
| - assert.equal(commonUrls.helpAccessRules, "https://support.getgrist.com/access-rules"); |
186 |
| - }); |
187 |
| - |
188 |
| - it('should throw when keys extraneous to the ICommonUrls interface are added', function () { |
189 |
| - const nonExistingKey = 'iDontExist'; |
190 |
| - sandbox.define(process.env, 'GRIST_CUSTOM_COMMON_URLS', |
191 |
| - `{"${nonExistingKey}": "foo", "help": "https://getgrist.com"}`); |
192 |
| - assert.throws(() => getCommonUrls(), `value.${nonExistingKey} is extraneous`); |
193 |
| - }); |
194 |
| - |
195 |
| - it('should throw when the passed JSON is malformed', function () { |
196 |
| - sandbox.define(process.env, 'GRIST_CUSTOM_COMMON_URLS', '{"malformed": 42'); |
197 |
| - assert.throws(() => getCommonUrls(), 'The JSON passed to GRIST_CUSTOM_COMMON_URLS is malformed'); |
198 |
| - }); |
199 |
| - |
200 |
| - it('should throw when keys has unexpected type', function () { |
201 |
| - const regularValueKey = 'help'; |
202 |
| - const numberValueKey = 'helpAccessRules'; |
203 |
| - const objectValueKey = 'helpAssistant'; |
204 |
| - const arrayValueKey = 'helpAssistantDataUse'; |
205 |
| - const nullValueKey = 'helpFormulaAssistantDataUse'; |
206 |
| - |
207 |
| - sandbox.define(process.env, 'GRIST_CUSTOM_COMMON_URLS', |
208 |
| - JSON.stringify({ |
209 |
| - [regularValueKey]: "https://getgrist.com", |
210 |
| - [numberValueKey]: 42, |
211 |
| - [objectValueKey]: {"key": "value"}, |
212 |
| - [arrayValueKey]: ["foo"], |
213 |
| - }) |
214 |
| - ); |
215 |
| - const buildExpectedErrRegEx = (...keys: string[]) => new RegExp( |
216 |
| - keys.map(key => `value\\.${key}`).join('.*'), |
217 |
| - 'ms' |
218 |
| - ); |
219 |
| - assert.throws(() => getCommonUrls(), buildExpectedErrRegEx(numberValueKey, objectValueKey, arrayValueKey)); |
220 |
| - sandbox.restore(); |
221 |
| - sandbox.define(process.env, 'GRIST_CUSTOM_COMMON_URLS', |
222 |
| - JSON.stringify({ |
223 |
| - [regularValueKey]: "https://getgrist.com", |
224 |
| - [nullValueKey]: null, |
225 |
| - }) |
226 |
| - ); |
227 |
| - assert.throws(() => getCommonUrls(), buildExpectedErrRegEx(nullValueKey)); |
228 |
| - }); |
229 |
| - |
230 |
| - it("should return the default URLs when the parsed value is not an object", function () { |
231 |
| - sandbox.define(process.env, "GRIST_CUSTOM_COMMON_URLS", "42"); |
232 |
| - assert.deepEqual(getCommonUrls(), defaultCommonUrls); |
233 |
| - sandbox.restore(); |
234 |
| - sandbox.define(process.env, "GRIST_CUSTOM_COMMON_URLS", "null"); |
235 |
| - assert.deepEqual(getCommonUrls(), defaultCommonUrls); |
236 |
| - }); |
237 |
| - }); |
238 |
| - |
239 |
| - describe("client-side when customized by the admin", function () { |
240 |
| - it("should read the admin-defined values gristConfig", function () { |
241 |
| - sandbox.define(globalThis, 'window', { |
242 |
| - gristConfig: { |
243 |
| - adminDefinedUrls: JSON.stringify({ |
244 |
| - help: "https://getgrist.com" |
245 |
| - }) |
246 |
| - }, |
247 |
| - // Fake location to make isClient() believe the code is executed client-side. |
248 |
| - location: { |
249 |
| - hostname: 'getgrist.com' |
250 |
| - }, |
251 |
| - }); |
252 |
| - const commonUrls = getCommonUrls(); |
253 |
| - assert.isObject(commonUrls); |
254 |
| - assert.equal(commonUrls.help, "https://getgrist.com"); |
255 |
| - assert.equal(commonUrls.helpAccessRules, "https://support.getgrist.com/access-rules"); |
256 |
| - }); |
257 |
| - }); |
258 |
| - }); |
259 | 168 | });
|
0 commit comments