| 113 | * @param {t.TestCase} tc |
| 114 | */ |
| 115 | export const testBasicMapTests = tc => { |
| 116 | const { testConnector, users, map0, map1, map2 } = init(tc, { users: 3 }) |
| 117 | users[2].disconnect() |
| 118 | |
| 119 | map0.setAttr('null', null) |
| 120 | map0.setAttr('number', 1) |
| 121 | map0.setAttr('string', 'hello Y') |
| 122 | map0.setAttr('object', { key: { key2: 'value' } }) |
| 123 | map0.setAttr('y-map', new Y.Type()) |
| 124 | map0.setAttr('boolean1', true) |
| 125 | map0.setAttr('boolean0', false) |
| 126 | const map = map0.getAttr('y-map') |
| 127 | map.setAttr('y-array', new Y.Type()) |
| 128 | const array = map.getAttr('y-array') |
| 129 | array.insert(0, [0]) |
| 130 | array.insert(0, [-1]) |
| 131 | |
| 132 | t.assert(map0.getAttr('null') === null, 'client 0 computed the change (null)') |
| 133 | t.assert(map0.getAttr('number') === 1, 'client 0 computed the change (number)') |
| 134 | t.assert(map0.getAttr('string') === 'hello Y', 'client 0 computed the change (string)') |
| 135 | t.assert(map0.getAttr('boolean0') === false, 'client 0 computed the change (boolean)') |
| 136 | t.assert(map0.getAttr('boolean1') === true, 'client 0 computed the change (boolean)') |
| 137 | t.compare(map0.getAttr('object'), { key: { key2: 'value' } }, 'client 0 computed the change (object)') |
| 138 | t.assert(map0.getAttr('y-map').getAttr('y-array').get(0) === -1, 'client 0 computed the change (type)') |
| 139 | t.assert(map0.attrSize === 7, 'client 0 map has correct size') |
| 140 | |
| 141 | users[2].connect() |
| 142 | testConnector.flushAllMessages() |
| 143 | |
| 144 | t.assert(map1.getAttr('null') === null, 'client 1 received the update (null)') |
| 145 | t.assert(map1.getAttr('number') === 1, 'client 1 received the update (number)') |
| 146 | t.assert(map1.getAttr('string') === 'hello Y', 'client 1 received the update (string)') |
| 147 | t.assert(map1.getAttr('boolean0') === false, 'client 1 computed the change (boolean)') |
| 148 | t.assert(map1.getAttr('boolean1') === true, 'client 1 computed the change (boolean)') |
| 149 | t.compare(map1.getAttr('object'), { key: { key2: 'value' } }, 'client 1 received the update (object)') |
| 150 | t.assert(map1.getAttr('y-map').getAttr('y-array').get(0) === -1, 'client 1 received the update (type)') |
| 151 | t.assert(map1.attrSize === 7, 'client 1 map has correct size') |
| 152 | |
| 153 | // compare disconnected user |
| 154 | t.assert(map2.getAttr('null') === null, 'client 2 received the update (null) - was disconnected') |
| 155 | t.assert(map2.getAttr('number') === 1, 'client 2 received the update (number) - was disconnected') |
| 156 | t.assert(map2.getAttr('string') === 'hello Y', 'client 2 received the update (string) - was disconnected') |
| 157 | t.assert(map2.getAttr('boolean0') === false, 'client 2 computed the change (boolean)') |
| 158 | t.assert(map2.getAttr('boolean1') === true, 'client 2 computed the change (boolean)') |
| 159 | t.compare(map2.getAttr('object'), { key: { key2: 'value' } }, 'client 2 received the update (object) - was disconnected') |
| 160 | t.assert(map2.getAttr('y-map').getAttr('y-array').get(0) === -1, 'client 2 received the update (type) - was disconnected') |
| 161 | compare(users) |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @param {t.TestCase} tc |
nothing calls this directly
no test coverage detected
searching dependent graphs…