|
| 1 | +classdef testplotlyoffline < matlab.unittest.TestCase |
| 2 | + |
| 3 | + properties |
| 4 | + creds = loadplotlycredentials; |
| 5 | + config = loadplotlyconfig; |
| 6 | + username = 'test_user_name'; |
| 7 | + api_key = 'test_api_keu'; |
| 8 | + plotly_domain = 'test_plotly_domain'; |
| 9 | + end |
| 10 | + |
| 11 | + methods(TestMethodTeardown) |
| 12 | + function setCredentials(testCase) |
| 13 | + saveplotlycredentials(testCase.creds.username, ... |
| 14 | + testCase.creds.api_key, ... |
| 15 | + testCase.creds.stream_ids); |
| 16 | + end |
| 17 | + function setConfig(testCase) |
| 18 | + saveplotlyconfig(testCase.config.plotly_domain, ... |
| 19 | + testCase.config.plotly_streaming_domain); |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + methods (Test) |
| 24 | + |
| 25 | + function testGetPlotlyOfflineInvalidLink(testCase) |
| 26 | + |
| 27 | + invalid_link = 'http://purchasing.plot.ly/invalid'; |
| 28 | + actual = 'this should get modified'; |
| 29 | + |
| 30 | + try |
| 31 | + getplotlyoffline(invalid_link); |
| 32 | + catch exception |
| 33 | + actual = exception.message; |
| 34 | + end |
| 35 | + |
| 36 | + expected = ['Whoops! There was an error attempting to ', ... |
| 37 | + 'download the MATLAB offline Plotly bundle. ', ... |
| 38 | + 'Status: 404 NOT FOUND.']; |
| 39 | + |
| 40 | + testCase.verifyEqual(actual,expected); |
| 41 | + end |
| 42 | + |
| 43 | + function testGetPlotlyOfflineCreateDir(testCase) |
| 44 | + |
| 45 | + % get plotlyjs dir |
| 46 | + userhome = getuserdir(); |
| 47 | + plotly_config_folder = fullfile(userhome, '.plotly'); |
| 48 | + plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs'); |
| 49 | + |
| 50 | + test_link = ['https://gist.githubusercontent.com/chriddyp', ... |
| 51 | + '/f40bd33d1eab6f0715dc/raw/24cd2e4e62ceea79e6', ... |
| 52 | + 'e790b3a2c94cda63510ede/test.js']; |
| 53 | + |
| 54 | + getplotlyoffline(test_link); |
| 55 | + js_folder_exists = (exist(plotly_js_folder, 'dir') == 7); |
| 56 | + testCase.verifyTrue(js_folder_exists); |
| 57 | + end |
| 58 | + |
| 59 | + function testPlotlyOffline(testCase) |
| 60 | + test_filename = 'test_offline'; |
| 61 | + p = plotlyfig('visible', 'off', 'filename', test_filename); |
| 62 | + p.layout.width = 0; |
| 63 | + p.layout.height = 0; |
| 64 | + plotlyoffline(p); |
| 65 | + test_file = fullfile(pwd, strcat(test_filename, '.html')); |
| 66 | + html_file_exists = (exist(test_file, 'file') == 2); |
| 67 | + testCase.verifyTrue(html_file_exists); |
| 68 | + delete(test_file); |
| 69 | + end |
| 70 | + |
| 71 | + function testPlotlyOfflineNoBundle(testCase) |
| 72 | + |
| 73 | + actual = 'this should get modified'; |
| 74 | + |
| 75 | + % get plotlyjs dir |
| 76 | + userhome = getuserdir(); |
| 77 | + plotly_config_folder = fullfile(userhome, '.plotly'); |
| 78 | + plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs'); |
| 79 | + bundle_name = 'plotly-matlab-offline-bundle.js'; |
| 80 | + delete(fullfile(plotly_js_folder, bundle_name)) |
| 81 | + |
| 82 | + p = plotlyfig('visible', 'off'); |
| 83 | + |
| 84 | + try |
| 85 | + plotlyoffline(p); |
| 86 | + catch exception |
| 87 | + actual = exception.message; |
| 88 | + end |
| 89 | + |
| 90 | + expected = sprintf(['Error reading: /Users/bronsolo/', ... |
| 91 | + '.plotly/plotlyjs/plotly-matlab-', ... |
| 92 | + 'offline-bundle.js.\nPlease download ', ... |
| 93 | + 'the required dependencies using: ', ... |
| 94 | + '>>getplotloffline \nor contact ', ... |
| 95 | + 'support@plot.ly for assistance.']); |
| 96 | + |
| 97 | + testCase.verifyEqual(actual,expected); |
| 98 | + end |
| 99 | + end |
| 100 | +end |
| 101 | + |
| 102 | + |
0 commit comments