summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/page/router/url_params.spec.js
blob: 3c550a430ececd108d7e1ff1c83a137de0d80770 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require(['page/router/url_params'], function (urlParams) {
  'use strict';

  describe('urlParams', function () {

    beforeEach(function () {
      //preventing the hash change to fire the onpopstate event in other components
      //in this case in the router component
      window.onpopstate = function () {};
    });

    afterEach(function () {
      document.location.hash = '';
    });

    describe('getTag', function () {
      it('returns inbox if there is no tag in the url hash', function () {
        expect(urlParams.getTag()).toEqual('inbox');
      });

      it('returns the tag in the hash if there is one', function () {
        document.location.hash = '#/Drafts';

        expect(urlParams.getTag()).toEqual('Drafts');
      });

      it('returns tag with slash', function () {
        document.location.hash = '#/Events/2011';

        expect(urlParams.getTag()).toEqual('Events/2011');
      });

      it('returns tag even if there is an mail ident', function () {
        document.location.hash = '#/events/2011/mail/M-123_abc';

        expect(urlParams.getTag()).toEqual('events/2011');
      });

      it('returns the tag even if there is a trailing slash', function () {
        document.location.hash = '#/Events/';

        expect(urlParams.getTag()).toEqual('Events');
      });
    });

    describe('hasMailIdent', function () {
      it('is true if hash has mailIdent', function () {
        document.location.hash = '#/inbox/mail/M-123_abc';

        expect(urlParams.hasMailIdent()).toBeTruthy();
      });

      it('is false if hash has no mail ident', function () {
        document.location.hash = '#/Drafts';

        expect(urlParams.hasMailIdent()).toBeFalsy();
      });
    });

    describe('getMailIdent', function () {
      it('returns the mail ident that is in the hash', function () {
        document.location.hash = '#/inbox/mail/M-123_abc';

        expect(urlParams.getMailIdent()).toEqual('M-123_abc');
      });

      it('supports uppercase letters and numbers as mail id', function () {
        document.location.hash = '#/inbox/mail/123ASDADA';

        expect(urlParams.getMailIdent()).toEqual('123ASDADA');
      });
    });
  });

});