|
| 1 | +/* eslint no-undef: 0 */ |
| 2 | +/* eslint prefer-arrow-callback: 0 */ |
| 3 | +casper.test.begin('Document Conversion Demo', 31, function suite(test) { |
| 4 | + const baseHost = 'http://localhost:3000'; |
| 5 | + |
| 6 | + function testButtonExists() { |
| 7 | + test.assertExists('label[for="source-sampleHTML.html"]', 'Sample html - button is found'); |
| 8 | + test.assertExists('label[for="source-sampleWORD.docx"]', 'Sample docx - button is found'); |
| 9 | + test.assertExists('label[for="source-samplePDF.pdf"]', 'Sample pdf - button is found'); |
| 10 | + test.assertExists('label[for="source-custom"]', 'Upload a file - button is found'); |
| 11 | + } |
| 12 | + |
| 13 | + function testOutputSection() { |
| 14 | + // Brings up Choose an output format - check for 3 new buttons |
| 15 | + casper.waitForSelector('div._content--choose-output-format', function () { |
| 16 | + test.assertExists('label[for="destination-json"]', 'Answer units JSON - button is found'); |
| 17 | + test.assertExists('label[for="destination-html"]', 'Normlized HTML - button is found'); |
| 18 | + test.assertExists('label[for="destination-text"]', 'Plain text - button is found'); |
| 19 | + }); |
| 20 | + } |
| 21 | + |
| 22 | + function testHtmlButtonClick() { |
| 23 | + casper.then(function () { |
| 24 | + this.click('label[for="source-sampleHTML.html"]'); |
| 25 | + }); |
| 26 | + |
| 27 | + testOutputSection(); |
| 28 | + } |
| 29 | + |
| 30 | + function testDocxButtonClick() { |
| 31 | + casper.then(function () { |
| 32 | + this.click('label[for="source-sampleWORD.docx"]'); |
| 33 | + }); |
| 34 | + |
| 35 | + testOutputSection(); |
| 36 | + } |
| 37 | + |
| 38 | + function testPdfButtonClick() { |
| 39 | + casper.then(function () { |
| 40 | + this.click('label[for="source-samplePDF.pdf"]'); |
| 41 | + }); |
| 42 | + |
| 43 | + testOutputSection(); |
| 44 | + } |
| 45 | + |
| 46 | + function testUploadButtonClick() { |
| 47 | + casper.then(function () { |
| 48 | + this.click('label[for="source-custom"]'); |
| 49 | + }); |
| 50 | + |
| 51 | + casper.waitForSelector('div._content--choose-output-format', function () { |
| 52 | + test.assertExists('label[for="file-chooser-input"]', 'Choose your file - button is found'); |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + function checkLinkDest(starturl, selectorToClick) { |
| 57 | + casper.thenOpen(starturl, function () { }); |
| 58 | + casper.then(function () { this.click(selectorToClick); }); |
| 59 | + test.assertHttpStatus(200); |
| 60 | + } |
| 61 | + |
| 62 | + function testHeaderLinks() { |
| 63 | + checkLinkDest(baseHost, 'nav.jumbotron--nav h5:nth-child(1)'); |
| 64 | + checkLinkDest(baseHost, 'nav.jumbotron--nav li:nth-child(1)'); |
| 65 | + checkLinkDest(baseHost, 'nav.jumbotron--nav li:nth-child(2)'); |
| 66 | + checkLinkDest(baseHost, 'nav.jumbotron--nav li:nth-child(3)'); |
| 67 | + } |
| 68 | + |
| 69 | + function testDocumentSection() { |
| 70 | + // Brings up Document section - Your document and Output document |
| 71 | + casper.waitForSelector('div._content--output', function () { |
| 72 | + test.assertExists('div[class="tab-panels"]', 'The tab panel is found'); |
| 73 | + test.assertExists('a[class="active tab-panels--tab base--a"]', 'Your document - is found'); |
| 74 | + test.assertExists('a[class=" tab-panels--tab base--a"]', 'Output document - is found'); |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + function testOutputFormatButtonsClick() { |
| 79 | + casper.then(function () { |
| 80 | + this.click('label[for="destination-json"]'); |
| 81 | + }); |
| 82 | + |
| 83 | + testDocumentSection(); |
| 84 | + |
| 85 | + casper.then(function () { |
| 86 | + this.click('label[for="destination-html"]'); |
| 87 | + }); |
| 88 | + |
| 89 | + testDocumentSection(); |
| 90 | + |
| 91 | + casper.then(function () { |
| 92 | + this.click('label[for="destination-text"]'); |
| 93 | + }); |
| 94 | + |
| 95 | + testDocumentSection(); |
| 96 | + |
| 97 | + // Your document |
| 98 | + casper.then(function () { |
| 99 | + this.click('ul.tab-panels--tab-list li:nth-child(1)'); |
| 100 | + }); |
| 101 | + test.assertHttpStatus(200); |
| 102 | + |
| 103 | + // Output document |
| 104 | + casper.then(function () { |
| 105 | + this.click('ul.tab-panels--tab-list li:nth-child(2)'); |
| 106 | + }); |
| 107 | + test.assertHttpStatus(200); |
| 108 | + } |
| 109 | + |
| 110 | + casper.start(baseHost, function (result) { |
| 111 | + test.assert(result.status === 200, 'Front page opens'); |
| 112 | + test.assertEquals(this.getTitle(), 'Document Conversion Demo', 'Title is found'); |
| 113 | + |
| 114 | + testButtonExists(); |
| 115 | + testHtmlButtonClick(); |
| 116 | + testDocxButtonClick(); |
| 117 | + testPdfButtonClick(); |
| 118 | + testUploadButtonClick(); |
| 119 | + testHeaderLinks(); |
| 120 | + testOutputFormatButtonsClick(); |
| 121 | + }); |
| 122 | + |
| 123 | + casper.run(function () { |
| 124 | + test.done(); |
| 125 | + }); |
| 126 | +}); |
0 commit comments