|
| 1 | +import { Selector } from 'testcafe'; |
| 2 | +import { keyLength, rte } from '../../../helpers/constants'; |
| 3 | +import { addKeysViaCli, deleteKeysViaCli, keyTypes } from '../../../helpers/keys'; |
| 4 | +import { acceptLicenseTermsAndAddDatabaseApi } from '../../../helpers/database'; |
| 5 | +import { BrowserPage } from '../../../pageObjects'; |
| 6 | +import { commonUrl, ossStandaloneConfig } from '../../../helpers/conf'; |
| 7 | +import { deleteStandaloneDatabaseApi } from '../../../helpers/api/api-database'; |
| 8 | +import { Common } from '../../../helpers/common'; |
| 9 | + |
| 10 | +const browserPage = new BrowserPage(); |
| 11 | +const common = new Common(); |
| 12 | + |
| 13 | +const keysData = keyTypes.map(object => ({ ...object })).filter((v, i) => i <= 6 && i !== 5); |
| 14 | +keysData.forEach(key => key.keyName = `${key.keyName}` + '-' + `${common.generateWord(keyLength)}`); |
| 15 | +const formatters = [{ |
| 16 | + format: 'JSON', |
| 17 | + fromText: '{ "field": "value" }' |
| 18 | +}, { |
| 19 | + format: 'Msgpack', |
| 20 | + fromText: '{ "field": "value" }', |
| 21 | + toText: 'DF00000001A56669656C64A576616C7565' |
| 22 | +}, { |
| 23 | + format: 'ASCII', |
| 24 | + fromText: '山女子水 рус ascii', |
| 25 | + toText: '\\xe5\\xb1\\xb1\\xe5\\xa5\\xb3\\xe5\\xad\\x90\\xe6\\xb0\\xb4 \\xd1\\x80\\xd1\\x83\\xd1\\x81 ascii' |
| 26 | +}, { |
| 27 | + format: 'HEX', |
| 28 | + fromText: '山女子水 рус ascii', |
| 29 | + toText: 'e5b1b1e5a5b3e5ad90e6b0b420d180d183d181206173636969' |
| 30 | +}]; |
| 31 | + |
| 32 | +fixture `Formatters` |
| 33 | + .meta({ |
| 34 | + type: 'regression', |
| 35 | + rte: rte.standalone |
| 36 | + }) |
| 37 | + .page(commonUrl) |
| 38 | + .beforeEach(async() => { |
| 39 | + await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName); |
| 40 | + // Create new keys |
| 41 | + await addKeysViaCli(keysData); |
| 42 | + }) |
| 43 | + .afterEach(async() => { |
| 44 | + // Clear keys and database |
| 45 | + await deleteKeysViaCli(keysData); |
| 46 | + await deleteStandaloneDatabaseApi(ossStandaloneConfig); |
| 47 | + }); |
| 48 | +test |
| 49 | + .before(async() => { |
| 50 | + await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName); |
| 51 | + // Create new keys |
| 52 | + await addKeysViaCli(keysData, formatters[0].fromText, formatters[0].fromText); |
| 53 | + })('Verify that user can see highlighted key details in JSON format', async t => { |
| 54 | + // Verify for Hash, List, Set, ZSet, String, Stream keys |
| 55 | + for (let i = 0; i < keysData.length; i++) { |
| 56 | + const valueSelector = Selector(`[data-testid^=${keysData[i].keyName.split('-')[0]}-][data-testid*=${keysData[i].data}]`); |
| 57 | + await browserPage.openKeyDetailsByKeyName(keysData[i].keyName); |
| 58 | + // Verify that json value not formatted with default formatter |
| 59 | + await t.expect(valueSelector.find(browserPage.cssJsonValue).exists).notOk(`${keysData[i].textType} Value is formatted to JSON`); |
| 60 | + await browserPage.selectFormatter('JSON'); |
| 61 | + // Verify that json value is formatted and highlighted |
| 62 | + await t.expect(valueSelector.find(browserPage.cssJsonValue).exists).ok(`${keysData[i].textType} Value is not formatted to JSON`); |
| 63 | + // Verify that Hash field is formatted to json and highlighted |
| 64 | + if (keysData[i].keyName === 'hash') { |
| 65 | + await t.expect(browserPage.hashField.find(browserPage.cssJsonValue).exists).ok('Hash field is not formatted to JSON'); |
| 66 | + } |
| 67 | + // Verify that Stream field is formatted to json and highlighted |
| 68 | + if (keysData[i].keyName === 'stream') { |
| 69 | + await t.expect(Selector(browserPage.cssJsonValue).count).eql(2, 'Hash field is not formatted to JSON'); |
| 70 | + } |
| 71 | + } |
| 72 | + }); |
| 73 | +test('Verify that user can edit the values in the key regardless if they are valid in JSON/Msgpack format or not', async t => { |
| 74 | + // Verify for JSON and Msgpack formatters |
| 75 | + const invalidText = 'invalid text'; |
| 76 | + for (const formatter of formatters) { |
| 77 | + if (formatter.format === 'JSON' || formatter.format === 'Msgpack') { |
| 78 | + // Open key details and select formatter |
| 79 | + await browserPage.openKeyDetails(keysData[0].keyName); |
| 80 | + await browserPage.selectFormatter(formatter.format); |
| 81 | + await browserPage.editHashKeyValue(invalidText); |
| 82 | + // Verify that invalid value can be saved |
| 83 | + await t.expect(browserPage.hashFieldValue.textContent).contains(invalidText, `Invalid ${formatter.format} value is not saved`); |
| 84 | + await browserPage.editHashKeyValue(formatter.fromText); |
| 85 | + // Verify that valid value can be saved |
| 86 | + await t.expect(browserPage.hashFieldValue.innerText).contains(formatter.fromText, `Valid ${formatter.format} value is not saved`); |
| 87 | + await t.expect(browserPage.hashFieldValue.find(browserPage.cssJsonValue).exists).ok(`Value is not formatted to ${formatter.format}`); |
| 88 | + } |
| 89 | + } |
| 90 | +}); |
| 91 | +test('Verify that user can see tooltip with convertion failed message on hover when data is not valid JSON/Msgpack', async t => { |
| 92 | + // Verify for JSON and Msgpack formatters |
| 93 | + for (const formatter of formatters) { |
| 94 | + if (formatter.format === 'JSON' || formatter.format === 'Msgpack') { |
| 95 | + const failedMessage = `Failed to convert to ${formatter.format}`; |
| 96 | + for (let i = 0; i < keysData.length; i++) { |
| 97 | + const valueSelector = Selector(`[data-testid^=${keysData[i].keyName.split('-')[0]}-][data-testid*=${keysData[i].data}]`); |
| 98 | + // Open key details and select formatter |
| 99 | + await browserPage.openKeyDetailsByKeyName(keysData[i].keyName); |
| 100 | + await browserPage.selectFormatter(formatter.format); |
| 101 | + // Verify that not valid value is not formatted |
| 102 | + await t.expect(valueSelector.find(browserPage.cssJsonValue).exists).notOk(`${keysData[i].textType} Value is formatted to ${formatter.format}`); |
| 103 | + await t.hover(valueSelector, { offsetX: 5 }); |
| 104 | + // Verify that tooltip with convertion failed message displayed |
| 105 | + await t.expect(browserPage.tooltip.textContent).contains(failedMessage, `"${failedMessage}" is not displayed in tooltip`); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +}); |
| 110 | +test |
| 111 | + .before(async() => { |
| 112 | + await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName); |
| 113 | + // Create new keys |
| 114 | + await addKeysViaCli(keysData, formatters[1].fromText); |
| 115 | + })('Verify that user can see highlighted key details in Msgpack format', async t => { |
| 116 | + // Open HaSH key details |
| 117 | + await browserPage.openKeyDetailsByKeyName(keysData[0].keyName); |
| 118 | + // Verify that msgpack value not formatted with default formatter |
| 119 | + await t.expect(browserPage.hashFieldValue.find(browserPage.cssJsonValue).exists).notOk('Value is formatted to Msgpack'); |
| 120 | + // Add valid msgpack in HEX format |
| 121 | + await browserPage.selectFormatter('HEX'); |
| 122 | + await browserPage.editHashKeyValue(formatters[1].toText!); |
| 123 | + await browserPage.selectFormatter('Msgpack'); |
| 124 | + // Verify that msgpack value is formatted and highlighted |
| 125 | + await t.expect(browserPage.hashFieldValue.innerText).contains(formatters[1].fromText!, 'Value is not saved as msgpack'); |
| 126 | + await t.expect(browserPage.hashFieldValue.find(browserPage.cssJsonValue).exists).ok('Value is not formatted to Msgpack'); |
| 127 | + }); |
| 128 | +test |
| 129 | + .before(async() => { |
| 130 | + await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName); |
| 131 | + // Create new keys |
| 132 | + await addKeysViaCli(keysData, formatters[2].fromText); |
| 133 | + })('Verify that user can see key details converted to ASCII/HEX format', async t => { |
| 134 | + // Verify for ASCII and HEX formatters |
| 135 | + for (const formatter of formatters) { |
| 136 | + if (formatter.format === 'ASCII' || formatter.format === 'HEX') { |
| 137 | + // Verify for Hash, List, Set, ZSet, String, Stream keys |
| 138 | + for (let i = 0; i < keysData.length; i++) { |
| 139 | + const valueSelector = Selector(`[data-testid^=${keysData[i].keyName.split('-')[0]}-][data-testid*=${keysData[i].data}]`); |
| 140 | + await browserPage.openKeyDetailsByKeyName(keysData[i].keyName); |
| 141 | + // Verify that value not formatted with default formatter |
| 142 | + await t.expect(valueSelector.innerText).contains(formatter.fromText!, `Value is formatted as ${formatter.format} in Unicode`); |
| 143 | + await browserPage.selectFormatter(formatter.format); |
| 144 | + // Verify that value is formatted |
| 145 | + await t.expect(valueSelector.innerText).contains(formatter.toText!, `Value is formatted to ${formatter.format}`); |
| 146 | + // Verify that Hash field is formatted to ASCII/HEX |
| 147 | + if (keysData[i].keyName === 'hash') { |
| 148 | + await t.expect(browserPage.hashField.innerText).contains(formatter.toText!, `Hash field is not formatted to ${formatter.format}`); |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + }); |
| 154 | +test('Verify that user can edit value for Hash field in ASCII/HEX and convert then to another format', async t => { |
| 155 | + // Verify for ASCII and HEX formaterrs |
| 156 | + for (const formatter of formatters) { |
| 157 | + if (formatter.format === 'ASCII' || formatter.format === 'HEX') { |
| 158 | + // Open key details and select formatter |
| 159 | + await browserPage.openKeyDetails(keysData[0].keyName); |
| 160 | + await browserPage.selectFormatter(formatter.format); |
| 161 | + // Add value in selected format |
| 162 | + await browserPage.editHashKeyValue(formatter.toText!); |
| 163 | + // Verify that value saved in selected format |
| 164 | + await t.expect(browserPage.hashFieldValue.innerText).contains(formatter.toText!, `${formatter.format} value is not saved`); |
| 165 | + await browserPage.selectFormatter('Unicode'); |
| 166 | + // Verify that value converted to Unicode |
| 167 | + await t.expect(browserPage.hashFieldValue.innerText).contains(formatter.fromText!, `${formatter.format} value is not converted to Unicode`); |
| 168 | + } |
| 169 | + } |
| 170 | +}); |
0 commit comments