mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	This mainly extracts a new module called
browser_history. It has much fewer dependencies
than hashchange.js, so any modules that just
need the smaller API from browser_history now
have fewer transitive dependencies.
Here are some details:
    * Move is_overlay_hash to hash_util.
    * Rename hashchange.update_browser_history to
      brower_history.update
    * Move go_to_location verbatim.
    * Remove unused argument for exit_overlay.
    * Introduce helper functions:
        * old_hash()
        * set_hash_before_overlay()
        * save_old_hash()
We now have 100% line coverage on the extracted
code.
		
	
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const {strict: assert} = require("assert");
 | 
						|
 | 
						|
const {set_global, zrequire} = require("../zjsunit/namespace");
 | 
						|
const {run_test} = require("../zjsunit/test");
 | 
						|
const blueslip = require("../zjsunit/zblueslip");
 | 
						|
 | 
						|
const browser_history = zrequire("browser_history");
 | 
						|
 | 
						|
const location = set_global("location", {
 | 
						|
    hash: "bogus",
 | 
						|
});
 | 
						|
 | 
						|
function test(label, f) {
 | 
						|
    run_test(label, (override) => {
 | 
						|
        location.hash = "bogus";
 | 
						|
        browser_history.clear_for_testing();
 | 
						|
        f(override);
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
test("basics", () => {
 | 
						|
    const hash1 = "#settings/your-account";
 | 
						|
    const hash2 = "#narrow/is/private";
 | 
						|
    browser_history.go_to_location(hash1);
 | 
						|
    assert.equal(location.hash, hash1);
 | 
						|
 | 
						|
    browser_history.update(hash2);
 | 
						|
    assert.equal(location.hash, hash2);
 | 
						|
    assert.equal(browser_history.old_hash(), hash1);
 | 
						|
 | 
						|
    const was_internal_change = browser_history.save_old_hash();
 | 
						|
    assert(was_internal_change);
 | 
						|
    assert.equal(browser_history.old_hash(), hash2);
 | 
						|
});
 | 
						|
 | 
						|
test("update with same hash", () => {
 | 
						|
    const hash = "#keyboard-shortcuts";
 | 
						|
 | 
						|
    browser_history.update(hash);
 | 
						|
    assert.equal(location.hash, hash);
 | 
						|
    browser_history.update(hash);
 | 
						|
    assert.equal(location.hash, hash);
 | 
						|
});
 | 
						|
 | 
						|
test("error for bad hashes", () => {
 | 
						|
    const hash = "bogus";
 | 
						|
    blueslip.expect("error", "programming error: prefix hashes with #: bogus");
 | 
						|
    browser_history.update(hash);
 | 
						|
});
 |