Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
51d28dae
Commit
51d28dae
authored
May 12, 2021
by
Paul Slaughter
Committed by
David O'Regan
May 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add keep_alive_slots component
parent
dc248dd7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
0 deletions
+173
-0
app/assets/javascripts/vue_shared/components/keep_alive_slots.vue
...ts/javascripts/vue_shared/components/keep_alive_slots.vue
+51
-0
spec/frontend/vue_shared/components/keep_alive_slots_spec.js
spec/frontend/vue_shared/components/keep_alive_slots_spec.js
+122
-0
No files found.
app/assets/javascripts/vue_shared/components/keep_alive_slots.vue
0 → 100644
View file @
51d28dae
<
script
>
export
default
{
props
:
{
slotKey
:
{
type
:
String
,
required
:
false
,
default
:
''
,
},
},
data
()
{
return
{
aliveSlotsLookup
:
{},
};
},
computed
:
{
aliveSlots
()
{
return
Object
.
keys
(
this
.
aliveSlotsLookup
);
},
},
watch
:
{
slotKey
:
{
handler
(
val
)
{
if
(
!
val
)
{
return
;
}
this
.
$set
(
this
.
aliveSlotsLookup
,
val
,
true
);
},
immediate
:
true
,
},
},
methods
:
{
isCurrentSlot
(
key
)
{
return
key
===
this
.
slotKey
;
},
},
};
</
script
>
<
template
>
<div>
<div
v-for=
"slot in aliveSlots"
v-show=
"isCurrentSlot(slot)"
:key=
"slot"
class=
"gl-h-full gl-w-full"
>
<slot
:name=
"slot"
></slot>
</div>
</div>
</
template
>
spec/frontend/vue_shared/components/keep_alive_slots_spec.js
0 → 100644
View file @
51d28dae
import
{
nextTick
}
from
'
vue
'
;
import
{
mountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
KeepAliveSlots
from
'
~/vue_shared/components/keep_alive_slots.vue
'
;
const
SLOT_1
=
{
slotKey
:
'
slot-1
'
,
title
:
'
Hello 1
'
,
};
const
SLOT_2
=
{
slotKey
:
'
slot-2
'
,
title
:
'
Hello 2
'
,
};
describe
(
'
~/vue_shared/components/keep_alive_slots.vue
'
,
()
=>
{
let
wrapper
;
const
createSlotContent
=
({
slotKey
,
title
})
=>
`
<div data-testid="slot-child" data-slot-id="
${
slotKey
}
">
<h1>
${
title
}
</h1>
<input type="text" />
</div>
`
;
const
createComponent
=
(
props
=
{})
=>
{
wrapper
=
mountExtended
(
KeepAliveSlots
,
{
propsData
:
props
,
slots
:
{
[
SLOT_1
.
slotKey
]:
createSlotContent
(
SLOT_1
),
[
SLOT_2
.
slotKey
]:
createSlotContent
(
SLOT_2
),
},
});
};
const
findRenderedSlots
=
()
=>
wrapper
.
findAllByTestId
(
'
slot-child
'
).
wrappers
.
map
((
x
)
=>
({
title
:
x
.
find
(
'
h1
'
).
text
(),
inputValue
:
x
.
find
(
'
input
'
).
element
.
value
,
isVisible
:
x
.
isVisible
(),
}));
afterEach
(()
=>
{
wrapper
.
destroy
();
});
describe
(
'
default
'
,
()
=>
{
beforeEach
(()
=>
{
createComponent
();
});
it
(
'
doesnt show anything
'
,
()
=>
{
expect
(
findRenderedSlots
()).
toEqual
([]);
});
describe
(
'
when slotKey is changed
'
,
()
=>
{
beforeEach
(
async
()
=>
{
wrapper
.
setProps
({
slotKey
:
SLOT_1
.
slotKey
});
await
nextTick
();
});
it
(
'
shows slot
'
,
()
=>
{
expect
(
findRenderedSlots
()).
toEqual
([
{
title
:
SLOT_1
.
title
,
isVisible
:
true
,
inputValue
:
''
,
},
]);
});
it
(
'
hides everything when slotKey cannot be found
'
,
async
()
=>
{
wrapper
.
setProps
({
slotKey
:
''
});
await
nextTick
();
expect
(
findRenderedSlots
()).
toEqual
([
{
title
:
SLOT_1
.
title
,
isVisible
:
false
,
inputValue
:
''
,
},
]);
});
describe
(
'
when user intreracts then slotKey changes again
'
,
()
=>
{
beforeEach
(
async
()
=>
{
wrapper
.
find
(
'
input
'
).
setValue
(
'
TEST
'
);
wrapper
.
setProps
({
slotKey
:
SLOT_2
.
slotKey
});
await
nextTick
();
});
it
(
'
keeps first slot alive but hidden
'
,
()
=>
{
expect
(
findRenderedSlots
()).
toEqual
([
{
title
:
SLOT_1
.
title
,
isVisible
:
false
,
inputValue
:
'
TEST
'
,
},
{
title
:
SLOT_2
.
title
,
isVisible
:
true
,
inputValue
:
''
,
},
]);
});
});
});
});
describe
(
'
initialized with slotKey
'
,
()
=>
{
beforeEach
(()
=>
{
createComponent
({
slotKey
:
SLOT_2
.
slotKey
});
});
it
(
'
shows slot
'
,
()
=>
{
expect
(
findRenderedSlots
()).
toEqual
([
{
title
:
SLOT_2
.
title
,
isVisible
:
true
,
inputValue
:
''
,
},
]);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment