| 1 |
/* eslint max-len: */ |
| 2 |
|
| 3 |
/* testPathRow.js |
| 4 |
* |
| 5 |
* Copyright 2020 Martin Abente Lahaye |
| 6 |
* |
| 7 |
* This program is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
const {setup} = imports.utils; |
| 22 |
setup(); |
| 23 |
|
| 24 |
const {FlatsealPathRow, mode, validity} = imports.widgets.pathRow; |
| 25 |
|
| 26 |
|
| 27 |
describe('FlatsealPathRow', function() { |
| 28 |
var row; |
| 29 |
|
| 30 |
beforeEach(function() { |
| 31 |
row = new FlatsealPathRow(); |
| 32 |
}); |
| 33 |
|
| 34 |
it('starts empty', function() { |
| 35 |
expect(row.text).toEqual(''); |
| 36 |
}); |
| 37 |
|
| 38 |
it('processes path correctly', function() { |
| 39 |
const text = 'home:ro'; |
| 40 |
row.text = text; |
| 41 |
|
| 42 |
expect(row.text).toEqual(text); |
| 43 |
}); |
| 44 |
|
| 45 |
it('sets ready-only style class', function() { |
| 46 |
row.text = 'home:ro'; |
| 47 |
const context = row.get_style_context(); |
| 48 |
|
| 49 |
expect(context.has_class(mode.READONLY)).toBe(true); |
| 50 |
expect(context.has_class(mode.READWRITE)).toBe(false); |
| 51 |
expect(context.has_class(mode.CREATE)).toBe(false); |
| 52 |
}); |
| 53 |
|
| 54 |
it('sets ready-write style class', function() { |
| 55 |
row.text = 'home:rw'; |
| 56 |
const context = row.get_style_context(); |
| 57 |
|
| 58 |
expect(context.has_class(mode.READONLY)).toBe(false); |
| 59 |
expect(context.has_class(mode.READWRITE)).toBe(true); |
| 60 |
expect(context.has_class(mode.CREATE)).toBe(false); |
| 61 |
}); |
| 62 |
|
| 63 |
it('sets ready-write style class (default)', function() { |
| 64 |
row.text = 'home'; |
| 65 |
const context = row.get_style_context(); |
| 66 |
|
| 67 |
expect(context.has_class(mode.READONLY)).toBe(false); |
| 68 |
expect(context.has_class(mode.READWRITE)).toBe(true); |
| 69 |
expect(context.has_class(mode.CREATE)).toBe(false); |
| 70 |
}); |
| 71 |
|
| 72 |
it('sets create style class', function() { |
| 73 |
row.text = 'home:create'; |
| 74 |
const context = row.get_style_context(); |
| 75 |
|
| 76 |
expect(context.has_class(mode.READONLY)).toBe(false); |
| 77 |
expect(context.has_class(mode.READWRITE)).toBe(false); |
| 78 |
expect(context.has_class(mode.CREATE)).toBe(true); |
| 79 |
}); |
| 80 |
|
| 81 |
function _handles(description, path, _mode) { |
| 82 |
it(`handles ${description} paths (${_mode ? _mode : 'default'})`, function() { |
| 83 |
row.text = `${path}${_mode}`; |
| 84 |
const context = row.get_style_context(); |
| 85 |
|
| 86 |
expect(context.has_class(validity.VALID)).toBe(true); |
| 87 |
expect(context.has_class(validity.NOTVALID)).toBe(false); |
| 88 |
}); |
| 89 |
} |
| 90 |
_handles('absolute', '/home/.test', ''); |
| 91 |
_handles('absolute', '/home/.test', ':ro'); |
| 92 |
_handles('absolute', '/home/.test', ':rw'); |
| 93 |
_handles('absolute', '/home/.test', ':create'); |
| 94 |
_handles('absolute', '/home/.test/', ''); |
| 95 |
_handles('relative', '~/.test', ''); |
| 96 |
_handles('relative', '~/.test', ':ro'); |
| 97 |
_handles('relative', '~/.test', ':rw'); |
| 98 |
_handles('relative', '~/.test', ':create'); |
| 99 |
_handles('relative', '~/.test/', ''); |
| 100 |
_handles('relative', '~/.local/share/Folder/Games/common/Console Classics/uncompressed GAMEs/Old_Game_wVersion3.bin', ':ro'); |
| 101 |
_handles('relative', '!~/.TelegramDesktop', ''); |
| 102 |
_handles('token-based', 'home/.test', ''); |
| 103 |
_handles('token-based', 'home/.test', ':ro'); |
| 104 |
_handles('token-based', 'home/.test', ':rw'); |
| 105 |
_handles('token-based', 'home/.test', ':create'); |
| 106 |
_handles('token-based', 'home/.test/', ''); |
| 107 |
_handles('token-based', 'xdg-download/Telegram Desktop:create', ''); |
| 108 |
_handles('token-based', '!xdg-download', ''); |
| 109 |
_handles('token-based', '!xdg-download', ':reset'); |
| 110 |
|
| 111 |
function _catches(description, path, _mode) { |
| 112 |
it(`catches ${description} paths (${_mode ? _mode : 'default'})`, function() { |
| 113 |
row.text = `${path}${_mode}`; |
| 114 |
const context = row.get_style_context(); |
| 115 |
|
| 116 |
expect(context.has_class(validity.VALID)).toBe(false); |
| 117 |
expect(context.has_class(validity.NOTVALID)).toBe(true); |
| 118 |
}); |
| 119 |
} |
| 120 |
|
| 121 |
_catches('not-valid empty', '', ''); |
| 122 |
_catches('not-valid absolute', '/', ''); |
| 123 |
_catches('not-valid relative', '~/', ''); |
| 124 |
_catches('not-valid absolute', '/home/ .test ', ''); |
| 125 |
_catches('not-valid relative', '~/ .test ', ''); |
| 126 |
_catches('not-valid token-based', 'home ', ':ro'); |
| 127 |
_catches('not-valid token-based', 'home/', ''); |
| 128 |
_catches('not-valid token-based', 'home/.test/ ', ''); |
| 129 |
_catches('not-valid token-based', 'home-non-valid', ''); |
| 130 |
_catches('not-valid token-based', 'jome/.test ', ''); |
| 131 |
_catches('not-valid mode', 'home', ':'); |
| 132 |
_catches('not-valid mode', 'home', ':not'); |
| 133 |
_catches('not-valid negation', '!!~/.TelegramDesktop', ''); |
| 134 |
_catches('not-valid negation', '!~/.TelegramDesktop', ':'); |
| 135 |
_catches('not-valid negation', '!~/.TelegramDesktop', ':ro'); |
| 136 |
}); |