|
1 | | -// import { users } from 'oa-shared/mocks/data' |
2 | | - |
3 | | -// import { generateAlphaNumeric } from '../../utils/TestUtils' |
4 | | - |
5 | | -// let initialRandomId |
6 | | - |
7 | | -// describe('[News.Write]', () => { |
8 | | -// describe('[Create a news item]', () => { |
9 | | -// beforeEach(() => { |
10 | | -// initialRandomId = generateAlphaNumeric(8).toLowerCase() |
11 | | -// }) |
12 | | - |
13 | | -// it('[By Authenticated]', () => { |
14 | | -// const initialTitle = `${initialRandomId} Amazing new thing` |
15 | | -// const initialExpectedSlug = `${initialRandomId}-amazing-new-thing` |
16 | | -// const initialNewsBodyOne = 'Yo.' |
17 | | -// const initialNewsBodyTwo = "We've done something." |
18 | | -// const initialNewsBodyThree = 'We saved so much plastic.' |
19 | | -// const initialSummary = `${initialNewsBodyOne} ${initialNewsBodyTwo} ${initialNewsBodyThree}` |
20 | | -// const category = 'Moulds' |
21 | | -// const tag1 = 'product' |
22 | | -// const tag2 = 'workshop' |
23 | | -// const updatedTitle = `Still an amazing thing ${initialRandomId}` |
24 | | -// const updatedExpectedSlug = `still-an-amazing-thing-${initialRandomId}` |
25 | | -// const updatedNewsBody = 'PLUS sparkles!' |
26 | | -// const updatedSummary = `${updatedNewsBody} ${initialNewsBodyOne} ${initialNewsBodyTwo}` |
27 | | - |
28 | | -// cy.visit('/news') |
29 | | -// const user = users.admin |
30 | | -// cy.signIn(user.email, user.password) |
31 | | - |
32 | | -// cy.step("Can't add news from main page") |
33 | | -// cy.visit('/news') |
34 | | -// cy.get('[data-cy=create-news]').should('not.exist') |
35 | | - |
36 | | -// cy.step('Can go direct to url') |
37 | | -// cy.visit('/news/create') |
38 | | -// cy.get('[data-cy=field-title]', { timeout: 20000 }) |
39 | | - |
40 | | -// cy.step('Cannot be published when empty') |
41 | | -// cy.get('[data-cy=submit]').click() |
42 | | -// cy.get('[data-cy=errors-container]') |
43 | | - |
44 | | -// cy.step('Add image') |
45 | | -// cy.get('[data-cy=heroImage-upload]') |
46 | | -// .find(':file') |
47 | | -// .selectFile('images/howto-step-pic1.jpg') |
48 | | - |
49 | | -// cy.step('Can add draft news') |
50 | | -// cy.get('[data-cy=field-title]') |
51 | | -// .clear() |
52 | | -// .type(initialTitle) |
53 | | -// .blur({ force: true }) |
54 | | - |
55 | | -// cy.addToMarkdownField(initialNewsBodyOne) |
56 | | -// cy.addToMarkdownField(initialNewsBodyTwo) |
57 | | -// cy.addToMarkdownField(initialNewsBodyThree) |
58 | | - |
59 | | -// cy.get('[data-cy=draft]').click() |
60 | | -// cy.wait(2000) |
61 | | -// cy.url().should('include', `/news/${initialExpectedSlug}`) |
62 | | - |
63 | | -// cy.step('Can get to drafts') |
64 | | -// cy.visit('/news') |
65 | | -// cy.contains(initialTitle).should('not.exist') |
66 | | -// cy.get('[data-cy=my-drafts]').click() |
67 | | -// cy.contains(initialTitle).click() |
68 | | - |
69 | | -// cy.step('Shows draft news') |
70 | | -// cy.get('[data-cy=draft-tag]').should('be.visible') |
71 | | -// cy.contains(initialNewsBodyOne) |
72 | | - |
73 | | -// cy.step('Submit news') |
74 | | -// cy.get('[data-cy=edit]').click() |
75 | | - |
76 | | -// cy.selectTag(category, '[data-cy=category-select]') |
77 | | -// cy.selectTag(tag1, '[data-cy="tag-select"]') |
78 | | -// cy.selectTag(tag2, '[data-cy="tag-select"]') |
79 | | - |
80 | | -// cy.get('[data-cy=errors-container]').should('not.exist') |
81 | | -// cy.wait(2000) |
82 | | -// cy.get('[data-cy=submit]').click() |
83 | | - |
84 | | -// cy.wait(2000) |
85 | | -// cy.url().should('include', `/news/${initialExpectedSlug}`) |
86 | | - |
87 | | -// cy.step('All news fields shown') |
88 | | -// cy.visit('/news') |
89 | | -// cy.get('[data-cy=news-list-item-summary]') |
90 | | -// .first() |
91 | | -// .contains(initialSummary) |
92 | | -// cy.get('[data-cy=news-list-item]').contains(initialTitle).click() |
93 | | - |
94 | | -// cy.contains(initialTitle) |
95 | | -// cy.contains(initialNewsBodyOne) |
96 | | -// cy.contains(initialNewsBodyTwo) |
97 | | -// cy.contains(initialNewsBodyThree) |
98 | | -// cy.contains(category) |
99 | | -// cy.contains(tag1) |
100 | | -// cy.contains(tag2) |
101 | | -// // contains images |
102 | | - |
103 | | -// cy.step('All ready for a discussion') |
104 | | -// cy.get('[data-cy=DiscussionTitle]').contains('Start the discussion') |
105 | | -// cy.get('[data-cy=follow-button]').contains('Following Comments') |
106 | | - |
107 | | -// cy.step('Edit fields') |
108 | | -// cy.wait(2000) |
109 | | -// cy.get('[data-cy=edit]').click() |
110 | | -// cy.wait(2000) |
111 | | -// cy.url().should('include', `/news/${initialExpectedSlug}/edit`) |
112 | | - |
113 | | -// cy.get('[data-cy=field-title]').clear().type(updatedTitle).blur() |
114 | | -// cy.get('.mdxeditor-root-contenteditable').type('{selectAll}{del}') |
115 | | - |
116 | | -// cy.addToMarkdownField(updatedNewsBody) |
117 | | -// cy.addToMarkdownField(initialNewsBodyOne) |
118 | | -// cy.addToMarkdownField(initialNewsBodyTwo) |
119 | | -// cy.addToMarkdownField(initialNewsBodyThree) |
120 | | - |
121 | | -// // cy.step('Update images by removing one') |
122 | | -// // cy.get('[data-cy=image-upload-0]') |
123 | | -// // .get('[data-cy=delete-image]:first') |
124 | | -// // .click({ force: true }) |
125 | | - |
126 | | -// cy.step('Updated news details shown') |
127 | | -// cy.wait(2000) |
128 | | -// cy.get('[data-cy=submit]').click() |
129 | | -// cy.wait(2000) |
130 | | -// cy.url().should('include', `/news/${updatedExpectedSlug}`) |
131 | | -// cy.contains(updatedNewsBody) |
132 | | - |
133 | | -// cy.contains(updatedTitle) |
134 | | -// cy.contains(updatedNewsBody) |
135 | | -// cy.contains(initialNewsBodyOne) |
136 | | -// cy.contains(initialNewsBodyTwo) |
137 | | -// cy.contains(initialNewsBodyThree) |
138 | | -// cy.get('[data-cy=follow-button]').contains('Following') |
139 | | - |
140 | | -// cy.step('Can access the news with the previous slug') |
141 | | -// cy.visit(`/news/${initialExpectedSlug}`) |
142 | | -// cy.contains(updatedTitle) |
143 | | - |
144 | | -// cy.step('All updated fields visible on list') |
145 | | -// cy.visit('/news') |
146 | | -// cy.contains(updatedSummary) |
147 | | -// cy.contains(updatedTitle) |
148 | | -// cy.contains(category) |
149 | | - |
150 | | -// cy.step('Can add profile badge') |
151 | | -// cy.visit(`/news/${updatedExpectedSlug}/edit`) |
152 | | -// cy.wait(1000) |
153 | | -// cy.selectTag('PRO', '[data-cy=profileBadge-select]') |
154 | | -// cy.get('[data-cy=submit]') |
155 | | -// .click() |
156 | | -// .url() |
157 | | -// .should('include', `/news/${updatedExpectedSlug}`) |
158 | | -// cy.get('[data-cy=profileBadge]').contains('only news') |
159 | | - |
160 | | -// cy.step('Not visible to logged out users') |
161 | | -// cy.wait(1000) |
162 | | -// cy.logout() |
163 | | -// cy.reload() |
164 | | -// cy.url().should( |
165 | | -// 'include', |
166 | | -// `/sign-in?returnUrl=%2Fnews%2F${updatedExpectedSlug}`, |
167 | | -// ) |
168 | | - |
169 | | -// cy.step('Not visible on the list view') |
170 | | -// cy.visit('/news') |
171 | | -// cy.contains(updatedTitle).should('not.exist') |
172 | | - |
173 | | -// cy.step("Logged in user (who is not an admin) can't view item") |
174 | | -// cy.signUpNewUser() |
175 | | -// cy.visit(`/news/${updatedExpectedSlug}`) |
176 | | -// cy.reload() |
177 | | -// cy.url().should('include', `/news`) |
178 | | -// cy.url().should('not.include', `updatedExpectedSlug`) |
179 | | - |
180 | | -// Should also check that a user with the right badge (and not an admin) can view |
181 | | -// }) |
182 | | - |
183 | | -// it('[By Anonymous]', () => { |
184 | | -// cy.step('Ask users to login before creating a news') |
185 | | -// cy.visit('/news') |
186 | | -// cy.get('[data-cy=create-news]').should('not.exist') |
187 | | - |
188 | | -// cy.visit('/news/create') |
189 | | -// cy.url().should('contain', '/sign-in?returnUrl=%2Fnews%2Fcreate') |
190 | | -// }) |
191 | | - |
192 | | -// // it('[Admin]', () => { |
193 | | -// // Should check an admin can edit other's content |
194 | | -// // }) |
195 | | -// }) |
196 | | -// }) |
| 1 | +import { users } from 'oa-shared/mocks/data'; |
| 2 | + |
| 3 | +import { generateAlphaNumeric } from '../../utils/TestUtils'; |
| 4 | + |
| 5 | +let initialRandomId; |
| 6 | + |
| 7 | +describe('[News.Write]', () => { |
| 8 | + describe('[Create a news item]', () => { |
| 9 | + beforeEach(() => { |
| 10 | + initialRandomId = generateAlphaNumeric(8).toLowerCase(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('[By Authenticated]', () => { |
| 14 | + const initialTitle = `${initialRandomId} Amazing new thing`; |
| 15 | + const initialExpectedSlug = `${initialRandomId}-amazing-new-thing`; |
| 16 | + const initialNewsBodyOne = 'Yo.'; |
| 17 | + const initialNewsBodyTwo = 'HiHi!'; |
| 18 | + const initialNewsBodyThree = 'We did good.'; |
| 19 | + const initialSummary = `${initialNewsBodyOne} ${initialNewsBodyTwo} ${initialNewsBodyThree}`; |
| 20 | + const category = 'Moulds'; |
| 21 | + const tag1 = 'product'; |
| 22 | + const tag2 = 'workshop'; |
| 23 | + const updatedTitle = `Still an amazing thing ${initialRandomId}`; |
| 24 | + const updatedExpectedSlug = `still-an-amazing-thing-${initialRandomId}`; |
| 25 | + const updatedNewsBody = 'PLUS sparkles!'; |
| 26 | + const updatedSummary = `${updatedNewsBody} ${initialNewsBodyOne} ${initialNewsBodyTwo}`; |
| 27 | + |
| 28 | + cy.visit('/news'); |
| 29 | + const user = users.admin; |
| 30 | + cy.signIn(user.email, user.password); |
| 31 | + |
| 32 | + cy.step("Can't add news from main page"); |
| 33 | + cy.visit('/news'); |
| 34 | + cy.get('[data-cy=create-news]').should('not.exist'); |
| 35 | + |
| 36 | + cy.step('Can go direct to url'); |
| 37 | + cy.visit('/news/create'); |
| 38 | + cy.get('[data-cy=field-title]', { timeout: 20000 }); |
| 39 | + |
| 40 | + cy.step('Cannot be published when empty'); |
| 41 | + cy.get('[data-cy=submit]').click(); |
| 42 | + cy.get('[data-cy=errors-container]'); |
| 43 | + |
| 44 | + cy.step('Add image'); |
| 45 | + cy.get('[data-cy=heroImage-upload]') |
| 46 | + .find(':file') |
| 47 | + .selectFile('src/fixtures/images/howto-step-pic1.jpg', { force: true }); |
| 48 | + |
| 49 | + cy.step('Can add draft news'); |
| 50 | + cy.get('[data-cy=field-title]').clear().type(initialTitle).blur({ force: true }); |
| 51 | + |
| 52 | + cy.addToMarkdownField(initialNewsBodyOne); |
| 53 | + cy.addToMarkdownField(initialNewsBodyTwo); |
| 54 | + cy.addToMarkdownField(initialNewsBodyThree); |
| 55 | + |
| 56 | + cy.get('[data-cy=draft]').click(); |
| 57 | + cy.wait(2000); |
| 58 | + cy.url().should('include', `/news/${initialExpectedSlug}`); |
| 59 | + |
| 60 | + cy.step('Can get to drafts'); |
| 61 | + cy.visit('/news'); |
| 62 | + cy.contains(initialTitle).should('not.exist'); |
| 63 | + cy.get('[data-cy=my-drafts]').first().click({ force: true }); |
| 64 | + cy.contains(initialTitle).click(); |
| 65 | + |
| 66 | + cy.step('Shows draft news'); |
| 67 | + cy.get('[data-cy=draft-tag]').should('be.visible'); |
| 68 | + cy.contains(initialNewsBodyOne); |
| 69 | + |
| 70 | + cy.step('Submit news'); |
| 71 | + cy.get('[data-cy=edit]').click(); |
| 72 | + |
| 73 | + cy.selectTag(category, '[data-cy=category-select]'); |
| 74 | + cy.selectTag(tag1, '[data-cy="tag-select"]'); |
| 75 | + cy.selectTag(tag2, '[data-cy="tag-select"]'); |
| 76 | + |
| 77 | + cy.get('[data-cy=errors-container]').should('not.exist'); |
| 78 | + cy.wait(2000); |
| 79 | + cy.get('[data-cy=submit]').click(); |
| 80 | + |
| 81 | + cy.wait(2000); |
| 82 | + cy.url().should('include', `/news/${initialExpectedSlug}`); |
| 83 | + |
| 84 | + cy.step('All news fields shown'); |
| 85 | + cy.visit('/news'); |
| 86 | + cy.get('[data-cy=news-list-item-summary]').first().contains(initialSummary); |
| 87 | + cy.get('[data-cy=news-list-item]').contains(initialTitle).click(); |
| 88 | + |
| 89 | + cy.contains(initialTitle); |
| 90 | + cy.contains(initialNewsBodyOne); |
| 91 | + cy.contains(initialNewsBodyTwo); |
| 92 | + cy.contains(initialNewsBodyThree); |
| 93 | + cy.contains(category); |
| 94 | + cy.contains(tag1); |
| 95 | + cy.contains(tag2); |
| 96 | + // contains images |
| 97 | + |
| 98 | + cy.step('All ready for a discussion'); |
| 99 | + cy.get('[data-cy=DiscussionTitle]').contains('Start the discussion'); |
| 100 | + cy.get('[data-cy=follow-button]').contains('Following Comments'); |
| 101 | + |
| 102 | + cy.step('Edit fields'); |
| 103 | + cy.wait(2000); |
| 104 | + cy.get('[data-cy=edit]').click(); |
| 105 | + cy.wait(2000); |
| 106 | + cy.url().should('include', `/news/${initialExpectedSlug}/edit`); |
| 107 | + |
| 108 | + cy.get('[data-cy=field-title]').clear().type(updatedTitle).blur(); |
| 109 | + cy.get('.mdxeditor-root-contenteditable').type('{selectAll}{del}'); |
| 110 | + |
| 111 | + cy.addToMarkdownField(updatedNewsBody); |
| 112 | + cy.addToMarkdownField(initialNewsBodyOne); |
| 113 | + cy.addToMarkdownField(initialNewsBodyTwo); |
| 114 | + cy.addToMarkdownField(initialNewsBodyThree); |
| 115 | + |
| 116 | + // cy.step('Update images by removing one') |
| 117 | + // cy.get('[data-cy=image-upload-0]') |
| 118 | + // .get('[data-cy=delete-image]:first') |
| 119 | + // .click({ force: true }) |
| 120 | + |
| 121 | + cy.step('Updated news details shown'); |
| 122 | + cy.wait(2000); |
| 123 | + cy.get('[data-cy=submit]').click(); |
| 124 | + cy.wait(2000); |
| 125 | + cy.url().should('include', `/news/${updatedExpectedSlug}`); |
| 126 | + cy.contains(updatedNewsBody); |
| 127 | + |
| 128 | + cy.contains(updatedTitle); |
| 129 | + cy.contains(updatedNewsBody); |
| 130 | + cy.contains(initialNewsBodyOne); |
| 131 | + cy.contains(initialNewsBodyTwo); |
| 132 | + cy.contains(initialNewsBodyThree); |
| 133 | + cy.get('[data-cy=follow-button]').contains('Following'); |
| 134 | + |
| 135 | + cy.step('Can access the news with the previous slug'); |
| 136 | + cy.visit(`/news/${initialExpectedSlug}`); |
| 137 | + cy.contains(updatedTitle); |
| 138 | + |
| 139 | + cy.step('All updated fields visible on list'); |
| 140 | + cy.visit('/news'); |
| 141 | + cy.contains(updatedSummary); |
| 142 | + cy.contains(updatedTitle); |
| 143 | + cy.contains(category); |
| 144 | + |
| 145 | + cy.step('Can add profile badge'); |
| 146 | + cy.visit(`/news/${updatedExpectedSlug}/edit`); |
| 147 | + cy.wait(1000); |
| 148 | + cy.selectTag('PRO', '[data-cy=profileBadge-select]'); |
| 149 | + cy.get('[data-cy=submit]').click().url().should('include', `/news/${updatedExpectedSlug}`); |
| 150 | + cy.get('[data-cy=profileBadge]').contains('only news'); |
| 151 | + |
| 152 | + cy.step('Not visible to logged out users'); |
| 153 | + cy.wait(1000); |
| 154 | + cy.logout(); |
| 155 | + cy.reload(); |
| 156 | + cy.url().should('include', `/sign-in?returnUrl=%2Fnews%2F${updatedExpectedSlug}`); |
| 157 | + |
| 158 | + cy.step('Not visible on the list view'); |
| 159 | + cy.visit('/news'); |
| 160 | + cy.contains(updatedTitle).should('not.exist'); |
| 161 | + |
| 162 | + cy.step("Logged in user (who is not an admin) can't view item"); |
| 163 | + cy.signUpNewUser(); |
| 164 | + cy.visit(`/news/${updatedExpectedSlug}`); |
| 165 | + cy.reload(); |
| 166 | + cy.url().should('include', `/news`); |
| 167 | + cy.url().should('not.include', `updatedExpectedSlug`); |
| 168 | + }); |
| 169 | + |
| 170 | + it('[By Anonymous]', () => { |
| 171 | + cy.step('Ask users to login before creating a news'); |
| 172 | + cy.visit('/news'); |
| 173 | + cy.get('[data-cy=create-news]').should('not.exist'); |
| 174 | + |
| 175 | + cy.visit('/news/create'); |
| 176 | + cy.url().should('contain', '/sign-in?returnUrl=%2Fnews%2Fcreate'); |
| 177 | + }); |
| 178 | + |
| 179 | + // it('[Admin]', () => { |
| 180 | + // Should check an admin can edit other's content |
| 181 | + // }) |
| 182 | + }); |
| 183 | +}); |
0 commit comments