diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-06-29 14:49:13 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-07-01 11:37:48 +0200 |
| commit | e6d83cc9fe4b8e951403bc3ee6d0744934b041ee (patch) | |
| tree | 29a4738c20ce56e2f29855111a235a251807e96c /gui/test | |
| parent | d962e59af7ebe3980686324d430ff1854a832445 (diff) | |
| download | mullvadvpn-e6d83cc9fe4b8e951403bc3ee6d0744934b041ee.tar.xz mullvadvpn-e6d83cc9fe4b8e951403bc3ee6d0744934b041ee.zip | |
Replace history methods with new ones more aligned with our needs
Diffstat (limited to 'gui/test')
| -rw-r--r-- | gui/test/history.spec.ts | 117 |
1 files changed, 26 insertions, 91 deletions
diff --git a/gui/test/history.spec.ts b/gui/test/history.spec.ts index 1bf00dd4ba..3087905c7b 100644 --- a/gui/test/history.spec.ts +++ b/gui/test/history.spec.ts @@ -8,7 +8,6 @@ const SECOND_PATH = '/second-path'; const THIRD_PATH = '/third-path'; const FOURTH_PATH = '/fourth-path'; const FIFTH_PATH = '/fifth-path'; -const SIXTH_PATH = '/sixth-path'; describe('History', () => { let history: History; @@ -30,139 +29,75 @@ describe('History', () => { expect(history.length).to.equal(5); }); - it('should go back', () => { - history.goBack(); + it('should pop', () => { + history.pop(); expect(history.location.pathname).to.equal(THIRD_PATH); - expect(history.length).to.equal(5); + expect(history.length).to.equal(4); }); - it('should go back three entries', () => { - history.go(-3); - expect(history.location.pathname).to.equal(FIRST_PATH); - expect(history.length).to.equal(5); - }); + it('should fail to pop', () => { + history.pop(); + history.pop(); + history.pop(); + history.pop(); - it('should go forward', () => { - history.go(-3); - history.goForward(); - expect(history.location.pathname).to.equal(SECOND_PATH); - expect(history.length).to.equal(5); - }); + expect(history.location.pathname).to.equal(BASE_PATH); + expect(history.length).to.equal(1); - it('should go forward two entries', () => { - history.go(-3); - history.go(2); - expect(history.location.pathname).to.equal(THIRD_PATH); - expect(history.length).to.equal(5); - }); + history.pop(); - it('should fail to go forward', () => { - history.goForward(); - expect(history.location.pathname).to.equal(FOURTH_PATH); - expect(history.length).to.equal(5); + expect(history.location.pathname).to.equal(BASE_PATH); + expect(history.length).to.equal(1); }); it('should push', () => { history.push(FIFTH_PATH); - history.goBack(); - expect(history.location.pathname).to.equal(FOURTH_PATH); + expect(history.location.pathname).to.equal(FIFTH_PATH); expect(history.length).to.equal(6); }); - it('should replace', () => { - history.replace(FIFTH_PATH); - history.goBack(); - expect(history.location.pathname).to.equal(THIRD_PATH); - expect(history.length).to.equal(5); - }); - - it('should fail to go backwards further than base path', () => { - history.go(-5); - expect(history.location.pathname).to.equal(FOURTH_PATH); - expect(history.length).to.equal(5); - }); - it('should go backward to base path', () => { - history.reset(); + history.dismiss(true); expect(history.location.pathname).to.equal(BASE_PATH); - expect(history.length).to.equal(5); + expect(history.length).to.equal(1); }); it('should reset entries with path', () => { - history.resetWith(THIRD_PATH); + history.reset(THIRD_PATH); expect(history.location.pathname).to.equal(THIRD_PATH); expect(history.length).to.equal(1); - - history.goBack(); - expect(history.location.pathname).to.equal(THIRD_PATH); - expect(history.length).to.equal(1); - - history.goForward(); - expect(history.location.pathname).to.equal(THIRD_PATH); - expect(history.length).to.equal(1); - }); - - it('should fail to go forward after navigating', () => { - history.goBack(); - history.push(FIFTH_PATH); - history.goForward(); - expect(history.location.pathname).to.equal(FIFTH_PATH); - - history.goBack(); - history.replace(SIXTH_PATH); - history.goForward(); - expect(history.location.pathname).to.equal(FIFTH_PATH); }); it('should add a listener', () => { const listenerA = spy(); history.listen(listenerA); - history.goBack(); - history.goForward(); + history.pop(); + history.push(FIFTH_PATH); const listenerB = spy(); history.listen(listenerB); - history.reset(); + history.dismiss(true); history.push(FIRST_PATH); - history.replace(SECOND_PATH); - expect(listenerA).to.have.been.called.exactly(5); - expect(listenerB).to.have.been.called.exactly(3); + expect(listenerA).to.have.been.called.exactly(4); + expect(listenerB).to.have.been.called.exactly(2); }); it('should remove a listener', () => { const listenerA = spy(); const removeListenerA = history.listen(listenerA); - history.goBack(); - history.goForward(); + history.pop(); + history.push(FIFTH_PATH); const listenerB = spy(); history.listen(listenerB); - history.reset(); + history.dismiss(true); removeListenerA(); history.push(FIRST_PATH); - history.replace(SECOND_PATH); + history.reset(SECOND_PATH); expect(listenerA).to.have.been.called.exactly(3); expect(listenerB).to.have.been.called.exactly(3); }); - - it('should only remove listener once', () => { - const listenerA = spy(); - const removeListenerA = history.listen(listenerA); - history.goBack(); - - const listenerB = spy(); - history.listen(listenerB); - history.goForward(); - - removeListenerA(); - removeListenerA(); - - history.reset(); - - expect(listenerA).to.have.been.called.exactly(2); - expect(listenerB).to.have.been.called.exactly(2); - }); }); |
