|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright 2025 Adobe |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + ******************************************************************************/ |
| 16 | +describe("Test content fragment edit action for", function() { |
| 17 | + |
| 18 | + beforeAll(function () { |
| 19 | + fixture.setBase('test/fixtures/contentfragment') |
| 20 | + Granite.author.CFM.Fragments.mappings.set( |
| 21 | + "/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia", |
| 22 | + { variation: "master" } |
| 23 | + ); |
| 24 | + Granite.author.CFM.Fragments.mappings.set( |
| 25 | + "/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting", |
| 26 | + { variation: "other" } |
| 27 | + ); |
| 28 | + }) |
| 29 | + |
| 30 | + afterAll(function () { |
| 31 | + Granite.author.CFM.Fragments.mappings.clear(); |
| 32 | + }); |
| 33 | + |
| 34 | + beforeEach(function () { |
| 35 | + this.result = fixture.load('editActionTest.html'); |
| 36 | + spyOn(window, 'open'); |
| 37 | + }); |
| 38 | + |
| 39 | + afterEach(function () { |
| 40 | + fixture.cleanup() |
| 41 | + }); |
| 42 | + |
| 43 | + it("empty content fragment", function() { |
| 44 | + const editable = { dom: fixture.el.children.item(0)}; |
| 45 | + Granite.author.editor.contentfragment.setUp(editable); |
| 46 | + |
| 47 | + const canEdit = Granite.author.editor.contentfragment.canEdit(editable); |
| 48 | + Granite.author.editor.contentfragment.setUp(editable); |
| 49 | + |
| 50 | + expect(canEdit).toBeFalse(); |
| 51 | + expect(window.open).toHaveBeenCalledTimes(0); |
| 52 | + }); |
| 53 | + |
| 54 | + it("content fragment master variation and feature toggle disabled", function() { |
| 55 | + Granite.Toggles.enabled = false; |
| 56 | + const editable = { dom: fixture.el.children.item(1)}; |
| 57 | + |
| 58 | + const canEdit = Granite.author.editor.contentfragment.canEdit(editable); |
| 59 | + Granite.author.editor.contentfragment.setUp(editable); |
| 60 | + |
| 61 | + expect(canEdit).toBeTrue(); |
| 62 | + const expectedUrl = '/editor.html/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia'; |
| 63 | + expect(window.open).toHaveBeenCalledOnceWith(expectedUrl); |
| 64 | + }); |
| 65 | + |
| 66 | + it("content fragment master variation and feature toggle enabled", function() { |
| 67 | + Granite.Toggles.enabled = true; |
| 68 | + const editable = { dom: fixture.el.children.item(1)}; |
| 69 | + |
| 70 | + const canEdit = Granite.author.editor.contentfragment.canEdit(editable); |
| 71 | + Granite.author.editor.contentfragment.setUp(editable); |
| 72 | + |
| 73 | + expect(canEdit).toBeTrue(); |
| 74 | + const expectedUrl = 'https://experience.adobe.com/?repo=localhost#/aem/cf/editor/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia'; |
| 75 | + expect(window.open).toHaveBeenCalledOnceWith(expectedUrl); |
| 76 | + }); |
| 77 | + |
| 78 | + it("content fragment other variation and feature toggle disabled", function() { |
| 79 | + Granite.Toggles.enabled = false; |
| 80 | + const editable = { dom: fixture.el.children.item(2)}; |
| 81 | + |
| 82 | + const canEdit = Granite.author.editor.contentfragment.canEdit(editable); |
| 83 | + Granite.author.editor.contentfragment.setUp(editable); |
| 84 | + |
| 85 | + expect(canEdit).toBeTrue(); |
| 86 | + const expectedUrl = '/editor.html/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting?variation=other'; |
| 87 | + expect(window.open).toHaveBeenCalledOnceWith(expectedUrl); |
| 88 | + }); |
| 89 | + |
| 90 | + it("content fragment other variation and feature toggle enabled", function() { |
| 91 | + Granite.Toggles.enabled = true; |
| 92 | + const editable = { dom: fixture.el.children.item(2)}; |
| 93 | + |
| 94 | + const canEdit = Granite.author.editor.contentfragment.canEdit(editable); |
| 95 | + Granite.author.editor.contentfragment.setUp(editable); |
| 96 | + |
| 97 | + expect(canEdit).toBeTrue(); |
| 98 | + const expectedUrl = 'https://experience.adobe.com/?repo=localhost#/aem/cf/editor/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting'; |
| 99 | + expect(window.open).toHaveBeenCalledOnceWith(expectedUrl); |
| 100 | + }); |
| 101 | + |
| 102 | +}) |
0 commit comments