forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWikiPageSpec.coffee
More file actions
127 lines (106 loc) · 4.79 KB
/
Copy pathWikiPageSpec.coffee
File metadata and controls
127 lines (106 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# Copyright (C) 2013 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
define [
'compiled/models/WikiPage'
'underscore'
], (WikiPage, _) ->
wikiPageObj = (options={}) ->
defaults =
body: "<p>content for the uploading of content</p>"
created_at: "2013-05-10T13:18:27-06:00"
editing_roles: "teachers"
front_page: false
hide_from_students: false
locked_for_user: false
published: false
title: "Front Page-3"
updated_at: "2013-06-13T10:30:37-06:00"
url: "front-page-2"
_.extend defaults, options
QUnit.module 'WikiPage'
test 'latestRevision is only available when a url is provided', ->
wikiPage = new WikiPage
equal wikiPage.latestRevision(), null, 'not provided without url'
wikiPage = new WikiPage url: 'url'
notEqual wikiPage.latestRevision(), null, 'provided with url'
test 'revision passed to latestRevision', ->
wikiPage = new WikiPage {url: 'url'}, revision: 42
equal wikiPage.latestRevision().get('revision_id'), 42, 'revision passed to latestRevision'
test 'wiki page passed to latestRevision', ->
wikiPage = new WikiPage {url: 'url'}
equal wikiPage.latestRevision().page, wikiPage, 'wiki page passed to latestRevision'
test 'latestRevision should be marked as latest', ->
wikiPage = new WikiPage {url: 'url'}
equal wikiPage.latestRevision().latest, true, 'marked as latest'
test 'latestRevision should default to summary', ->
wikiPage = new WikiPage {url: 'url'}
equal wikiPage.latestRevision().summary, true, 'defaulted to summary'
QUnit.module 'WikiPage:Publishable'
test 'publishable', ->
wikiPage = new WikiPage
front_page: false
published: true
strictEqual wikiPage.get('publishable'), true, 'publishable set during construction'
wikiPage.set('front_page', true)
strictEqual wikiPage.get('publishable'), false, 'publishable set when front_page changed'
test 'deletable', ->
wikiPage = new WikiPage
front_page: false
published: true
strictEqual wikiPage.get('deletable'), true, 'deletable set during construction'
wikiPage.set('front_page', true)
strictEqual wikiPage.get('deletable'), false, 'deletable set when front_page changed'
QUnit.module 'WikiPage:Sync'
test 'parse removes wiki_page namespace added by api', ->
wikiPage = new WikiPage
namespacedObj = {}
namespacedObj.wiki_page = wikiPageObj()
parseResponse = wikiPage.parse(namespacedObj)
ok !_.isObject(parseResponse.wiki_page), "Removes the wiki_page namespace"
test 'present includes the context information', ->
wikiPage = new WikiPage {}, contextAssetString: 'course_31'
json = wikiPage.present()
equal json.contextName, 'courses', 'contextName'
equal json.contextId, 31, 'contextId'
test 'publish convenience method', 3, ->
wikiPage = new WikiPage wikiPageObj()
@stub wikiPage, 'save', (attributes, options) ->
ok attributes, 'attributes present'
ok attributes.wiki_page, 'wiki_page present'
strictEqual attributes.wiki_page.published, true, 'published provided correctly'
wikiPage.publish()
test 'unpublish convenience method', 3, ->
wikiPage = new WikiPage wikiPageObj()
@stub wikiPage, 'save', (attributes, options) ->
ok attributes, 'attributes present'
ok attributes.wiki_page, 'wiki_page present'
strictEqual attributes.wiki_page.published, false, 'published provided correctly'
wikiPage.unpublish()
test 'setFrontPage convenience method', 3, ->
wikiPage = new WikiPage wikiPageObj()
@stub wikiPage, 'save', (attributes, options) ->
ok attributes, 'attributes present'
ok attributes.wiki_page, 'wiki_page present'
strictEqual attributes.wiki_page.front_page, true, 'front_page provided correctly'
wikiPage.setFrontPage()
test 'unsetFrontPage convenience method', 3, ->
wikiPage = new WikiPage wikiPageObj()
@stub wikiPage, 'save', (attributes, options) ->
ok attributes, 'attributes present'
ok attributes.wiki_page, 'wiki_page present'
strictEqual attributes.wiki_page.front_page, false, 'front_page provided correctly'
wikiPage.unsetFrontPage()